Render on two blender instances with two GPUs.

I would like to optimize my PC for rendering animations. It runs Linux Mint 17.2. It has a CPU I5 4570 and two GPUs (1.GPU: GTX780TI + 2.GPU: GTX590). I tested the render times on simple scene.

1.GPU 36sec.
2.GPU 42sec
1.+2.GPU 23sec.

I have also tested to render parallel on two blender instances: 1.instance on 1.GPU and 2.instance on 2.GPU. The render times are the same as I would render on one GPU after another(36sec. and 42sec.). Simple math says that rendering an animation would be faster to let GPUs render separately on two blender instances as together rendering one frame.

Question: Is it possible to create a little script which starts to render one blend file on two blender instances each on one GPU?

Here’s what you can do (I do something similar with a local machine with 4 GPUs). In you .blend file, you should have two scripts (just use the text editor), batch0.py and batch1.py. Each one enables a specific CUDA device. They also disable overwrite and enable placeholder attributes of rendering. So here’s what batch0.py should look like:

import bpy

C = bpy.context
C.user_preferences.system.compute_device = 'CUDA_0'

C.scene.render.use_overwrite = False
C.scene.render.use_placeholder = True

The only difference between batch0.py and batch1.py is that the fourth line should be CUDA_1 instead of CUDA_0.

Now… for rendering with two simultaneous session (assuming you’re running Linux or something using bash), you’ll need a shell script. Call it something like batch_render.sh. It should look something like this:

#!/bin/bash

if [ $# = 0 ]; then
    echo "You forgot to mention the .blend file you want to render"
else
    for i in `seq 0 1`;
    do
         blender -b $1 --python-text batch$i.py -a &
    done
fi

Then, all you need to do (after making your script executable) is open a terminal, change to the directory where your .blend file and shell script are saved, and run ./batch_render.py myblendfile.blend.

A couple additional notes:

  • If you’re re-rendering, make sure that you delete all of your previously rendered files before running your script. This is because you enabled overwrite and placeholders… so if there are already files there, neither Blender instance will render a file to replace them.
  • These scripts are quick n’ dirty hacks… I’m sure that they can be improved

Thank you very much Fweeb.
I made some quick test, but some of the images are rendered only in one tile and the rest is black. I think it is because GTX 590 is dual GPU and system recognize it as two cards.

But it is no problem because I will change that 590 with another 780Ti next week. I will post then how it works with two single cards.

Thank you very much Fweeb.
I made some quick test, but some of the images are rendered only in one tile and the rest is black. I think it is because GTX 590 is dual GPU and system recognize it as two cards.

But it is no problem because I will change that 590 with another 780Ti next week. I will post then how it works with two single cards.

At the moment I am using two GTX 780TI and everything seems to work fine. Although these scripts are quick n’ dirty hacks, they are working great :wink:

Thank you Fweeb, was very helpful.

Batch script is working fine, but I have one issue with it. I am using 2x GTX 780Ti and when rendering an animation, some of the images have an error – black tiles, see the attachment. It appears unexpectedly. Sometimes 200frames everything fine and sometimes in 20frames I get 2-3 results as you see…


Any idea?

Batch script is working fine, but I have one issue with it. I am using 2x GTX 780Ti and when rendering an animation, some of the images have an error – black tiles, see the attachment. It appears unexpectedly. Sometimes 200frames everything fine and sometimes in 20frames I get 2-3 results as you see…


Any idea?