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:
Install Ubuntu Server 12.04 LTS.
sudo apt-get update; sudo apt-get upgrade
- 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
- 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
- In this step we will remove this version of blender.
sudo rm -r /usr/lib/blender/ sudo rm /usr/bin/blender
- Now we will download the latest version of blender from Blender.org. 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>
- Now extract the downloaded blender*.tar.bz2:
sudo tar -xvjf blender*.tar.bz2
- Rename the extracted folder to blender:
sudo mv /blender* /blender
- Copy the blender files to /usr/lib/
sudo cp <path to blender>/blender /usr/lib/blender -r
- 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.
- 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:
In Windows this can be found in:
C:\Documents and Settings<user>\AppData\Roaming\Blender Foundation\Blender<version>\config\userpref.blend
Copy this file to your Ubuntu Server into:
NOTE: The folder config probably does not exist yet. You have to make this folder.
Now we have to fix the permissions of this folder.
cd /home/<user>/.config/blender/<version>/ sudo chown -R user:group /home/<user>/.config/blender/<version>/config/ sudo chmod -R 775 /home/<user>/.config/blender/<version>/config/
- 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.
Copy these files to your server and place them in /usr/lib/blender (or another file folder you like).
When everything is set, you can start blender in netrender mode using the following commands:
blender -b <path to>/master.blend --addons netrender -a -noaudio -nojoystick & blender -b <path to>/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.
- 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 try: bpy.context.user_preferences.system.compute_device_type = 'CUDA' FlagCUDA = True except: print("No CUDA-Device") FlagCUDA = False #Choose CUDA device if FlagCUDA: try: bpy.context.user_preferences.system.compute_device = 'CUDA_MULTI_2' #Use all graphics cards if available. except: 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' bpy.ops.render.render(True)
Save this file as gpurender.py. In the Text Editor window this file is probably still called Text, rename this to gpurender.py. 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 gpurender.py script when loading the .blend file on your slave. Don’t forget to save your .blend file before sending.
- 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 gpurender.py 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).
- 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 <path to>/master.blend --addons netrender -a -noaudio -nojoystick & @reboot blender -b <path to>/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)