magma: init 2.7.1; migrate to cudaPackages

authored by Connor Baker and committed by Connor Baker 434c3ea4 308dfa93

+309 -80
+42 -72
pkgs/development/libraries/science/math/magma/default.nix
··· 1 - { lib 2 - , stdenv 3 - , fetchurl 4 - , cmake 5 - , ninja 6 - , gfortran 7 - , libpthreadstubs 8 - , lapack 9 - , blas 10 - , cudaPackages 11 - , hip 12 - , hipblas 13 - , hipsparse 14 - , openmp 15 - , useCUDA ? true 16 - , useROCM ? false 17 - , gpuTargets ? [ ] 1 + args@{ callPackage 2 + , lib 3 + , ... 18 4 }: 19 5 6 + # Type aliases 7 + # Release = { 8 + # version: String 9 + # hash: String 10 + # supportedGpuTargets: List String 11 + # } 12 + 20 13 let 21 - inherit (cudaPackages) cudatoolkit cudaFlags; 22 - in stdenv.mkDerivation (finalAttrs: { 23 - pname = "magma"; 24 - version = "2.6.2"; 14 + inherit (lib) lists strings trivial; 25 15 26 - src = fetchurl { 27 - name = "magma-${finalAttrs.version}.tar.gz"; 28 - url = "https://icl.cs.utk.edu/projectsfiles/magma/downloads/magma-${finalAttrs.version}.tar.gz"; 29 - hash = "sha256-dbVU2rAJA+LRC5cskT5Q5/iMvGLzrkMrWghsfk7aCnE="; 30 - }; 16 + computeName = version: "magma_${strings.replaceStrings [ "." ] [ "_" ] version}"; 31 17 32 - nativeBuildInputs = [ 33 - cmake 34 - ninja 35 - gfortran 36 - ]; 18 + # buildMagmaPackage :: Release -> Derivation 19 + buildMagmaPackage = magmaRelease: callPackage ./generic.nix ( 20 + (builtins.removeAttrs args [ "callPackage" ]) // { 21 + inherit magmaRelease; 22 + } 23 + ); 37 24 38 - buildInputs = [ 39 - libpthreadstubs 40 - lapack 41 - blas 42 - ] ++ lib.optionals useCUDA [ 43 - cudatoolkit 44 - ] ++ lib.optionals useROCM [ 45 - hip 46 - hipblas 47 - hipsparse 48 - openmp 49 - ]; 25 + # Reverse the list to have the latest release first 26 + # magmaReleases :: List Release 27 + magmaReleases = lists.reverseList (builtins.import ./releases.nix); 28 + 29 + # The latest release is the first element of the list and will be our default choice 30 + # latestReleaseName :: String 31 + latestReleaseName = computeName (builtins.head magmaReleases).version; 32 + 33 + # Function to transform our releases into build attributes 34 + # toBuildAttrs :: Release -> { name: String, value: Derivation } 35 + toBuildAttrs = release: { 36 + name = computeName release.version; 37 + value = buildMagmaPackage release; 38 + }; 50 39 51 - cmakeFlags = lib.optionals useCUDA [ 52 - "-DCMAKE_C_COMPILER=${cudatoolkit.cc}/bin/gcc" 53 - "-DCMAKE_CXX_COMPILER=${cudatoolkit.cc}/bin/g++" 54 - "-DMAGMA_ENABLE_CUDA=ON" 55 - "-DGPU_TARGET=${builtins.concatStringsSep "," cudaFlags.cudaRealArches}" 56 - ] ++ lib.optionals useROCM [ 57 - "-DCMAKE_C_COMPILER=${hip}/bin/hipcc" 58 - "-DCMAKE_CXX_COMPILER=${hip}/bin/hipcc" 59 - "-DMAGMA_ENABLE_HIP=ON" 60 - "-DGPU_TARGET=${builtins.concatStringsSep "," (if gpuTargets == [ ] then hip.gpuTargets else gpuTargets)}" 61 - ]; 40 + # Add all supported builds as attributes 41 + # allBuilds :: AttrSet String Derivation 42 + allBuilds = builtins.listToAttrs (lists.map toBuildAttrs magmaReleases); 62 43 63 - buildFlags = [ 64 - "magma" 65 - "magma_sparse" 66 - ]; 44 + # The latest release will be our default build 45 + # defaultBuild :: AttrSet String Derivation 46 + defaultBuild.magma = allBuilds.${latestReleaseName}; 67 47 68 - doCheck = false; 48 + # builds :: AttrSet String Derivation 49 + builds = allBuilds // defaultBuild; 50 + in 69 51 70 - passthru = { 71 - inherit cudatoolkit; 72 - }; 52 + builds 73 53 74 - meta = with lib; { 75 - description = "Matrix Algebra on GPU and Multicore Architectures"; 76 - license = licenses.bsd3; 77 - homepage = "http://icl.cs.utk.edu/magma/index.html"; 78 - platforms = platforms.unix; 79 - maintainers = with maintainers; [ tbenst ]; 80 - # CUDA and ROCm are mutually exclusive 81 - broken = useCUDA && useROCM || useCUDA && versionOlder cudatoolkit.version "9"; 82 - }; 83 - })
+160
pkgs/development/libraries/science/math/magma/generic.nix
··· 1 + # Type aliases 2 + # Release = { 3 + # version: String 4 + # hash: String 5 + # supportedGpuTargets: List String 6 + # } 7 + 8 + { blas 9 + , cmake 10 + , cudaPackages 11 + , cudaSupport ? true 12 + , fetchurl 13 + , gfortran 14 + , gpuTargets ? [ ] 15 + , hip 16 + , hipblas 17 + , hipsparse 18 + , lapack 19 + , lib 20 + , libpthreadstubs 21 + , magmaRelease 22 + , ninja 23 + , openmp 24 + , rocmSupport ? false 25 + , stdenv 26 + , symlinkJoin 27 + }: 28 + 29 + 30 + let 31 + inherit (lib) lists strings trivial; 32 + inherit (cudaPackages) cudatoolkit cudaFlags cudaVersion; 33 + inherit (magmaRelease) version hash supportedGpuTargets; 34 + 35 + # NOTE: The lists.subtractLists function is perhaps a bit unintuitive. It subtracts the elements 36 + # of the first list *from* the second list. That means: 37 + # lists.subtractLists a b = b - a 38 + 39 + # For CUDA 40 + supportedCudaSmArches = lists.intersectLists cudaFlags.cudaRealArches supportedGpuTargets; 41 + # Subtract the supported SM architectures from the real SM architectures to get the unsupported 42 + # SM architectures. 43 + unsupportedCudaSmArches = lists.subtractLists supportedCudaSmArches cudaFlags.cudaRealArches; 44 + 45 + # For ROCm 46 + # NOTE: The hip.gpuTargets are prefixed with "gfx" instead of "sm" like cudaFlags.cudaRealArches. 47 + # For some reason, Magma's CMakeLists.txt file does not handle the "gfx" prefix, so we must 48 + # remove it. 49 + rocmArches = lists.map (x: strings.removePrefix "gfx" x) hip.gpuTargets; 50 + supportedRocmArches = lists.intersectLists rocmArches supportedGpuTargets; 51 + unsupportedRocmArches = lists.subtractLists supportedRocmArches rocmArches; 52 + 53 + supportedCustomGpuTargets = lists.intersectLists gpuTargets supportedGpuTargets; 54 + unsupportedCustomGpuTargets = lists.subtractLists supportedCustomGpuTargets gpuTargets; 55 + 56 + # Use trivial.warnIf to print a warning if any unsupported GPU targets are specified. 57 + gpuArchWarner = supported: unsupported: 58 + trivial.throwIf (supported == [ ]) 59 + ( 60 + "No supported GPU targets specified. Requested GPU targets: " 61 + + strings.concatStringsSep ", " unsupported 62 + ) 63 + supported; 64 + 65 + # Create the gpuTargetString. 66 + gpuTargetString = strings.concatStringsSep "," ( 67 + if gpuTargets != [ ] then 68 + # If gpuTargets is specified, it always takes priority. 69 + gpuArchWarner supportedCustomGpuTargets unsupportedCustomGpuTargets 70 + else if cudaSupport then 71 + gpuArchWarner supportedCudaSmArches unsupportedCudaSmArches 72 + else if rocmSupport then 73 + gpuArchWarner supportedRocmArches unsupportedRocmArches 74 + else 75 + throw "No GPU targets specified" 76 + ); 77 + 78 + cuda_joined = symlinkJoin { 79 + name = "cuda-redist-${cudaVersion}"; 80 + paths = with cudaPackages; [ 81 + cuda_nvcc 82 + cuda_cudart # cuda_runtime.h 83 + libcublas 84 + libcusparse 85 + cuda_nvprof # <cuda_profiler_api.h> 86 + ]; 87 + }; 88 + in 89 + 90 + stdenv.mkDerivation { 91 + pname = "magma"; 92 + inherit version; 93 + 94 + src = fetchurl { 95 + name = "magma-${version}.tar.gz"; 96 + url = "https://icl.cs.utk.edu/projectsfiles/magma/downloads/magma-${version}.tar.gz"; 97 + inherit hash; 98 + }; 99 + 100 + nativeBuildInputs = [ 101 + cmake 102 + ninja 103 + gfortran 104 + ]; 105 + 106 + buildInputs = [ 107 + libpthreadstubs 108 + lapack 109 + blas 110 + ] ++ lists.optionals cudaSupport [ 111 + cuda_joined 112 + ] ++ lists.optionals rocmSupport [ 113 + hip 114 + hipblas 115 + hipsparse 116 + openmp 117 + ]; 118 + 119 + cmakeFlags = lists.optionals cudaSupport [ 120 + "-DCMAKE_C_COMPILER=${cudatoolkit.cc}/bin/cc" 121 + "-DCMAKE_CXX_COMPILER=${cudatoolkit.cc}/bin/c++" 122 + "-DMAGMA_ENABLE_CUDA=ON" 123 + ] ++ lists.optionals rocmSupport [ 124 + "-DCMAKE_C_COMPILER=${hip}/bin/hipcc" 125 + "-DCMAKE_CXX_COMPILER=${hip}/bin/hipcc" 126 + "-DMAGMA_ENABLE_HIP=ON" 127 + ]; 128 + 129 + # NOTE: We must set GPU_TARGET in preConfigure in this way because it may contain spaces. 130 + preConfigure = '' 131 + cmakeFlagsArray+=("-DGPU_TARGET=${gpuTargetString}") 132 + '' 133 + # NOTE: The stdenv's CXX is used when compiling the CMake test to determine the version of 134 + # CUDA available. This isn't necessarily the same as cudatoolkit.cc, so we must set 135 + # CUDAHOSTCXX. 136 + + strings.optionalString cudaSupport '' 137 + export CUDAHOSTCXX=${cudatoolkit.cc}/bin/c++ 138 + ''; 139 + 140 + buildFlags = [ 141 + "magma" 142 + "magma_sparse" 143 + ]; 144 + 145 + doCheck = false; 146 + 147 + passthru = { 148 + inherit cudaPackages cudaSupport; 149 + }; 150 + 151 + meta = with lib; { 152 + description = "Matrix Algebra on GPU and Multicore Architectures"; 153 + license = licenses.bsd3; 154 + homepage = "http://icl.cs.utk.edu/magma/index.html"; 155 + platforms = platforms.unix; 156 + maintainers = with maintainers; [ tbenst ]; 157 + # CUDA and ROCm are mutually exclusive 158 + broken = cudaSupport && rocmSupport || cudaSupport && strings.versionOlder cudaVersion "9"; 159 + }; 160 + }
+98
pkgs/development/libraries/science/math/magma/releases.nix
··· 1 + # NOTE: Order matters! Put the oldest version first, and the newest version last. 2 + # NOTE: Make sure the supportedGpuTargets are in order of oldest to newest. 3 + # You can update the supportedGpuTargets by looking at the CMakeLists.txt file. 4 + # CUDA starts here: https://bitbucket.org/icl/magma/src/f4ec79e2c13a2347eff8a77a3be6f83bc2daec20/CMakeLists.txt#lines-175 5 + # HIP is here: https://bitbucket.org/icl/magma/src/f4ec79e2c13a2347eff8a77a3be6f83bc2daec20/CMakeLists.txt#lines-386 6 + [ 7 + { 8 + version = "2.6.2"; 9 + hash = "sha256-dbVU2rAJA+LRC5cskT5Q5/iMvGLzrkMrWghsfk7aCnE="; 10 + supportedGpuTargets = [ 11 + "sm_20" 12 + "sm_30" 13 + "sm_35" 14 + "sm_37" 15 + "sm_50" 16 + "sm_52" 17 + "sm_53" 18 + "sm_60" 19 + "sm_61" 20 + "sm_62" 21 + "sm_70" 22 + "sm_71" 23 + "sm_75" 24 + "sm_80" 25 + "700" 26 + "701" 27 + "702" 28 + "703" 29 + "704" 30 + "705" 31 + "801" 32 + "802" 33 + "803" 34 + "805" 35 + "810" 36 + "900" 37 + "902" 38 + "904" 39 + "906" 40 + "908" 41 + "909" 42 + "90c" 43 + "1010" 44 + "1011" 45 + "1012" 46 + "1030" 47 + "1031" 48 + "1032" 49 + "1033" 50 + ]; 51 + } 52 + { 53 + version = "2.7.1"; 54 + hash = "sha256-2chxHAR6OMrhbv3nS+4uszMyF/0nEeHpuGBsu7SuGlA="; 55 + supportedGpuTargets = [ 56 + "sm_20" 57 + "sm_30" 58 + "sm_35" 59 + "sm_37" 60 + "sm_50" 61 + "sm_52" 62 + "sm_53" 63 + "sm_60" 64 + "sm_61" 65 + "sm_62" 66 + "sm_70" 67 + "sm_71" 68 + "sm_75" 69 + "sm_80" 70 + "sm_90" 71 + "700" 72 + "701" 73 + "702" 74 + "703" 75 + "704" 76 + "705" 77 + "801" 78 + "802" 79 + "803" 80 + "805" 81 + "810" 82 + "900" 83 + "902" 84 + "904" 85 + "906" 86 + "908" 87 + "909" 88 + "90c" 89 + "1010" 90 + "1011" 91 + "1012" 92 + "1030" 93 + "1031" 94 + "1032" 95 + "1033" 96 + ]; 97 + } 98 + ]
+1 -1
pkgs/development/python-modules/torch/default.nix
··· 51 51 52 52 # confirm that cudatoolkits are sync'd across dependencies 53 53 assert !(MPISupport && cudaSupport) || mpi.cudatoolkit == cudatoolkit; 54 - assert !cudaSupport || magma.cudatoolkit == cudatoolkit; 54 + assert !cudaSupport || magma.cudaPackages.cudatoolkit == cudatoolkit; 55 55 56 56 let 57 57 setBool = v: if v then "1" else "0";
+8 -7
pkgs/top-level/all-packages.nix
··· 36661 36661 36662 36662 lie = callPackage ../applications/science/math/LiE { }; 36663 36663 36664 - magma = callPackage ../development/libraries/science/math/magma { 36664 + inherit (callPackage ../development/libraries/science/math/magma { 36665 36665 inherit (llvmPackages_rocm) openmp; 36666 - }; 36666 + }) magma magma_2_7_1 magma_2_6_2; 36667 36667 36668 36668 magma-cuda = magma.override { 36669 - useCUDA = true; 36670 - useROCM = false; 36669 + cudaSupport = true; 36670 + rocmSupport = false; 36671 36671 }; 36672 36672 36673 - magma-hip = magma.override { 36674 - useCUDA = false; 36675 - useROCM = true; 36673 + # TODO:AMD won't compile with anything newer than 2.6.2 -- it fails at the linking stage. 36674 + magma-hip = magma_2_6_2.override { 36675 + cudaSupport = false; 36676 + rocmSupport = true; 36676 36677 }; 36677 36678 36678 36679 clmagma = callPackage ../development/libraries/science/math/clmagma { };