NMake (Windows): robust CUDA lib path resolution for Conda & system installs#705
Conversation
|
I didn't realise how weirdly case-sensitive NMake was when I originally implemented the |
|
Totally agree it’s cleaner to standardize on
// Prefer explicit CUDALIBRARYPATH (Conda/runtime) then CUDA_LIBRARY_PATH, then manual CUDA installs, else nothing (fall back to LIB)
!IF DEFINED(CUDALIBRARYPATH) // uses defined and doesn't rely on empty string comparisons
LIBCUDA=/LIBPATH:"$(CUDALIBRARYPATH)"
!ELSEIF DEFINED(CUDA_LIBRARY_PATH)
LIBCUDA=/LIBPATH:"$(CUDA_LIBRARY_PATH)"
!ELSEIF EXIST("$(CUDA_PATH)\lib\x64\cudart.lib")
LIBCUDA=/LIBPATH:"$(CUDA_PATH)\lib\x64"
!ELSEIF EXIST("$(CUDA_PATH)\lib\cudart.lib")
LIBCUDA=/LIBPATH:"$(CUDA_PATH)\lib"
// Nothing – rely on LIB if it’s set by the environment/toolchain
!ELSE
LIBCUDA=
!ENDIFIf we standardize our docs and CI to always set
That will make NMake builds work out-of-the-box across Conda modular CUDA, system CUDA, and quirky environments—without relying on fragile mixed-case names. If you’re happy with the dual-variable check, I can update the PR to prefer |
What scripts do this? I'm pretty surprised that anyone cares about this arcane combination apart from us 🤣 If it's even semi-standard then I'll just change everything to use |
|
Ah sorry, I should’ve been clearer — I didn’t mean there’s some wider “semi-standard.” I was referring to our Conda packaging CI scripts, where we exported CUDALIBRARYPATH specifically so NMake would pick it up (since it uppercases env vars). That’s what I had in mind when I mentioned “some scripts.” (all the draft scripts of our conda recipe) So yeah, it’s totally internal/our setup, not anything broader in the wild. If you’d prefer to standardize on CUDALIBRARYPATH in the repo and I just adapt our Conda recipes/CI to set that instead, that works fine too 👍 |
|
Ahh ok, that makes more sense. In that case, can you rebase onto my nmake branch and update all our scripts to use |
…llback to CUDA_PATH\lib\x64 for manual installs, otherwise let linker use LIB if present
6957b44 to
d3996b5
Compare
Summary
On Windows NMake builds, the generated link step hardcoded
/LIBPATH:"$(CUDA_PATH)\lib\x64"and/or referenced$(CudaLibraryPath). In practice:%CONDA_PREFIX%\Library\libCudaLibraryPath→CUDALIBRARYPATH%LIB%may not include%CONDA_PREFIX%\Library\libThis PR makes the NMake preamble define a
$(LIBCUDA)variable with sensible fallbacks, and uses it in the link rule:Priority:
CUDALIBRARYPATH(Conda/runtime)$(CUDA_PATH)\lib\x64(system CUDA)$(CUDA_PATH)\lib(alternate layout)LIBsearch resolve)Changes
src/genn/backends/cuda/backend.ccgenNMakefilePreambleto emit$(LIBCUDA)with the above fallback logic.genNMakefileLinkRuleto use$(LIBCUDA)and link dynamically to CUDA (nocudart_static.libdependence).LIBCUDAlogic for HIP backend NMake preamble/link rule insrc/genn/backends/hip/backend.cc.Why
CudaLibraryPath) that NMake won’t populate.cuda-cudart-staticat runtime; dynamic linking viacudart.libis sufficient (and consistent with MSBuild configs in the repo).Backwards compatibility
$(CUDA_PATH)\lib\x64/\lib).LIBwill still link (empty$(LIBCUDA)).