Way to detect if a valid GPU device is available from Python
A bit of ferreting around yielded this:
import bpy
import _cycles

cycles_preferences = bpy.context.preferences.addons['cycles'].preferences
cuda_devices, opencl_devices = cycles_preferences.get_devices()
for device in cuda_devices:
    if device.use == True:
        print(&quot;Device -&quot;, device.name, &quot;is&quot;, device.use)

Basically, it will iterate through the available devices in the &quot;cuda_devices&quot; (you can iterate &quot;opencl_devices&quot; too) and &quot;device.use&quot; will be true if it is active. So if anything returns True you know a valid rendering device is active.
You can adapt it to suit your application.