Clone of https://github.com/NixOS/nixpkgs.git (to stress-test knotserver)
at 23.05 197 lines 5.2 kB view raw
1{ lib 2, stdenv 3, fetchFromGitHub 4, fetchpatch 5, rocmUpdateScript 6, substituteAll 7, makeWrapper 8, hip-common 9, hipcc 10, rocclr 11, roctracer 12, cmake 13, perl 14, llvm 15, rocminfo 16, rocm-thunk 17, rocm-comgr 18, rocm-device-libs 19, rocm-runtime 20, rocm-opencl-runtime 21, cudatoolkit 22, numactl 23, libxml2 24, libX11 25, libglvnd 26, doxygen 27, graphviz 28, fontconfig 29, python3Packages 30, buildDocs ? true 31, buildTests ? false 32, useNVIDIA ? false 33}: 34 35let 36 hipPlatform = if useNVIDIA then "nvidia" else "amd"; 37 38 wrapperArgs = [ 39 "--prefix PATH : $out/bin" 40 "--prefix LD_LIBRARY_PATH : ${rocm-runtime}" 41 "--set HIP_PLATFORM ${hipPlatform}" 42 "--set HIP_PATH $out" 43 "--set HIP_CLANG_PATH ${stdenv.cc}/bin" 44 "--set DEVICE_LIB_PATH ${rocm-device-libs}/amdgcn/bitcode" 45 "--set HSA_PATH ${rocm-runtime}" 46 "--set ROCM_PATH $out" 47 ] ++ lib.optionals useNVIDIA [ 48 "--set CUDA_PATH ${cudatoolkit}" 49 ]; 50in stdenv.mkDerivation (finalAttrs: { 51 pname = "hip-${hipPlatform}"; 52 version = "5.4.4"; 53 54 outputs = [ 55 "out" 56 ] ++ lib.optionals buildDocs [ 57 "doc" 58 ]; 59 60 src = fetchFromGitHub { 61 owner = "ROCm-Developer-Tools"; 62 repo = "hipamd"; 63 rev = "rocm-${finalAttrs.version}"; 64 hash = "sha256-FcuylhkG7HqLYXH1J6ND6IVEIbDzHp7h7jg2ZZ4XoFM="; 65 }; 66 67 patches = [ 68 (substituteAll { 69 src = ./0000-fixup-paths.patch; 70 inherit llvm; 71 clang = stdenv.cc; 72 rocm_runtime = rocm-runtime; 73 }) 74 75 # https://github.com/ROCm-Developer-Tools/hipamd/commit/be33ec55acc104a59d01df5912261d007c7f3ee9 76 (fetchpatch { 77 url = "https://github.com/ROCm-Developer-Tools/hipamd/commit/be33ec55acc104a59d01df5912261d007c7f3ee9.patch"; 78 hash = "sha256-eTC4mUIN1FwRce1n38uDOlITFL/vpcOhvnaZTo5R7lo="; 79 }) 80 ]; 81 82 nativeBuildInputs = [ 83 makeWrapper 84 cmake 85 perl 86 python3Packages.python 87 python3Packages.cppheaderparser 88 ] ++ lib.optionals buildDocs [ 89 doxygen 90 graphviz 91 fontconfig 92 ]; 93 94 buildInputs = [ 95 numactl 96 libxml2 97 libX11 98 libglvnd 99 ]; 100 101 propagatedBuildInputs = [ 102 stdenv.cc 103 llvm 104 rocminfo 105 rocm-thunk 106 rocm-comgr 107 rocm-device-libs 108 rocm-runtime 109 rocm-opencl-runtime 110 ] ++ lib.optionals useNVIDIA [ 111 cudatoolkit 112 ]; 113 114 cmakeFlags = [ 115 "-DROCM_PATH=${rocminfo}" 116 "-DHIP_PLATFORM=${hipPlatform}" 117 "-DHIP_COMMON_DIR=${hip-common}" 118 "-DHIPCC_BIN_DIR=${hipcc}/bin" 119 "-DHIP_LLVM_ROOT=${stdenv.cc}" 120 "-DROCCLR_PATH=${rocclr}" 121 "-DAMD_OPENCL_PATH=${rocm-opencl-runtime.src}" 122 "-DPROF_API_HEADER_PATH=${roctracer.src}/inc/ext" 123 # Temporarily set variables to work around upstream CMakeLists issue 124 # Can be removed once https://github.com/ROCm-Developer-Tools/hipamd/issues/55 is fixed 125 "-DCMAKE_INSTALL_BINDIR=bin" 126 "-DCMAKE_INSTALL_INCLUDEDIR=include" 127 "-DCMAKE_INSTALL_LIBDIR=lib" 128 ] ++ lib.optionals buildTests [ 129 "-DHIP_CATCH_TEST=1" 130 ]; 131 132 postPatch = '' 133 export HIP_CLANG_PATH=${stdenv.cc}/bin 134 patchShebangs src 135 '' + lib.optionalString buildDocs '' 136 export HOME=$(mktemp -d) 137 export FONTCONFIG_FILE=${fontconfig.out}/etc/fonts/fonts.conf 138 ''; 139 140 doCheck = buildTests; 141 checkTarget = "build_tests"; 142 143 preCheck = lib.optionalString buildTests '' 144 export ROCM_PATH=$PWD 145 export DEVICE_LIB_PATH=${rocm-device-libs}/amdgcn/bitcode 146 patchShebangs bin 147 ''; 148 149 postInstall = '' 150 patchShebangs $out/bin 151 cp -a $out/bin/hipcc $out/bin/hipcc-pl 152 cp -a $out/bin/hipconfig $out/bin/hipconfig-pl 153 wrapProgram $out/bin/hipcc --set HIP_USE_PERL_SCRIPTS 0 154 wrapProgram $out/bin/hipconfig --set HIP_USE_PERL_SCRIPTS 0 155 wrapProgram $out/bin/hipcc.bin ${lib.concatStringsSep " " wrapperArgs} 156 wrapProgram $out/bin/hipconfig.bin ${lib.concatStringsSep " " wrapperArgs} 157 wrapProgram $out/bin/hipcc-pl --set HIP_USE_PERL_SCRIPTS 1 158 wrapProgram $out/bin/hipconfig-pl --set HIP_USE_PERL_SCRIPTS 1 159 wrapProgram $out/bin/hipcc.pl ${lib.concatStringsSep " " wrapperArgs} 160 wrapProgram $out/bin/hipconfig.pl ${lib.concatStringsSep " " wrapperArgs} 161 ''; 162 163 passthru = { 164 # All known and valid general GPU targets 165 # We cannot use this for each ROCm library, as each defines their own supported targets 166 # See: https://github.com/RadeonOpenCompute/ROCm/blob/77cbac4abab13046ee93d8b5bf410684caf91145/README.md#library-target-matrix 167 gpuTargets = lib.forEach [ 168 "803" 169 "900" 170 "906" 171 "908" 172 "90a" 173 "1010" 174 "1012" 175 "1030" 176 ] (target: "gfx${target}"); 177 178 updateScript = rocmUpdateScript { 179 name = finalAttrs.pname; 180 owner = finalAttrs.src.owner; 181 repo = finalAttrs.src.repo; 182 }; 183 }; 184 185 meta = with lib; { 186 description = "C++ Heterogeneous-Compute Interface for Portability specifically for AMD platform"; 187 homepage = "https://github.com/ROCm-Developer-Tools/hipamd"; 188 license = with licenses; [ mit ]; 189 maintainers = with maintainers; [ lovesegfault ] ++ teams.rocm.members; 190 platforms = platforms.linux; 191 # Tests require GPU, also include issues 192 broken = 193 versions.minor finalAttrs.version != versions.minor hip-common.version || 194 versions.minor finalAttrs.version != versions.minor hipcc.version || 195 buildTests; 196 }; 197})