0

When running (python) programs, I can use below code to set it only using No.1 and No.2 GPU:

CUDA_VISIBLE_DEVICES=1,2 python xxx.py

So How can I set CPU devices for this same (python) program? Something like:

CUDA_VISIBLE_DEVICES=1,2 CPU_VISIBLE_DEVICES=0-10 python xxx.py

Why I need this?

I have a server which has multi cpus and gpus. The gpus are divided as needed by multi user using CUDA_VISIBLE_DEVICES=0,1. But the cpus are not. So one user's program can take too much cpu power, slowing down other users.

I need some ways to divide the cpu as needed.

ToughMind
  • 987
  • 1
  • 10
  • 28
  • Python by itself can currently only use a single CPU because of the GIL. This is possibly going to be changed in a future Python version, but for the time being, that's how it is. If you want to run on multiple CPUs, maybe try the experimental Python fork which removes the GIL. – tripleee May 16 '22 at 04:25
  • If your actual question is "how can I make it run on CPU 3 only" maybe check out https://stackoverflow.com/questions/69872036/how-to-assign-cpu-affinity-for-python-3-subprocess and perhaps https://stackoverflow.com/questions/69095641/python-multithreading-multiprocessing-limiting-cpu-core-affinity – tripleee May 16 '22 at 05:10
  • @tripleee Sir, I have edited my question. I need to devide the cpu cores to multi user as needed. Because I notice that one user's program can occupy too much cpu power and slow down other users. – ToughMind May 16 '22 at 06:18
  • 1
    The first comment still stands; Python has `multiprocessing` for running mutiple processes, which allow you to run code on multiple CPUs, but a single script simply cannot run in more than one process. – tripleee May 16 '22 at 06:22
  • I need something simpler, as simple as setting some envirionment viriables so I can run any program through the command line while indicating which cpus it should use. Is this possible? – ToughMind May 16 '22 at 06:32
  • 4
    No. Again, see my previous comments. Goto 10. – tripleee May 16 '22 at 06:34
  • Note that `CUDA_VISIBLE_DEVICES` only works because the nVidia tools related to that know to look for it. There's no equivalent environment variable for the OS. – Ouroborus May 16 '22 at 07:05

0 Answers0