Blender deadline GPU rendering

Hello gang!

Our studio had blender set up to successfully render on GPUs through SGTK. We used this handy dandy little hack that modifies the in-app submitter

It wasn’t perfect (machines with multiple GPUs had strange behaviour), but it was still a huge performance improvement.

Modifying the submitter seems a bit trickier in Ayon. Has anyone tried to set this up before?

Got this to work, here’s a quick followup in case future people want this
Made a few modifications to the blender.py provided in that deadline forum (and some tweaks to the forceGPUScript to get worker’s GPU affinity to work)

  1. Replaced the gpuscriptpath ExtraArgs with a hard link to the forceGPUScript. There’s definitely better ways to do this

  2. Copied the getGPUList function from the redshift.py, and in the RenderArgument, stored the result as BLENDER_GPUDEVICES env var

  3. Added a loop in the BlenderForceGPU.py that enables only the CUDA devices listed in the env var

BlenderForceGPU.py
import os, bpy

# Set the device_type
bpy.context.preferences.addons["cycles"].preferences.compute_device_type = "CUDA" # or "OPENCL"
bpy.context.preferences.addons['cycles'].preferences.get_devices()


for d in bpy.context.preferences.addons["cycles"].preferences.devices:
    d["use"] = 0

## select and enable GPUs from env var set in the blender plugin
try: 
	GPUList = os.environ['BLENDER_GPUDEVICES']
	i = 0
	for d in bpy.context.preferences.addons["cycles"].preferences.devices:
		if str(i) in GPUList:
			d["use"] = 1
		i += 1
except KeyError:
	#env key not set, time to render on all available devices lesgoo
	for d in bpy.context.preferences.addons["cycles"].preferences.devices:
		d["use"] = 1

bpy.context.scene.cycles.device = 'GPU'