Command Line to Force a CPU or GPU render??

Is there a way for me to force Blender to render a .blend file with the CPU? or Force it to render with the GPU? Either a command line switch or some sort of python script (even though I am not super familiar with python).

We have a renderfarm with 9 machines. Three of them have high end GPUs for rendering. The problem I have, is that with our renderfarm management software (or any software). is that when sending a job to the farm, it will choose CPU or GPU, whichever is selected in the .blend file. That is great for the 3 machines that have good GPUs, but it renders 10x slower on the other machines with fast CPUs but slow GPUs. So I need a way to force blender to render on the CPU or GPU via a command line switch that can be integrated into the renderfarm management software, or possibly a python script. or maybe there is another way?

Any help would be much appreciated!

We’re running OSX on all machines.

UPDATE:

I was able to force GPU or CPU rendering via this script in a gpurender.py file:

import bpy
bpy.context.scene.cycles.device = ‘GPU’
bpy.ops.render.render(True)

But now the issue is the tile sizes. I need to be able to specify my tile sizes for CPU rendering to 64x64 and GPU renders need to be 512 by 512, otherwise render times are still very inefficient.

I attempted to implement tile sizes into my gpurender.py script by adding the following, but it didnt work. Render times were unchanged:

import bpy
bpy.context.scene.cycles.device = ‘CPU’
bpy.ops.render.render(True)

for scene in bpy.data.scenes:
scene.render.tile_x = 64
scene.render.tile_y = 64

I think the easiest way would be just to duplicate the scene in your .blend and have a gpu and a cpu variant.
Then just start blender with the -S or --scene <name> argument. ( just link, not full copy, so the blend size isn’t increased )
Thus you would have created optimal tilesizes and perhaps even other optimal settings depending on your targeted machine.
These are all belonging to “scene”.

Your scripting is okay, although i recommend 32 x 32 or even 16 x 16 with double the logical threads you have available (( cores + virtual cores ) * 2) . Did you miss perhaps just the right order of commands ?

Jens

I had the same problem: the command line render could not fully utilizing the the threads. It consumed only 30% of them.

But, after adding the tile sizes line, voila!

It now uses almost 90%.

My tile sizes are 32x32 for 20 cores.

Thanks!