2.8 not using GPU, but only when headless

I’m working on an animation, so part of my workflow is running a windows batch file that calls blender to render the frames I need in headless mode.

When I try switching to 2.8, I find that Blender uses only my CPU, not my GPU. While rendering, my CPU usage is pegged at 100% and my GPU is basically totally idle.

However, when I run Blender 2.8 in regular GUI mode and render the same frames, it uses my GPU like it is supposed to. Yes, I’ve checked that my GPU (GeForce GTX 1080) is properly set as the CUDA device.

I’ve determined that it is not a specific file, because the same behavior is present even for a new file just containing the default cube, a camera, and a light.

To summarize:

  • When rendering headless from the command-line, Blender uses only the CPU

  • When rendering the same frames of the same file from the GUI, Blender uses the GPU like it is supposed to.

Any thoughts about what I should look for?

See this thread, there is a solution at the bottom that shows how to set Cuda devices in the command line

Thank you for the link. Unfortunately, the property I am supposed to set appears not to exist.

>>> bpy.context.user_preferences.addons['cycles'].preferences.compute_device_type = 'CUDA'
Traceback (most recent call last):
  File "<console>", line 1, in <module>
AttributeError: 'Context' object has no attribute 'user_preferences'

Running all of the other python commands seems to work, and does list my video card, but rendering from there still doesn’t use the GPU. :frowning:

user_preferences named to preferences in 2.8

Excellent! That worked like a charm. Thank you very much for the help.

To save the next person a step, the python lines I used were:

bpy.context.preferences.addons['cycles'].preferences.compute_device_type = 'CUDA'
bpy.context.preferences.addons['cycles'].preferences.devices[0].use = True

Glad I found this, now I know how to do it when 2.8 releases!

Me three. So, do we need to activate CUDA options to run headless in command line?

If CUDA is enabled in the settings when you are using the GUI, it’ll be enabled when run without the GUI.

1 Like

Thank you very much. I’ve tried it on 2.83. Working spectacularly!