I have a machine with four GPUs (1080ti) running on ubuntu and I want to assign only one of them for rendering because it seems that using only one GPU per process and running 4 processes is much faster than running all GPUs on one process. The process in continuously rendering scenes.
This is the way I tried to do it:
cycles_preferences = preferences.addons['cycles'].preferences
cuda_devices, opencl_devices = cycles_preferences.get_devices()
cycles_preferences.compute_device_type = 'CUDA'
bpy.data.scenes[0].cycles.device = 'GPU'
gpus=[]
for device in cuda_devices:
if device.type == 'CUDA':
gpus.append(device)
if gpus:
gpus[self.gpu_num].use = True
gpus.pop(self.gpu_num)
if gpus: # in case of one gpu
for gpu in gpus:
gpu.use = False
else: bpy.data.scenes[0].cycles.device = 'CPU'
But when I render I see all 4 GPUs take part in the rendering.
self.gpu_num
- is FLAG passed form the command which holds for which of the four GPUs to use.
Update - This code works for me if you are trying to make better GPU utilization this is the way to do it.
bpy.data.scenes[0].cycles.device = 'GPU'
which comes after the assignment of the desired gpu? $\endgroup$