Skip to content

[Update Headless}: Add GPU enforcing for cycles and extend config vars to support --cylces-device #162

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 39 additions & 5 deletions __init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,21 +261,55 @@ def make_directories(save_path):
return Blend_My_NFTs_Output, batch_json_save_path, nftBatch_save_path


def run_as_headless():
def force_optix_or_cuda():
"""
For use when running from the command line.
Force OptiX or CUDA. Preferably OptiX
"""

# force CUDA device usage with cycles renderer
# Force Optix device usage with cycles renderer
cprefs = bpy.context.preferences.addons['cycles'].preferences
bpy.context.preferences.addons['cycles'].preferences.compute_device_type = 'OPTIX'
bpy.context.preferences.addons['cycles'].preferences.refresh_devices()
print(bpy.context.preferences.addons['cycles'].preferences.devices.keys())

for key in bpy.context.preferences.addons['cycles'].preferences.devices.keys():
bpy.context.preferences.addons['cycles'].preferences.devices[key].use = True

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

if cprefs.get_num_gpu_devices() > 0:
print('Using {} OptiX GPUs for rendering!'.format(cprefs.get_num_gpu_devices()))
return

print("no luck with OptiX! let's try CUDA instead!", end="\n")

cprefs.compute_device_type = 'CUDA'
cprefs.get_devices()
cprefs.refresh_devices()
print(cprefs.devices.keys())

for key in cprefs.devices.keys():
cprefs.devices[key].use = True

print('Using {} devices for rendering!'.format(cprefs.get_num_gpu_devices()))
bpy.context.scene.cycles.device = 'GPU'

if cprefs.get_num_gpu_devices() > 0:
print('Using {} CUDA GPUs for rendering!'.format(cprefs.get_num_gpu_devices()))
return


print("you're doomed! no CUDA or OptiX GPUs found!", end="\n")
bpy.context.scene.render.engine = 'CYCLES'
bpy.context.scene.cycles.device = 'CPU'
print("enjoy slow CPU ;)", end="\n")

def run_as_headless():
"""
For use when running from the command line.
"""

# if user want's the Eevee pass this
if bpy.context.scene.render.engine == 'CYCLES':
force_optix_or_cuda()

# def dumpSettings(settings):
# output = (
Expand Down
10 changes: 9 additions & 1 deletion main/headless_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def get_python_args():
required=False,
help="Use pre-existing batch data for rendering"
)

parser.add_argument("--logic-file",
dest="logic_file",
metavar='FILE',
Expand All @@ -71,4 +71,12 @@ def get_python_args():
required=False,
help="Resume failed batch"
)

parser.add_argument("--cycles-device",
dest="cycles-device",
choices=["OPTIX", "CUDA"],
required=False,
help="set cycles device to either OptiX or CUDA"
)

return parser.parse_args(argv), parser