6

I want to use two python source codes, the first one is developed with tensorflow and the other is developed using pythorch. I want to run each of these codes in a thread with a separate GPU. the input of both codes are the same and there are some post-processes when the result of two are ready.

I cannot use tf.device because it gets all available GPU when initializing and I have to use CUDA_VISIBLE_DEVICES environment variable.GPU access is selectable via setting CUDA_VISIBLE_DEVICES in python.

os.environ["CUDA_VISIBLE_DEVICES"] = "Accessible_GPUs"

But unfortunately, it seems CUDA_VISIBLE_DEVICES is not working with threads:

os.environ["CUDA_VISIBLE_DEVICES"] = "2"
Thread(target = method_from_code1).start()
os.environ["CUDA_VISIBLE_DEVICES"] = "3"
Thread(target = method_from_code2).start()

now the problem is to set different values an environment variable for each thread. Is there any solution to this issue?

Bharath Kumar
  • 548
  • 1
  • 6
  • 18
R.y.z
  • 213
  • 2
  • 15

0 Answers0