# Rendering on command-line with GPU?

I am trying to submit a render job via slurm on our cluster with blender 2.8, that is, completely command-line based with no way to start the GUI on the computing nodes.

I have assigned 38 CPU to the task (so that the resources are assigned on a single machine) and plenty of RAM. Unfortunately, Blender uses only about 5 CPUs and the whole thing is disappointingly slow, with 5s/frame. (We are not only rendering the scene but are especially saving the motion vectors and depth map, which seems to take it's time). On a local machine with 2 Geforce 1080 Ti, I got it running with 1.5s/frame.

We also have nodes with 20 CPUs and 2 Geforce 2080 Ti each. How do I configure CUDA on such a job?

• The following answer should help, you will need to include the CPUs though (get rid of the if statement that excludes CPUs) and enable GPU rendering as well (as shown in the add-on). blender.stackexchange.com/questions/154510/… – Robert Gützkow Oct 26 '19 at 14:22
• Thanks, I seem to have gotten it running by copying the enable_gpu function and calling it with "CUDA", then pass the script with -P. Do you want to make that an answer so I can mark it as a solution? I have not enables CPUs yet, because during initial, local tests with the GUI, having CPUs and GPUs ticked for CUDA led to GPUs not be utilized. No time to check further now, the new gpu job array will get the job done in time – mcandril Oct 27 '19 at 9:36
• I'm currently at the Blender Conference in Amsterdam. I'll add an answer within the next days when I'm back home. – Robert Gützkow Oct 27 '19 at 10:35

The following script allows you to enable all GPUs and optionally all CPUs as well.

import bpy

def enable_gpus(device_type, use_cpus=False):
preferences = bpy.context.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 device in devices:
if device.type == "CPU":
if use_cpus:
device.use = True
else:
device.use = False
else:
device.use = True
activated_gpus.append(device.name)

cycles_preferences.compute_device_type = device_type
bpy.context.scene.cycles.device = "GPU"

return activated_gpus

enable_gpus("CUDA")


The script can be called from the command line by starting Blender with the -Por --python flag followed by the path and name of the script.

• Thanks again! Marked as solution. – mcandril Oct 29 '19 at 10:21