Merge pull request #218166 from ConnorBaker/feat/tiny-cuda-nn

tiny-cuda-nn,python3Packages.tiny-cuda-nn: init 1.6

authored by

Samuel Ainsworth and committed by
GitHub
49fd723a 2676c648

+160
+152
pkgs/development/libraries/science/math/tiny-cuda-nn/default.nix
··· 1 + { cmake 2 + , cudaPackages 3 + , fetchFromGitHub 4 + , lib 5 + , ninja 6 + , pkgs 7 + , python3Packages ? { } 8 + , pythonSupport ? false 9 + , stdenv 10 + , symlinkJoin 11 + , which 12 + }: 13 + let 14 + inherit (lib) lists strings; 15 + inherit (cudaPackages) backendStdenv cudaFlags; 16 + 17 + cuda-common-redist = with cudaPackages; [ 18 + libcublas # cublas_v2.h 19 + libcusolver # cusolverDn.h 20 + libcusparse # cusparse.h 21 + ]; 22 + 23 + cuda-native-redist = symlinkJoin { 24 + name = "cuda-redist"; 25 + paths = with cudaPackages; [ 26 + cuda_cudart # cuda_runtime.h 27 + cuda_nvcc 28 + ] ++ cuda-common-redist; 29 + }; 30 + 31 + cuda-redist = symlinkJoin { 32 + name = "cuda-redist"; 33 + paths = cuda-common-redist; 34 + }; 35 + in 36 + stdenv.mkDerivation (finalAttrs: { 37 + name = "tiny-cuda-nn"; 38 + version = "1.6"; 39 + 40 + format = strings.optionalString pythonSupport "setuptools"; 41 + 42 + src = fetchFromGitHub { 43 + owner = "NVlabs"; 44 + repo = finalAttrs.name; 45 + rev = "v${finalAttrs.version}"; 46 + fetchSubmodules = true; 47 + hash = "sha256-qW6Fk2GB71fvZSsfu+mykabSxEKvaikZ/pQQZUycOy0="; 48 + }; 49 + 50 + nativeBuildInputs = [ 51 + cmake 52 + cuda-native-redist 53 + ninja 54 + which 55 + ] ++ lists.optionals pythonSupport (with python3Packages; [ 56 + pip 57 + setuptools 58 + wheel 59 + ]); 60 + 61 + buildInputs = [ 62 + cuda-redist 63 + ] ++ lib.optionals pythonSupport ( 64 + with python3Packages; [ 65 + pybind11 66 + python 67 + ] 68 + ); 69 + 70 + propagatedBuildInputs = lib.optionals pythonSupport ( 71 + with python3Packages; [ 72 + torch 73 + ] 74 + ); 75 + 76 + # NOTE: We cannot use pythonImportsCheck for this module because it uses torch to immediately 77 + # initailize CUDA and GPU access is not allowed in the nix build environment. 78 + # NOTE: There are no tests for the C++ library or the python bindings, so we just skip the check 79 + # phase -- we're not missing anything. 80 + doCheck = false; 81 + 82 + preConfigure = '' 83 + export TCNN_CUDA_ARCHITECTURES=${ 84 + strings.concatStringsSep ";" (lists.map cudaFlags.dropDot cudaFlags.cudaCapabilities) 85 + } 86 + export CUDA_HOME=${cuda-native-redist} 87 + export LIBRARY_PATH=${cuda-native-redist}/lib/stubs:$LIBRARY_PATH 88 + export CC=${backendStdenv.cc}/bin/cc 89 + export CXX=${backendStdenv.cc}/bin/c++ 90 + ''; 91 + 92 + # When building the python bindings, we cannot re-use the artifacts from the C++ build so we 93 + # skip the CMake confurePhase and the buildPhase. 94 + dontUseCmakeConfigure = pythonSupport; 95 + 96 + # The configurePhase usually puts you in the build directory, so for the python bindings we 97 + # need to change directories to the source directory. 98 + configurePhase = strings.optionalString pythonSupport '' 99 + runHook preConfigure 100 + mkdir -p $NIX_BUILD_TOP/build 101 + cd $NIX_BUILD_TOP/build 102 + runHook postConfigure 103 + ''; 104 + 105 + buildPhase = strings.optionalString pythonSupport '' 106 + runHook preBuild 107 + python -m pip wheel \ 108 + --no-build-isolation \ 109 + --no-clean \ 110 + --no-deps \ 111 + --no-index \ 112 + --verbose \ 113 + --wheel-dir $NIX_BUILD_TOP/build \ 114 + $NIX_BUILD_TOP/source/bindings/torch 115 + runHook postBuild 116 + ''; 117 + 118 + installPhase = '' 119 + runHook preInstall 120 + mkdir -p $out/lib 121 + '' 122 + # Installing the C++ library just requires copying the static library to the output directory 123 + + strings.optionalString (!pythonSupport) '' 124 + cp libtiny-cuda-nn.a $out/lib/ 125 + '' 126 + # Installing the python bindings requires building the wheel and installing it 127 + + strings.optionalString pythonSupport '' 128 + python -m pip install \ 129 + --no-build-isolation \ 130 + --no-cache-dir \ 131 + --no-deps \ 132 + --no-index \ 133 + --no-warn-script-location \ 134 + --prefix="$out" \ 135 + --verbose \ 136 + ./*.whl 137 + '' + '' 138 + runHook postInstall 139 + ''; 140 + 141 + passthru = { 142 + inherit cudaPackages; 143 + }; 144 + 145 + meta = with lib; { 146 + description = "Lightning fast C++/CUDA neural network framework"; 147 + homepage = "https://github.com/NVlabs/tiny-cuda-nn"; 148 + license = licenses.bsd3; 149 + maintainers = with maintainers; [ connorbaker ]; 150 + platforms = platforms.linux; 151 + }; 152 + })
+2
pkgs/top-level/all-packages.nix
··· 3822 3822 3823 3823 tensorflow-lite = callPackage ../development/libraries/science/math/tensorflow-lite { }; 3824 3824 3825 + tiny-cuda-nn = callPackage ../development/libraries/science/math/tiny-cuda-nn { }; 3826 + 3825 3827 tezos-rust-libs = callPackage ../development/libraries/tezos-rust-libs { }; 3826 3828 3827 3829 behave = with python3Packages; toPythonApplication behave;
+6
pkgs/top-level/python-packages.nix
··· 11702 11702 11703 11703 timm = callPackage ../development/python-modules/timm { }; 11704 11704 11705 + tiny-cuda-nn = toPythonModule (pkgs.tiny-cuda-nn.override { 11706 + cudaPackages = self.torch.cudaPackages; 11707 + python3Packages = self; 11708 + pythonSupport = true; 11709 + }); 11710 + 11705 11711 tinycss2 = callPackage ../development/python-modules/tinycss2 { }; 11706 11712 11707 11713 tinycss = callPackage ../development/python-modules/tinycss { };