How to set up a netrender on the GPU

Hello guys,

In this tutorial I will explain how I got my netrender working on the GPU from the command line. I only use one computer for netrender with 2 CUDA cards.
This computer runs Ubuntu Server 12.04 LTS, so I have no GUI, this makes everything slightly more complicated. Therefore I have wrote this tutorial.

I will start from the very beginning so:

  1. Install Ubuntu Server 12.04 LTS.

 sudo apt-get update; sudo apt-get upgrade
  1. Install cuda using the following guide. It is important that you do not forget to install gcc:
sudo apt-get install gcc

If the Nvidia driver fails to install, execute the following:

sudo apt-get install freeglut3-dev build-essential libx11-dev libxmu-dev libgl1-mesa-dri libxi-dev libgl1-mesa-glx libglu1-mesa libglu1-mesa-dev
sudo apt-get install libwxgtk2.8-0 libwxbase2.8-0 wx-common libglu1-mesa libgl1-mesa-glx zlib1g bzip2 gpsd gpsd-clients xcalib libportaudio2
  1. Install blender from the repository to get the dependencies (the version you receive does not matter in this step, this will probably be an older version of Blender)
sudo apt-get install blender

  1. In this step we will remove this version of blender.
sudo rm -r /usr/lib/blender/
sudo rm /usr/bin/blender

  1. Now we will download the latest version of blender from Switch to the GNU/Linux tab and select your preferred mirror and copy the link. Now run the following command on your server to download it.
sudo wget <blender_link> 

  1. Now extract the downloaded blender*.tar.bz2:
sudo tar -xvjf blender*.tar.bz2

  1. Rename the extracted folder to blender:
sudo mv /blender* /blender

  1. Copy the blender files to /usr/lib/
sudo cp <path to blender>/blender /usr/lib/blender -r 

  1. Now we will build a symlink to the executable in /usr/bin/ so we can start blender from our path.
cd /usr/bin/
sudo ln -s /usr/lib/blender/blender blender

You can choose to skip step 8 to 10 and run blender from the extracted folder.
NOTE: This folder is not in your path, so you have to start blender from this folder.

  1. Next step is to build a userpref.blend with Auto Run Python Scripts enabled.
    NOTE: This is essential because of a bug in blender. Starting blender with -y does not work. Neither does starting blender with a python script setting the autorun flag to ON. It even does not work to compile blender yourself with the WITH_PYTHON_SECURITY flag disabled (OFF). Blender will still not execute the python script. The only way to enable this auto execute is via the GUI. Since we do not have a GUI (or want to install one), we have to build a userpref.blend on a different machine.

Open Blender and open user preferences. Go to the File tab and check Auto Run Python Scripts. Now save User Settings.
Now locate your userpref.blend, on Ubuntu this usually can be found in:

In OS X this can be found in:
/Users/<user>/Library/Application\ Support/Blender/<version>/config/userpref.blend

In Windows this can be found in:
C:\Documents and Settings&lt;user>\AppData\Roaming\Blender Foundation\Blender&lt;version>\config\userpref.blend

  1. Copy this file to your Ubuntu Server into:
    NOTE: The folder config probably does not exist yet. You have to make this folder.

  2. Now we have to fix the permissions of this folder.

cd /home/&lt;user&gt;/.config/blender/&lt;version&gt;/
sudo chown -R user:group /home/&lt;user&gt;/.config/blender/&lt;version&gt;/config/
sudo chmod -R 775 /home/&lt;user&gt;/.config/blender/&lt;version&gt;/config/

  1. Now Blender is set up, it is time to create the slave and master servers. This can be done by making two .blend files and opening them on your server.
    NOTE: In my case, I’m running the slave and master on the same machine.

On your other machine, start Blender and enable the Network Renderer add-on. Now select Network render as your render engine. Go into your render settings and change to master. Disable broadcast and save the file to master.blend.

Create a new file, select Network Render again and go the render settings. Choose slave this time and set the master ip address to the correct address (in my case: localhost). Now save this file as slave.blend.

  1. Copy these files to your server and place them in /usr/lib/blender (or another file folder you like).

  2. When everything is set, you can start blender in netrender mode using the following commands:

blender -b &lt;path to&gt;/master.blend --addons netrender -a -noaudio -nojoystick &
blender -b &lt;path to&gt;/slave.blend --addons netrender -a -noaudio -nojoystick &

-b: runs Blender in the background
–addons netrender: this loads the netrender addon
-a: this command starts the master or slave.
-noaudio: prevents some ALSA errors.
-nojoystick: can prevent some errors too.
&: This is used to run a process as a background job, so you can still use your terminal (omit this if you want to see the console output).

You can check if everything is alright using the web interface found at <master-IP>:<port> (by default port is 8000).
If everything is ok, you should see a webpage which displays the connected slave(s).
Now everything is set up and you should be able to send jobs to your Ubuntu Server machine from your client. However, now it will render on you CPU.

  1. To enable GPU rendering on your slave, you have to incorporate a python script in the .blend file of your creation. This script sets the right render engine and compute device on your slave.

In your creation open the Text Editor.
Copy the following code into the Text Editor:

import bpy
FlagCUDA = False

#Select CUDA
    bpy.context.user_preferences.system.compute_device_type = 'CUDA'
    FlagCUDA = True
    print("No CUDA-Device")
    FlagCUDA = False
#Choose CUDA device
if FlagCUDA:    
        bpy.context.user_preferences.system.compute_device = 'CUDA_MULTI_2' #Use all graphics cards if available.
        bpy.context.user_preferences.system.compute_device = 'CUDA_0' 
#Check which GPUs are there
print("Rendering on: " + bpy.context.user_preferences.system.compute_device)

#set compute device to GPU (in render settings tab in .blend file)
bpy.context.scene.cycles.device = 'GPU'

Save this file as In the Text Editor window this file is probably still called Text, rename this to If you have done this, the register checkbox will light up (if you did not rename the file in the Text Editor, this checkbox is greyed out). Now tick this checkbox, this will load the script when loading the .blend file on your slave. Don’t forget to save your .blend file before sending.

  1. If you send your job to the master, it should now be rendered on the GPU of the slave. You can check this using htop or nvidia-smi or any other monitoring app you like.

Do not forget to incorporate the in every .blend file you send to the server. This is necessary to render on the GPU.

To view the status of the job, open the Master Monitor under render settings. If the job is done, press either get image or get animation to receive the rendered file(s).

  1. If you want to have your blender server ready on boot, you have to add a crontab.
sudo crontab -e

(select your favourite text editor if prompted)

add the following two lines at the end.

@reboot blender -b &lt;path to&gt;/master.blend --addons netrender -a -noaudio -nojoystick &
@reboot blender -b &lt;path to&gt;/slave.blend --addons netrender -a -noaudio -nojoystick &

NOTE: Don’t forget the & tag, otherwise blender will halt your system on boot.

Now you should always have your blender slave ready to fulfil your needs.

Happy Netrender GPU Blending!


Nimuin (and kudos to my friend)

Thanks for the tutorial, I was just thinking about setting up some on demand VMs for blender, and this is exactly what I was looking for.

Nimuin, are you still following this thread? If so I have some questions! Thanks for the tutorial.

Yes I am, however it has been quite some time since I had to deal with this problem. But fire away with your questions and I will see if I can answer them.

Thank you! Here’s my situation: I’m running a master and slave on a dual GTX 980 machine (Windows 8). GPU is enabled in user preferences. I’m just running them as normal Blender instances, not from the command line.

On my client computer, I have my .blend project I want to render, and I followed step 17 to add the script to the client’s .blend file, however, the script appears to run on the slave only AFTER the slave has finished rendering. Based on the render times, it is definitely rendering on the CPU

Here’s output from the slave’s console:

Created directory: C:\Users\90158\AppData\Local\Temp\1\slave_f7bd6b9444b827ef55b
Fullpath \\users$\staff\90158\Desktop\SeabassBearNetRenderGPU.
File: SeabassBearNetRenderGPU.blend and 0 other files
frame 1
Read new prefs: C:\Users\90158\AppData\Roaming\Blender Foundation\Blender\2.74\c
found bundled python: C:\Program Files\Blender Foundation\Blender\2.74\python
read blend: \\users$\staff\90158\Desktop\SeabassBearNetRenderG
Fra:1 Mem:105.73M (0.00M, Peak 124.41M) | Mem:0.00M, Peak:0.00M | Scene, RenderL
ayer | Synchronizing object | Sphere
Fra:1 Mem:105.73M (0.00M, Peak 124.41M) | Mem:0.00M, Peak:0.00M | Scene, RenderL
ayer | Synchronizing object | Plane

Fra:1 Mem:105.73M (0.00M, Peak 430.68M) | Remaining:00:02.62 | Mem:1252.56M, Pea
k:1252.58M | Scene, RenderLayer | Path Tracing Tile 509/510
Fra:1 Mem:105.73M (0.00M, Peak 430.68M) | Remaining:00:02.12 | Mem:1252.56M, Pea
k:1252.58M | Scene, RenderLayer | Path Tracing Tile 510/510
Fra:1 Mem:105.73M (0.00M, Peak 430.68M) | Mem:1252.30M, Peak:1252.58M | Scene, R
enderLayer | Finished
Fra:1 Mem:105.65M (0.00M, Peak 430.68M) Sce: Scene Ve:0 Fa:0 La:0
Saved: C:\Users\90158\AppData\Local\Temp\1\slave_f7bd6b9444b827ef55bb56522659c1f
2\job_2604\000001.exr Time: 05:59.28 (Saving: 00:00.04)

  • CUDA GPU found
  • Rendering on: CUDA_MULTI_2

Blender quit
status 0

I have tried it, but I run into the same problem. I haven’t figured out a solution yet. If I find one, I will let you know :slight_smile:

Cool, thank you!

Is this because I am not running the clinet/master form the command line?