|
| 1 | +# Support matrix can be found at |
| 2 | +# https://docs.nvidia.com/deeplearning/cudnn/archives/cudnn-880/support-matrix/index.html |
| 3 | +{ |
| 4 | + lib, |
| 5 | + stdenv, |
| 6 | + cudaVersion, |
| 7 | + flags, |
| 8 | + mkVersionedPackageName, |
| 9 | +}: |
| 10 | +let |
| 11 | + inherit (lib) |
| 12 | + attrsets |
| 13 | + lists |
| 14 | + modules |
| 15 | + versions |
| 16 | + strings |
| 17 | + trivial |
| 18 | + ; |
| 19 | + |
| 20 | + inherit (stdenv) hostPlatform; |
| 21 | + |
| 22 | + redistName = "cusparselt"; |
| 23 | + pname = "libcusparse_lt"; |
| 24 | + |
| 25 | + cusparseltVersions = [ |
| 26 | + "0.7.1" |
| 27 | + ]; |
| 28 | + |
| 29 | + # Manifests :: { redistrib, feature } |
| 30 | + |
| 31 | + # Each release of cusparselt gets mapped to an evaluated module for that release. |
| 32 | + # From there, we can get the min/max CUDA versions supported by that release. |
| 33 | + # listOfManifests :: List Manifests |
| 34 | + listOfManifests = |
| 35 | + let |
| 36 | + configEvaluator = |
| 37 | + fullCusparseltVersion: |
| 38 | + modules.evalModules { |
| 39 | + modules = [ |
| 40 | + ../modules |
| 41 | + # We need to nest the manifests in a config.cusparselt.manifests attribute so the |
| 42 | + # module system can evaluate them. |
| 43 | + { |
| 44 | + cusparselt.manifests = { |
| 45 | + redistrib = trivial.importJSON (./manifests + "/redistrib_${fullCusparseltVersion}.json"); |
| 46 | + feature = trivial.importJSON (./manifests + "/feature_${fullCusparseltVersion}.json"); |
| 47 | + }; |
| 48 | + } |
| 49 | + ]; |
| 50 | + }; |
| 51 | + # Un-nest the manifests attribute set. |
| 52 | + releaseGrabber = evaluatedModules: evaluatedModules.config.cusparselt.manifests; |
| 53 | + in |
| 54 | + lists.map (trivial.flip trivial.pipe [ |
| 55 | + configEvaluator |
| 56 | + releaseGrabber |
| 57 | + ]) cusparseltVersions; |
| 58 | + |
| 59 | + # Our cudaVersion tells us which version of CUDA we're building against. |
| 60 | + # The subdirectories in lib/ tell us which versions of CUDA are supported. |
| 61 | + # Typically the names will look like this: |
| 62 | + # |
| 63 | + # - 10.2 |
| 64 | + # - 11 |
| 65 | + # - 11.0 |
| 66 | + # - 12 |
| 67 | + |
| 68 | + # libPath :: String |
| 69 | + libPath = |
| 70 | + let |
| 71 | + cudaMajorMinor = versions.majorMinor cudaVersion; |
| 72 | + cudaMajor = versions.major cudaVersion; |
| 73 | + in |
| 74 | + if cudaMajorMinor == "10.2" then cudaMajorMinor else cudaMajor; |
| 75 | + |
| 76 | + # A release is supported if it has a libPath that matches our CUDA version for our platform. |
| 77 | + # LibPath are not constant across the same release -- one platform may support fewer |
| 78 | + # CUDA versions than another. |
| 79 | + # redistArch :: String |
| 80 | + redistArch = flags.getRedistArch hostPlatform.system; |
| 81 | + # platformIsSupported :: Manifests -> Boolean |
| 82 | + platformIsSupported = |
| 83 | + { feature, redistrib, ... }: |
| 84 | + (attrsets.attrByPath [ |
| 85 | + pname |
| 86 | + redistArch |
| 87 | + ] null feature) != null; |
| 88 | + |
| 89 | + # TODO(@connorbaker): With an auxiliary file keeping track of the CUDA versions each release supports, |
| 90 | + # we could filter out releases that don't support our CUDA version. |
| 91 | + # However, we don't have that currently, so we make a best-effort to try to build TensorRT with whatever |
| 92 | + # libPath corresponds to our CUDA version. |
| 93 | + # supportedManifests :: List Manifests |
| 94 | + supportedManifests = builtins.filter platformIsSupported listOfManifests; |
| 95 | + |
| 96 | + # Compute versioned attribute name to be used in this package set |
| 97 | + # Patch version changes should not break the build, so we only use major and minor |
| 98 | + # computeName :: RedistribRelease -> String |
| 99 | + computeName = { version, ... }: mkVersionedPackageName redistName version; |
| 100 | +in |
| 101 | +final: _: |
| 102 | +let |
| 103 | + # buildCusparseltPackage :: Manifests -> AttrSet Derivation |
| 104 | + buildCusparseltPackage = |
| 105 | + { redistrib, feature }: |
| 106 | + let |
| 107 | + drv = final.callPackage ../generic-builders/manifest.nix { |
| 108 | + inherit pname redistName; |
| 109 | + redistribRelease = redistrib.${pname}; |
| 110 | + featureRelease = feature.${pname}; |
| 111 | + }; |
| 112 | + fixedDrv = drv.overrideAttrs (prevAttrs: { |
| 113 | + buildInputs = |
| 114 | + prevAttrs.buildInputs |
| 115 | + ++ lists.optionals (strings.versionOlder cudaVersion "11.4") [ final.cudatoolkit ] |
| 116 | + ++ lists.optionals (strings.versionAtLeast cudaVersion "11.4") ( |
| 117 | + [ final.libcublas.lib ] |
| 118 | + # For some reason, the 1.4.x release of cusparselt requires the cudart library. |
| 119 | + ++ lists.optionals (strings.hasPrefix "1.4" redistrib.${pname}.version) [ final.cuda_cudart.lib ] |
| 120 | + ); |
| 121 | + meta = prevAttrs.meta // { |
| 122 | + description = "cuSPARSELt: A High-Performance CUDA Library for Sparse Matrix-Matrix Multiplication"; |
| 123 | + homepage = "https://developer.nvidia.com/cusparselt-downloads"; |
| 124 | + |
| 125 | + maintainers = prevAttrs.meta.maintainers ++ [ lib.maintainers.sepiabrown ]; |
| 126 | + license = lib.licenses.unfreeRedistributable // { |
| 127 | + shortName = "cuSPARSELt EULA"; |
| 128 | + fullName = "cuSPARSELt SUPPLEMENT TO SOFTWARE LICENSE AGREEMENT FOR NVIDIA SOFTWARE DEVELOPMENT KITS"; |
| 129 | + url = "https://docs.nvidia.com/cuda/cusparselt/license.html"; |
| 130 | + }; |
| 131 | + }; |
| 132 | + }); |
| 133 | + in |
| 134 | + attrsets.nameValuePair (computeName redistrib.${pname}) fixedDrv; |
| 135 | + |
| 136 | + extension = |
| 137 | + let |
| 138 | + nameOfNewest = computeName (lists.last supportedManifests).redistrib.${pname}; |
| 139 | + drvs = builtins.listToAttrs (lists.map buildCusparseltPackage supportedManifests); |
| 140 | + containsDefault = attrsets.optionalAttrs (drvs != { }) { cusparselt = drvs.${nameOfNewest}; }; |
| 141 | + in |
| 142 | + drvs // containsDefault; |
| 143 | +in |
| 144 | +extension |
0 commit comments