Frequently Asked Question
Using our HPC to render Blender images and animations is pretty easy!
Blender has a command line interface that we will use, the full up-to-date documentation is located at:
https://docs.blender.org/manual/en/latest/render/workflows/command_line.html
First, load Blender via the modules command:
$ module load Blender
Running on compute nodes
The easiest way to run a render is to transfer your .blend file to you home folder and use srun:
$ srun -N1 blender -b .blend -o //_###.png -a
This command will ask for one node on the compute partition and will run blender on your .blend file. The output images will be stored in the same folder with the names you define in the -o option. The -a argument tells Blender that you want to render the whole animation, if you want to render specific frames, use the -f option. Keep in mind that the -a and -f options have to be the last options. A comma separated list of frames can also be used (no spaces) or you can define a range of frames using the '..' seperator between the first and last frames (inclusive). Also make sure to replace .blend with the name of your .blend render file, and with the name you want for the rendered output frames.
Running on gpu nodes
We also have a partition where nodes have a lot of GPU power, which can be beneficial for rendering. First, we need to load the CUDA module:
$ module load CUDA
Next, in order to run Blender jobs on our GPUs, copy and save the following in a file in the same folder with your .blend file:
For versions 2.81-3.0. :
import bpy bpy.context.user_preferences.addons['cycles'].preferences.compute_device_type= 'CUDA' bpy.context.user_preferences.addons['cycles'].preferences.devices[0].use = True bpy.context.scene.render.tile_x = 256 bpy.context.scene.render.tile_y = 256 bpy.context.scene.cycles.device = 'GPU' bpy.ops.render.render(write_still=True)
For versions 3.0. and later :
import bpy bpy.data.scenes[0].render.engine = "CYCLES" # Set device_type bpy.context.preferences.addons[ "cycles" ].preferences.compute_device_type = "CUDA" # or "OPTIX" # Set device and feature set bpy.context.scene.cycles.device = "GPU" print(bpy.context.preferences.addons["cycles"].preferences.has_active_device()) # get_devices() for Blender detects GPU device bpy.context.preferences.addons["cycles"].preferences.get_devices() print(bpy.context.preferences.addons["cycles"].preferences.compute_device_type) for d in bpy.context.preferences.addons["cycles"].preferences.devices: d["use"] = 1 # Using all devices, include GPU and CPU print(d["name"], d["use"])
Save it as cuda.py
This script tells blender to use our NVIDIA Tesla M60 GPUs running CUDA. It is necessary since you probably prepared your render files on your local machine with different hardware.
Run Blender, the command is similar to the one we used before:
$ srun -N1 -pgpu --gres=gpu:8 blender -b .blend -o //_###.png -P cuda.py -a
If you want to split the rendering to multiple nodes, the best way is to define sets of frames using the -f option and run multiple jobs. In that case, you can write a Slurm batch script and run the jobs with sbatch in the background.
A simple Slurm batch script that loads all the modules and renders frames 1 to 10 on the GPU nodes is here:
#!/bin/bash -l #SBATCH --partition=gpu #SBATCH --nodes=1 #SBATCH -n 28 #SBATCH --gres=gpu:8 module load Blender blender -b input.blend -o //_###.png -P cuda.py -f 1..10
Again, replace and with the correct names, save the script in the same directory as your .blend and cuda.py files as blender.slurm and run it with:
$ sbatch blender.slurm
More info here:
https://support.arctur.si/scp/faq.php?id=8