Something went wrong. Try again.
lol
Something went wrong. Try again.
4.8 kB · 182 lines
Nix
at master
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183{ lib, buildPythonPackage, fetchFromGitHub, cudaPackages, replaceVars, addDriverRunpath,
# build-system cython, pyclibrary, setuptools, setuptools-scm,
# env symlinkJoin,
# dependencies numpy,
# tests pytestCheckHook,
# passthru cuda-bindings,}:
buildPythonPackage (finalAttrs: { pname = "cuda-bindings"; version = "12.9.6"; pyproject = true; __structuredAttrs = true;
src = fetchFromGitHub { owner = "NVIDIA"; repo = "cuda-python"; tag = "v${finalAttrs.version}"; hash = "sha256-uRv27h2b6wXC8oOf5k2KxZ0bUFNvNu6XO05FBbJcU1k="; };
# Apply patch relative to cuda_bindings patchFlags = [ "-p2" ];
patches = [ (replaceVars ./patch-nvidia-libs-paths.patch { libcudart = lib.getLib cudaPackages.cuda_cudart; libcufile = lib.getLib cudaPackages.libcufile; libnvfatbin = lib.getLib cudaPackages.libnvfatbin; libnvjitlink = lib.getLib cudaPackages.libnvjitlink; libnvml = addDriverRunpath.driverLink; libnvrtc = lib.getLib cudaPackages.cuda_nvrtc; libnvvm = "${cudaPackages.cuda_nvcc}/nvvm"; }) ];
sourceRoot = "${finalAttrs.src.name}/cuda_bindings";
postPatch = let libCudaPath = # Use cuda_compat to provide libcuda.so on pre-Thor Jetsons if (cudaPackages.cuda_compat.meta.available or false) then cudaPackages.cuda_compat
# Else, use the host CUDA driver library else addDriverRunpath.driverLink; in '' substituteInPlace cuda/bindings/_internal/nvjitlink_linux.pyx \ --replace-fail \ "handle = dlopen('libcuda.so.1'" \ "handle = dlopen('${libCudaPath}/lib/libcuda.so.1'"
substituteInPlace cuda/bindings/_bindings/cydriver.pyx.in \ --replace-fail \ "path = 'libcuda.so.1'" \ "path = '${libCudaPath}/lib/libcuda.so.1'" '';
preBuild = '' export CUDA_PYTHON_PARALLEL_LEVEL=$NIX_BUILD_CORES '';
build-system = [ cython pyclibrary setuptools setuptools-scm ];
env = { CUDA_HOME = symlinkJoin { name = "cuda-redist"; paths = with cudaPackages; [ (lib.getInclude cuda_cudart) # cuda_runtime.h (lib.getInclude cuda_nvrtc) # nvrtc.h (lib.getInclude cuda_profiler_api) # cudaProfiler.h, cuda_profiler_api.h ]; }; };
buildInputs = [ cudaPackages.cuda_nvcc # crt/host_defines.h cudaPackages.libcufile # cufile.h ];
pythonRemoveDeps = [ # We circumvent cuda_pathfinder to localize nvidia libs with patches "cuda-pathfinder" ]; dependencies = [ # Not explicitly listed as a dependency, but is required at import time numpy ];
pythonImportsCheck = [ "cuda" "cuda.bindings.cufile" "cuda.bindings.driver" "cuda.bindings.nvfatbin" "cuda.bindings.nvjitlink" "cuda.bindings.nvml" "cuda.bindings.nvrtc" "cuda.bindings.nvvm" "cuda.bindings.runtime" ];
preCheck = '' rm -rf cuda '';
nativeCheckInputs = [ pytestCheckHook ];
enabledTestPaths = [ "tests/" ];
disabledTestPaths = [ # The current driver shipped in NixOS (590.48.01) advertises CUDA 13.1, causing the following # error: # cuda.bindings._internal.utils.NotSupportedError: only CUDA 12 driver is supported # # Ideally, we should transition to cuda 13 across the whole nixpkgs tree. "tests/test_nvjitlink.py" ];
disabledTests = [ # sysfs cpu topology is not available in the sandbox, causing: # cuda.bindings.nvml.UnknownError: Unknown Error # hwloc/linux: failed to find sysfs cpu topology directory, aborting linux discovery. "test_device_get_cpu_affinity_within_scope" "test_device_get_memory_affinity"
# Requires the nvidia_fs kernel module (GPUDirect Storage), causing: # cuda.bindings.cufile.cuFileError: NVFS_SETUP_ERROR (5033): NVFS driver initialization error "test_buf_register_already_registered" "test_buf_register_host_memory" "test_buf_register_invalid_flags" "test_buf_register_large_buffer" "test_buf_register_multiple_buffers" "test_buf_register_simple" "test_driver_open" ];
# Tests need access to a GPU doCheck = false; passthru.gpuCheck = cuda-bindings.overridePythonAttrs { requiredSystemFeatures = [ "cuda" ]; doCheck = true; };
meta = { description = "Standard set of low-level interfaces, providing access to the CUDA host APIs from Python"; homepage = "https://github.com/NVIDIA/cuda-python/tree/main/cuda_bindings"; changelog = "https://nvidia.github.io/cuda-python/${finalAttrs.version}/release/${finalAttrs.version}-notes.html"; license = lib.licenses.unfreeRedistributable; # NVIDIA Proprietary Software maintainers = with lib.maintainers; [ GaetanLepage ]; };})