Make CUDA runtime init soft-fail when no device is present - #107
Open
badnikhil wants to merge 1 commit into
Open
Make CUDA runtime init soft-fail when no device is present#107badnikhil wants to merge 1 commit into
badnikhil wants to merge 1 commit into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Follows up on #100 - ensure the runtime module does not cause issues trying to load itself when no CUDA is present.
The guard from #100 doesn't achieve this: it wraps
runtime.d's module constructors inversion(LDC_DCompute_CUDA), but no compiler defines that identifier — LDC predefines onlyLDC_DComputeThe constructors are therefore compiled out in every build, and on machines that do have a GPU the default context is never created:Changes
Platform.tryInitialise(): a soft-failing probe that never throws and never mutates the thread-local error status - checksloadCUDA()(noLibrary/badLibrary), thecuInitresult, andcuDeviceGetCount > 0._initPlatform()marks CUDA unavailable and returns quietly when the probe fails; device/context creation is wrapped in a defensive try/catch so nothing can escapeshared static this()and abort the process beforemain().static this()no-ops when the platform isn't ready.ensureInit()now throws a catchableDComputeDriverException("No CUDA driver or device available on this system.")when CUDA is absent, solaunch!'s lazy-init path reports cleanly instead of failing later with a confusinginvalidContext.Verification (RTX 2050; device masking via CUDA_VISIBLE_DEVICES)
invalidContext, exit 1)""/-1)invalidContexton first Buffercuda/runtime.d), CUDA maskedAn opt-in automated test in
tests/runtime_init.d(env-guarded) covers the no-device path:DCOMPUTE_TEST_NO_CUDA=1 CUDA_VISIBLE_DEVICES="" ./dcomputeverifies the constructors survive andensureInit()throws as expected.