Alright, so i have a slightly strange system configuration. I'm running Zorin OS 12, which is roughly equivalent to Ubuntu 16.04. I am also running Mesa, but i use AMD's OpenCL. It works just fine with various miners i tested.

Now i want blender to actually render on the GPU. Blender detects it when i use the split kernel, but for some reason, whatever i do, it always falls back to the cpu.

Here's the script i use:

import bpy, _cycles

for scene in bpy.data.scenes:
    bpy.context.scene.render.engine = 'CYCLES' 
    bpy.context.scene.cycles.device = 'GPU'

bpy.context.user_preferences.addons['cycles'].preferences.compute_device_type = "OPENCL"
bpy.context.user_preferences.addons['cycles'].preferences.devices[0].use = True

img_path = "/home/xxx/Bilder/test_1.png"
rendered_image = bpy.data.images["Render Result"]

I am really at a loss here, but i think this could work. I mean even if the GPU for some reason does not work, it should not just fall back to the CPU, but give me some sort of error, right?

uname -r



 Platform Name                                   AMD Accelerated Parallel Processing
 Platform Vendor                                 Advanced Micro Devices, Inc.
 Platform Version                                OpenCL 2.1 AMD-APP (2527.3)
 Platform Profile                                FULL_PROFILE
 Platform Extensions                             cl_khr_icd cl_amd_event_callback cl_amd_offline_devices 
 Platform Host timer resolution                  <printPlatformInfo:5: get CL_PLATFORM_HOST_TIMER_RESOLUTION : error -30>
 Platform Extensions function suffix             AMD


For reasons unknown to me, installing Radeon RenderPro for Blender has fixed the problem!



3 Answers 3


Right now, I am using Blender 2.90. Here is my Python code to detect and use GPU in Blender.

import bpy
bpy.data.scenes[0].render.engine = "CYCLES"

# Set the device_type
].preferences.compute_device_type = "CUDA" # or "OPENCL"

# Set the device and feature set
bpy.context.scene.cycles.device = "GPU"

# get_devices() to let Blender detects GPU device
for d in bpy.context.preferences.addons["cycles"].preferences.devices:
    d["use"] = 1 # Using all devices, include GPU and CPU
    print(d["name"], d["use"])

Looks like you have multiple scenes in your file. To cycle through them and set them all use:

for scene in bpy.data.scenes:
    scene.cycles.device = 'GPU'

bpy.context refers to the to the area of blender which is currently being accessed by the user, not the script loop. If you don't have the file open, I would avoid using bpy.context calls and instead access bpy.data.

  • 1
    $\begingroup$ Right, that makes sense. I changed the script to do that, but sadly the gpu still is not being used. It always falls back to my cpu. $\endgroup$ Commented Mar 22, 2018 at 8:22
  • $\begingroup$ @user3922088 Then the problem must be in setting up the devices in UserPrefs. Your system config is very rare, it will be hard to help. Are you able to run Blender normally on that system with GUI and setup it manually with everything working? I don't see why the script wouldn't work. $\endgroup$ Commented Mar 22, 2018 at 9:10
  • $\begingroup$ I can run it normally, but not when i use this specific OpenCl configuration. Is there no way to set the device via Python? I mean it must be possible on render farms, right? They don't run the gui either. I realize it's rare, but the thing is that the Mesa drivers are superior to AMD's in all regards BUT OpenCL. $\endgroup$ Commented Mar 22, 2018 at 9:39
  • $\begingroup$ @user3922088 you would use the command line arguments when rendering remotely for what is needed to set (docs.blender.org/manual/en/dev/advanced/command_line/…). The system setting in UserPrefs is persistent when saved so there is only need to set it once. What do you mean with: I can run it normally, but not when i use this specific OpenCL configuration? $\endgroup$ Commented Mar 22, 2018 at 10:09
  • $\begingroup$ I am running Blender with a custom LD_LIBRARY_PATH to access AMDs OpenCL. If i print the availible devices via Python it shows me the processors and the gpu. I just don't know why it does not let me select it. $\endgroup$ Commented Mar 22, 2018 at 10:14

For reasons unknown to me, installing Radeon RenderPro for Blender has fixed the problem!



You must log in to answer this question.

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