Selecting GPU with Python script 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
bpy.ops.wm.open_mainfile(filepath="/home/xxx/xxx.blend")

for scene in bpy.data.scenes:
    bpy.context.scene.render.engine = 'CYCLES' 
    bpy.data.scenes["Scene"].cycles.device='GPU' 
    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

bpy.ops.render.render(True)
img_path = "/home/xxx/Bilder/test_1.png"
rendered_image = bpy.data.images["Render Result"]
rendered_image.save_render(filepath=img_path)


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

4.15.1-041501-generic


clinfo

 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                  &lt;printPlatformInfo:5: get CL_PLATFORM_HOST_TIMER_RESOLUTION : error -30&gt;
 Platform Extensions function suffix             AMD


EDIT

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

https://pro.radeon.com/en/software/prorender/blender/
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 = &quot;CYCLES&quot;

# Set the device_type
bpy.context.preferences.addons[
    &quot;cycles&quot;
].preferences.compute_device_type = &quot;CUDA&quot; # or &quot;OPENCL&quot;

# Set the device and feature set
bpy.context.scene.cycles.device = &quot;GPU&quot;

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