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'
        for device in cuda_devices:
            if device.type == 'CUDA':
        if gpus:
            gpus[self.gpu_num].use = True
            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.

  • 1
    $\begingroup$ You also need to disable all other GPUs otherwise they will remain enabled as well. $\endgroup$ – Robert Gützkow Nov 1 '19 at 9:05
  • $\begingroup$ Got it. Will try that and let you know. $\endgroup$ – AvivSham Nov 1 '19 at 9:20
  • $\begingroup$ @rjg please check the edited code. this doesn't work either. should I remove the bpy.data.scenes[0].cycles.device = 'GPU' which comes after the assignment of the desired gpu? $\endgroup$ – AvivSham Nov 1 '19 at 10:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.