Sometimes, to effectively distribute the hardware load it is necessary to make a render from Blender only on certain video cards of several of them.
To do this we can use a simple script in which specify the numbers of devices to be used for rendering.
First, we need to determine in what order and with what numbers Blender sees the available video cards.
To do this, open the “Text Editor” window in Blender and paste the following script:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
import bpy def enable_gpus(device_type, use_cpus=False): preferences = bpy.context.preferences cycles_preferences = preferences.addons["cycles"].preferences cuda_devices, opencl_devices = cycles_preferences.get_devices() if device_type == "CUDA": devices = cuda_devices elif device_type == "OPENCL": devices = opencl_devices else: raise RuntimeError("Unsupported device type") for i,device in enumerate(devices): print("%i %s %s " % (i,device.type,device.name)) enable_gpus("CUDA") |
Click the “Run Script” button to execute it and a list of available video cards with their order numbers will be displayed in the system console (Window – Toggle System Console).
Getting the necessary numbers, create a file with the “custom_gpu_render.py” name in any text editor, paste the following script into it and save it in the right place.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
import bpy def enable_gpus(device_type,device_list): preferences = bpy.context.preferences cycles_preferences = preferences.addons["cycles"].preferences cuda_devices, opencl_devices = cycles_preferences.get_devices() if device_type == "CUDA": devices = cuda_devices elif device_type == "OPENCL": devices = opencl_devices else: raise RuntimeError("Unsupported device type") activated_gpus = [] for i,device in enumerate(devices): if (i in device_list): device.use = True activated_gpus.append(device.name) else: device.use = False cycles_preferences.compute_device_type = device_type for scene in bpy.data.scenes: scene.cycles.device = "GPU" return activated_gpus ######################### dev_list = [0, 3] ######################### gpus = enable_gpus("CUDA", dev_list) print("Activated gpu's: ") print(gpus) |
In the list
1 2 3 |
############################ dev_list = [0, 3] ############################ |
in square brackets specify the numbers of the required video cards comma-separated. In the current example script will use 0 and 3 video cards.
To start the render, at the console command prompt type:
for Windows OS (all files are located in the root of drive D):
1 |
"c:\Program Files\blender-2.81a-windows64\blender.exe" -b d:\file_to_render.blend -P d:\custom_gpu_render.py |
for Linux OS (all files are located in the /tmp directory):
1 |
blender -b /tmp/file_to_render.blend -P /tmp/custom_gpu_render.py |
While rendering, Blender will use only the video cards you specified.
Scripts author: Victor Mukaev.