3
$\begingroup$

Inspired by this question: Enabling GPU rendering for Cycles?


I have access to a Linux server that is equipped with GeForce GTX TITAN X. Now Cycles still renders everything with CPU. How can I get it to exploit the GPU?

Since I am talking about a Linux server, I guess there are two steps towards this goal:

  1. How to get the GPU ID or identifier with Unix commands so that I can refer to it in Blender?
  2. How to use Python to enable GPU computations?
$\endgroup$

1 Answer 1

7
$\begingroup$

For enabling the device for use, see bpy.context.user_preferences.system.compute_device_type and
bpy.context.user_preferences.system.compute_device
.

To check these from a shell, put the python you wish to execute in a file and run

blender --background --python <file.py>

Or, more concisely for quick tests,

blender -b --python-expr 'import bpy; <python code here>'

For convenience, here's a script which will print the possible and current values of compute_device_type and compute_device:

import bpy

sysp = bpy.context.user_preferences.system

devt = sysp.compute_device_type
dev = sysp.compute_device

# get list of possible values of enum, see http://blender.stackexchange.com/a/2268/599
devt_list = sysp.bl_rna.properties['compute_device_type'].enum_items.keys()
dev_list = sysp.bl_rna.properties['compute_device'].enum_items.keys()

# pretty print
lines=[
("Property", "Value", "Possible Values"),
("Device Type:", devt, str(devt_list)),
("Device:", dev, str(dev_list)),
]
print("\nGPU compute configuration:")
for l in lines:
    print("{0:<20} {1:<20} {2:<50}".format(*l))

If CUDA shows up in the possible values for device type, then enabling the device should be as simple as doing something like this in python:

devt = sysp.compute_device_type = 'CUDA'
dev = sysp.compute_device = 'CUDA_0'

To find the identifier for the device, you can use the script above with a line to set compute_device_type to CUDA before getting the list of possible devices.


Once that's all enabled we must still tell cycles to actually use it; to do this set bpy.context.scene.cycles.device to GPU.

$\endgroup$
6
  • $\begingroup$ Very clear answer; +1. For me, Device Type: NONE ['NONE', 'CUDA'] . What does this mean? My device type is None, and compute device is CUDA? Thanks! $\endgroup$ Dec 30, 2016 at 4:49
  • 1
    $\begingroup$ @SibbsGambling Ah, that wasn't layed out very clearly at all. There are two lines, the first is the "device type" property, its current value, and the possible selections (this is for picking between opencl and cuda). The second line shows the selected "device" (which, if device type is none, should also be none). The "device type" will have no option available besides NONE if there is a lack of detected devices for either opencl or cuda, so that fact that cuda is an option suggests you are in good shape. I've added headers to the little table printed by the snippet, hopefully that clarifies $\endgroup$
    – gandalf3
    Dec 30, 2016 at 6:46
  • $\begingroup$ Awesome! So I have devices ['CUDA_MULTI_0', 'CUDA_0', 'CUDA_1', 'CUDA_2', 'CUDA_3'], and now the GPU gets to run! $\endgroup$ Dec 30, 2016 at 17:28
  • $\begingroup$ But... why the GPU computation is much slower than the CPU computations to render the same scene? $\endgroup$ Dec 30, 2016 at 18:39
  • $\begingroup$ @SibbsGambling Sorry about the delay.. What tile size are you using? Does a larger size help (maybe 512)? $\endgroup$
    – gandalf3
    Jan 4, 2017 at 6:21

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .