c++ - Is it possible to execute multiple instances of a CUDA program on a multi-GPU machine? -


background:

i have written cuda program performs processing on sequence of symbols. program processes sequences of symbols in parallel stipulation sequences of same length. i'm sorting data groups each group consisting entirely of sequences of same length. program processes 1 group @ time.

question:

i running code on linux machine 4 gpus , utilize 4 gpus running 4 instances of program (1 per gpu). possible have program select gpu isn't in use cuda application run on? don't want hardcode cause problems down road when program run on different hardware greater or fewer number of gpus.

the environment variable cuda_visible_devices friend.

i assume have many terminals open have gpus. let's application called myexe

then in 1 terminal, do:

cuda_visible_devices="0" ./myexe 

in next terminal:

cuda_visible_devices="1" ./myexe 

and on.

then first instance run on first gpu enumerated cuda. second instance run on second gpu (only), , on.

assuming bash, , given terminal session, can make "permanent" exporting variable:

export cuda_visible_devices="2" 

thereafter, cuda applications run in session observe third enumerated gpu (enumeration starts @ 0), , observe gpu as if device 0 in session.

this means don't have make changes application method, assuming app uses default gpu or gpu 0.

you can extend make multiple gpus available, example:

export cuda_visible_devices="2,4" 

means gpus ordinarily enumerate 2 , 4 gpus "visible" in session , enumerate 0 , 1.

in opinion above approach easiest. selecting gpu "isn't in use" problematic because:

  1. we need definition of "in use"
  2. a gpu in use @ particular instant may not in use after that
  3. most important, gpu not "in use" become "in use" asynchronously, meaning exposed race conditions.

so best advice (imo) manage gpus explicitly. otherwise need form of job scheduler (outside scope of question, imo) able query unused gpus , "reserve" 1 before app tries so, in orderly fashion.


Comments

Popular posts from this blog

PHP DOM loadHTML() method unusual warning -

python - How to create jsonb index using GIN on SQLAlchemy? -

c# - TransactionScope not rolling back although no complete() is called -