Skip to content
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

CUDA device detection doesn't correctly handle all corner cases #493

Closed
errantspark opened this issue Jan 11, 2021 · 1 comment
Closed
Assignees
Labels

Comments

@errantspark
Copy link

errantspark commented Jan 11, 2021

Background

For background regarding this situation see this commit and this issue

I use an ultrabook with an eGPU (1080Ti) over TB3, when i have it plugged in everything works fine. When it's not connected attempting to enable BlendLuxCore I get the following error.

Traceback (most recent call last):
  File "C:\Program Files\Blender Foundation\Blender 2.91\2.91\scripts\modules\addon_utils.py", line 382, in enable
    mod.register()
  File "C:\Users\error\AppData\Roaming\Blender Foundation\Blender\2.91\scripts\addons\BlendLuxCore\__init__.py", line 93, in register
    pyluxcore.Init(LuxCoreLog.add)
RuntimeError: CUDA driver API error CUDA_ERROR_UNKNOWN (code: 999, file:C:\lambda\luxcorerender\LuxCore\src\luxrays\core\init.cpp, line: 71): unknown error

Problem

The issue is that even though I have CUDA installed but no CUDA devices we're getting past line 67 of init.cpp

66		const CUresult err = cuInit(0);
67		if (err == CUDA_ERROR_NO_DEVICE) {
68			// This handles the case when CUDA is installed but there are no
69			// NVIDIA GPUs installed.
70		} else {
71			CHECK_CUDA_ERROR(err);
72
73			isCudaAvilable = true;

I built LuxCore after changing line 67 to be simply

67           if ( true ) {

and when using the freshly built binaries BlendLuxCore behaves correctly and I'm able to render and use lux as expected. As best I can tell this means the problem has to be that the check on line 67 is failing to detect my particular no-cuda-device situation.

I think I can probably fix this myself and submit a PR, but I am not super familiar with C++, my next step is to log the actual error or analyze the state to see what it's returning and make sure we add whatever weird config I've ended up in to this check. I'm not sure what the easiest way to debug this is so any help on that front would be appreciated.


P.S. I'm also able to attempt a CPU render by unplugging my eGPU after enabling BlendLuxCore which results in a different error message. (sorry about the image)
image
I think this might(??) be a separate issue, but I haven't dug into the code to try and understand it. The question is, if the renderer is set to CPU in blender, why is CUDA attempting to initialize at all? However if isCudaAvilable = false; there is no problem, so as long as we fix the above issue this may be irrelevant.

P.P.S. What's the correct way to update the version of LuxCore inside BlendLuxCore, i was just copying over my freshly built pyluxcore.pyd which i'm sure is a bad idea for many reasons.


Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.

@Dade916 Dade916 self-assigned this Jan 11, 2021
Dade916 added a commit that referenced this issue Jan 11, 2021
@Dade916
Copy link
Member

Dade916 commented Jan 11, 2021

This is more a bug in CUDA because it should report an CUDA_ERROR_NO_DEVICE in your case instead of a CUDA_ERROR_UNKNOWN. However it is easy to work around: I modified the code to disable CUDA for any type of cuInit() error (not just CUDA_ERROR_NO_DEVICE).
This should work in your case too.

As far as I know, CUDA doesn't really support plugging/unplugging a GPU so you have still to restart Blender if you are connecting/disconnecting your device half way.

About CPU rendering: LuxCore uses GPU also for image pipeline (if CUDA is available) so it used also when doing CPU-only rendering. There is an option in BlendLuxCore to force the use of CPU for the image pipeline too (I'm not sure where it is, it may be in the camera panel).

Updating pyluxcore.pyd file is the only required step if you are not modifying the LuxCore Python API.

howetuft pushed a commit to howetuft/LuxCore that referenced this issue Jan 16, 2021
@Dade916 Dade916 closed this as completed May 15, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants