News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Multi-Core Programming in ASM

Started by bozo, September 15, 2006, 03:33:44 PM

Previous topic - Next topic

bozo

Hello all!

simple question, how to write asm programs for multi-core cpus?
i haven't actually got one yet, but plan on getting an AMD 3800 soon & start playing with it.

some things i was thinking.

how to detect how many cores a cpu has.(because future plans are for quad core)
how to run threads that work with shared objects, CreateMutex/WaitForSingleObject?

anyone playing with this stuff yet?

P1

Check here:
http://www.masm32.com/board/index.php?topic=4222.0

As long as your code is thread safe and the hardware engineers are faultless, we have nothing to worry about.

The only problems I have had is with terminal sessions because they operate in their own namespace.  i.e Mutexes lose their uniqueness.  Use Search to find that discussion.

Regards,  P1  :8)

BasilYercin

Hi all !

Anyone tried a multi core memcpy  :eek?

hutch--

The use of multi core hardware will probably have much more to do with the OS design than application coding. If I have it right it will means far better thread seperation without as much task switching with multiple core capacity. Individual tasks will not get faster but probably multithreaded apps will get extra benefit from this style of hardware.
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

stanhebben

Quote from: BasilYercin on September 16, 2006, 11:18:12 AM
Anyone tried a multi core memcpy  :eek?

You should try performing multiple memcpys at the same time instead. And if you really have large data, you can split it in parts and memcpy those individually.

Tedd

Individual threads will not get 'faster' but they will essentially gain more cpu time, which will have the effect of making them quicker (the same effect as halving the number of running processes.)

Multi-core memcopy -- 2 cores, one cpu, one bus. Only one can access the bus at a time. The slowest part in a memcopy is bus access, and with two cores trying to both access it at the same time, it's likely to cause more problems than it solves. Of course, you might get lucky and each one will magically synchronise so the accesses are interleaved (read1-read2-write1-write2).. but I doubt it :bdg
No snowflake in an avalanche feels responsible.

daydreamer

I am trying to make a testapp, but I am new to multithreaded when it comes to nonJava stuff
could I run several instances of threadproc? same code but used for multiple threads, so you simple can put in your own code and testrun it on multicores

daydreamer

Quote from: Kernel_Gaddafi on September 15, 2006, 03:33:44 PM
Hello all!

simple question, how to write asm programs for multi-core cpus?
i haven't actually got one yet, but plan on getting an AMD 3800 soon & start playing with it.

some things i was thinking.

how to detect how many cores a cpu has.(because future plans are for quad core)
how to run threads that work with shared objects, CreateMutex/WaitForSingleObject?

anyone playing with this stuff yet?
CODIFIED already coded a multithreaded app on his dualcore
on FASMboard someone posted fractalrenderingcode that can run upto 16 cpus


daydreamer

Hutch, after writing own multithread code I find out masm6.14 doesnt support "Pause" opcode
so here is a macro for you

pause MACRO
    db 0f3h
    db 090h
    ENDM


there is no align 128 either to align data on P4 cachelines to prevent "false sharing"
should it be possible to write such a macro?


askm

Can certain tasks be assigned to certain cores to a multicore cpu ?

Are there instructs for this ?

Not without fallback of course. Sort of like RAID for cpus.

Striping is the analogy here for performance.

But also what if certain tasks had access to certain hard drives only ?

What if certain cores had access to certain hard drives only ?

What if certain questions went only to people who could answer them ?

bozo

What i've started to do lately, and something which atleast to me makes more sense.
Implement "setup" code in a HLL such as C, and the time critical code in assembly.

This has made programming for me alot easier.
Now, for multi-threaded programming, i use PTHREAD library which runs both natively on UNIX based systems, and as a DLL on Windows.
Programming with Pthreads is much easier.

codewarp

Quote from: Kernel_Gaddafi on September 15, 2006, 03:33:44 PM
how to detect how many cores a cpu has.(because future plans are for quad core)
how to run threads that work with shared objects, CreateMutex/WaitForSingleObject?

Here is how you detect the number of CPU in Windows (pardon the C++).  Do not use CPUID for this, because, for example, a quad processor will "say" that it has 4 CPUs, but WinXP will only support two of them.  The call below will always return the correct number.

  SYSTEM_INFO si;
  GetSystemInfo (&si);
  CPUcount = si.dwNumberOfProcessors;

u

#12
Everything that plays audio has (always) been multithreaded for over a decade. Might help to look at such stuff. Though, things are extremely simple.. locking of data (search for my *lib/article), FIFO queues, polling, async msgs. You just have to get paranoid and think that your thread will be interrupted at any time, and data can be requested to lock at any time :). But it's not really unintuitive.
[oh well, I'm coming from microelectronics background, where everything runs in parallel ^^]
Please use a smaller graphic in your signature.

sinsi

Quote from: codewarp on May 09, 2008, 10:38:03 PM
Do not use CPUID for this, because, for example, a quad processor will "say" that it has 4 CPUs, but WinXP will only support two of them.  The call below will always return the correct number.
Huh? Win XP Home tells me I have a quad-core, and Task Manager shows me 4 CPU graphs, so what is it you mean?

Quote from: askm on May 09, 2008, 01:16:11 AM
Can certain tasks be assigned to certain cores to a multicore cpu ?
See SetProcessAffinityMask or SetThreadAffinityMask
Light travels faster than sound, that's why some people seem bright until you hear them.

codewarp

Quote from: sinsi on May 10, 2008, 01:51:41 AM
Quote from: codewarp on May 09, 2008, 10:38:03 PM
Do not use CPUID for this, because, for example, a quad processor will "say" that it has 4 CPUs, but WinXP will only support two of them.  The call below will always return the correct number.
Huh? Win XP Home tells me I have a quad-core, and Task Manager shows me 4 CPU graphs, so what is it you mean?
I went and checked.  Windows XP Pro can support two processors, Home supports only one.  But, each processor can have any number of cores--I stand corrected.  My original point however, was that the physical CPU count and what Windows is supplies at boot up may differ.  I can boot WinXP with only one CPU, even though it still has two.  Software often needs to know the how many CPUs it can count on, not how many it can count.