Bitcoin Forum
April 23, 2024, 06:35:55 AM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: Workaround for Nvidia OpenCL 100% CPU usage on linux.  (Read 1040 times)
Misiolap (OP)
Newbie
*
Offline Offline

Activity: 14
Merit: 0


View Profile
April 19, 2013, 02:57:36 PM
 #1

Little workaround for nvidia eating 100% CPU when running OpenCL apps.

mk.junkyard.one.pl/libsleep.c

To compile run:
gcc -O2 -fPIC -shared -Wl,-soname,libsleep.so -o libsleep.so libsleep.c

To use:
LD_PRELOAD="./libsleep.so" ./cgminer

You can configure sleep time by setting
YIELD_SLEEP_TIME environment variable (in microseconds)
Default is 1000usec
Example:
YIELD_SLEEP_TIME="1500" LD_PRELOAD="./libsleep.so" ./cgminer

How does it work:
It overrides sched_yield function called during running OpenCL program with call to usleep.
Expect a little performance drop (less than 5%) - adjust YIELD_SLEEP_TIME for your needs.
The longer opencl program running time (ie. higher agression), the lower the performance drop is.

Does someone who is affected by similar problem with ATI cards would be willing to give me access to their system, so i could look up how to resolve this issue with ATI?
The forum strives to allow free discussion of any ideas. All policies are built around this principle. This doesn't mean you can post garbage, though: posts should actually contain ideas, and these ideas should be argued reasonably.
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction.
bitbrandon
Newbie
*
Offline Offline

Activity: 21
Merit: 0


View Profile
April 25, 2013, 01:07:29 AM
 #2

So what exactly causes this issue? A problem in OpenCL or NVIDIA's driver?
Misiolap (OP)
Newbie
*
Offline Offline

Activity: 14
Merit: 0


View Profile
April 25, 2013, 11:45:58 AM
 #3

I'm only guessing here:

During executing the opencl program nvidia opencl library enters loop which checks if the execution of opencl program has ended. At the end of each iteration of the loop sched_yield function is called to move the tasks to the end of system tasks queue, to allow other tasks to run unaffected. But if there are no other tasks scheduled to run it just spins in this loop, eating CPU for nothing - not really a big problem, but eats power and heats up CPU.

In CUDA you can control weather it behaves like this, or use some kind of conditional wait, not spinning in a loop, till the CUDA program finishes.

Probably nvidia could've implemented this mode for OpenCL too, without much effort.
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!