To use a particular set of GPU devices, the CUDA_VISIBLE_DEVICES
environment variable can be used:
import os
os.environ["CUDA_DEVICE_ORDER"]="PCI_BUS_ID" # see issue #152
os.environ["CUDA_VISIBLE_DEVICES"]="0" # Will use only the first GPU device
os.environ["CUDA_VISIBLE_DEVICES"]="0,3" # Will use only the first and the fourth GPU devices
(Quoted from this answer; more information on the CUDA environment variables here.)