Any way to set CUDA/OPTIX via command line?

Use this forum for general user support and related questions.
Forum rules
Please upload a testscene that allows developers to reproduce the problem, and attach some images.
Post Reply
MCurto
Posts: 56
Joined: Sun May 09, 2021 5:28 pm

Any way to set CUDA/OPTIX via command line?

Post by MCurto »

Hi,

I'm getting a few erros in Colab with most files (but not all) that crash Blender only when using GPU, but do fine with CPU.

Since I don't have anything NVIDIA and can't pre set my files to CUDA/OPTIX, my question is: is there something similar to Cycles to set render device, like:

--cycles-device CUDA ?

If not, is it feasible to have a Pyton script to set CUDA as Blender default?

Ty in advance.

EDIT: Found this to set CUDA to Cycles in Blender, it aparently works ok, just tested in Colab:
Would it be easy to adapt to Lux?

Code: Select all

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

# Set the device_type
bpy.context.preferences.addons[
    "cycles"
].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
bpy.context.preferences.addons["cycles"].preferences.get_devices()
print(bpy.context.preferences.addons["cycles"].preferences.compute_device_type)
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"])

#Save Blender preferences
bpy.ops.wm.save_userpref()
Screenshot 2023-02-10 at 14.56.51.jpg
MCurto
Posts: 56
Joined: Sun May 09, 2021 5:28 pm

Re: Any way to set CUDA/OPTIX via command line?

Post by MCurto »

I Might have "done" it,a bit of a crooked way:

Opened up the ui/addon_preferences.py in installer and chaged default to CUDA, re zipped, uploaded and its now ok as it seems:


[LuxRays][11.550] [PathOCL kernel] Compiler options: -D LUXRAYS_OPENCL_KERNEL -D SLG_OPENCL_KERNEL -D RENDER_ENGINE_PATHOCL -D PARAM_RAY_EPSILON_MIN=1e-05f -D PARAM_RAY_EPSILON_MAX=0.1f -D LUXRAYS_CUDA_DEVICE -D LUXRAYS_OS_LINUX --use_fast_math

This means its using CUDA right?

At least its Rendering now, as in it wasnt with OpenCL:

Code: Select all

[LuxRays][437.531] [LinearToneMap] Compiler options: -D LUXRAYS_OPENCL_KERNEL -D SLG_OPENCL_KERNEL -D LUXRAYS_CUDA_DEVICE -D LUXRAYS_OS_LINUX --use_fast_math
[LuxRays][437.536] [LinearToneMap] Compiling kernels
[LuxRays][437.982] [LinearToneMap] Program not cached
[LuxCore][437.982] [AutoLinearToneMap] Compiling LinearToneMap_Apply Kernel
[LuxCore][437.982] [LinearToneMap] Kernels compilation time: 450ms
[LuxRays][438.753] [LinearToneMap] Compiler options: -D LUXRAYS_OPENCL_KERNEL -D SLG_OPENCL_KERNEL -D LUXRAYS_CUDA_DEVICE -D LUXRAYS_OS_LINUX --use_fast_math
[LuxRays][438.753] [LinearToneMap] Compiling kernels
[LuxRays][438.760] [LinearToneMap] Program cached
[LuxCore][438.760] [AutoLinearToneMap] Compiling LinearToneMap_Apply Kernel
[LuxCore][438.760] [LinearToneMap] Kernels compilation time: 6ms
Fra:76 Mem:1010.46M (Peak 1390.15M) | Time:07:18.17 | Base | Samples 0/750 | Samples/Sec 348 k | Rays/Sample 12.9 | Path GPU + Sobol | 786,452 Tris | Refreshing film...
Fra:76 Mem:1010.46M (Peak 1390.15M) | Time:07:19.93 | Base | Samples 0/750 | Samples/Sec 312 k | Rays/Sample 11.3 | Path GPU + Sobol | 786,452 Tris | Film refresh in 6 s
Fra:76 Mem:1010.46M (Peak 1390.15M) | Time:07:19.93 | Base | Samples 0/750 | Samples/Sec 312 k | Rays/Sample 11.3 | Path GPU + Sobol | 786,452 Tris | Film refresh in 6 s
Fra:76 Mem:1010.46M (Peak 1390.15M) | Time:07:20.13 | Base | Samples 0/750 | Samples/Sec 312 k | Rays/Sample 11.3 | Path GPU + Sobol | 786,452 Tris | Film refresh in 4 s
Fra:76 Mem:1010.46M (Peak 1390.15M) | Time:07:20.33 | Base | Samples 0/750 | Samples/Sec 312 k | Rays/Sample 11.3 | Path GPU + Sobol | 786,452 Tris | Film refresh in 4 s
Fra:76 Mem:1010.46M (Peak 1390.15M) | Time:07:20.53 | Base | Samples 0/750 | Samples/Sec 312 k | Rays/Sample 11.3 | Path GPU + Sobol | 786,452 Tris | Film refresh in 3 s
MCurto
Posts: 56
Joined: Sun May 09, 2021 5:28 pm

Re: Any way to set CUDA/OPTIX via command line?

Post by MCurto »

Apparently this linux lastest version works fine straight to Colab (if I edit the value of prefered GPU to CUDA in UI preferences). although it gives me an error about NumPy it renders just fine (and fast).As a rough comparison I have on my imac a AMD580X/i9 990k on a scene I'm doing I get 2 to 2.5M Samples/Sec and same scene I get around 6 to 6.5M on a Nvidia T4.

Any idea what this Numpy error might affect?

Code: Select all

Switching to fully guarded memory allocator.
Blender 3.4.1 (hash 55485cb379f7 built 2022-12-20 00:46:45)
Blender 3.4.1
Build: 2022-12-20 00:46:45 Linux release
argv[0] = ./blender-3.4.1-linux-x64/blender
argv[1] = -b
argv[2] = /gdrive/MyDrive/Blender/Squares/Square_Dreamz_GPU_2_Base.blend
argv[3] = -E
argv[4] = LUXCORE
argv[5] = -noaudio
argv[6] = -f
argv[7] = 76
argv[8] = --debug
Read prefs: /root/.config/blender/3.4/config/userpref.blend
RuntimeError: module compiled against API version 0x10 but this version of numpy is 0xf
ImportError: numpy.core._multiarray_umath failed to import
BlendLuxCore 2.61alpha registered (with pyluxcore 2.6)
Updating device list
Read blend: /gdrive/MyDrive/Blender/Squares/Square_Dreamz_GPU_2_Base.blend
Updating device list
Post Reply