at 23.05-pre 206 lines 6.9 kB view raw
1{ stdenv 2, binutils-unwrapped 3, clang 4, cmake 5, fetchFromGitHub 6, fetchpatch 7, file 8, lib 9, libglvnd 10, libX11 11, libxml2 12, llvm 13, makeWrapper 14, numactl 15, perl 16, python3 17, python3Packages 18, rocclr 19, rocm-comgr 20, rocm-device-libs 21, rocm-opencl-runtime 22, rocm-runtime 23, rocm-thunk 24, rocminfo 25, substituteAll 26, writeScript 27, writeText 28}: 29 30let 31 hip = stdenv.mkDerivation rec { 32 pname = "hip"; 33 version = "5.3.1"; 34 35 src = fetchFromGitHub { 36 owner = "ROCm-Developer-Tools"; 37 repo = "HIP"; 38 rev = "rocm-${version}"; 39 hash = "sha256-kmRvrwnT0h2dBMI+H9d1vmeW3TmDBD+qW4YYhaMV2dE="; 40 }; 41 42 patches = [ 43 (substituteAll { 44 src = ./hip-config-paths.patch; 45 inherit llvm; 46 rocm_runtime = rocm-runtime; 47 }) 48 ]; 49 50 # - fix bash paths 51 # - fix path to rocm_agent_enumerator 52 # - fix hcc path 53 # - fix hcc version parsing 54 # - add linker flags for libhsa-runtime64 and hc_am since libhip_hcc 55 # refers to them. 56 prePatch = '' 57 for f in $(find bin -type f); do 58 sed -e 's,#!/usr/bin/perl,#!${perl}/bin/perl,' \ 59 -e 's,#!/bin/bash,#!${stdenv.shell},' \ 60 -i "$f" 61 done 62 63 substituteInPlace bin/hip_embed_pch.sh \ 64 --replace '$LLVM_DIR/bin/' "" 65 66 sed 's,#!/usr/bin/python,#!${python3.interpreter},' -i hip_prof_gen.py 67 68 sed -e 's,$ROCM_AGENT_ENUM = "''${ROCM_PATH}/bin/rocm_agent_enumerator";,$ROCM_AGENT_ENUM = "${rocminfo}/bin/rocm_agent_enumerator";,' \ 69 -e 's,^\($DEVICE_LIB_PATH=\).*$,\1"${rocm-device-libs}/amdgcn/bitcode";,' \ 70 -e 's,^\($HIP_COMPILER=\).*$,\1"clang";,' \ 71 -e 's,^\($HIP_RUNTIME=\).*$,\1"ROCclr";,' \ 72 -e 's,^\([[:space:]]*$HSA_PATH=\).*$,\1"${rocm-runtime}";,'g \ 73 -e 's,^\([[:space:]]*\)$HIP_CLANG_INCLUDE_PATH = abs_path("$HIP_CLANG_PATH/../lib/clang/$HIP_CLANG_VERSION/include");,\1$HIP_CLANG_INCLUDE_PATH = "${llvm}/lib/clang/$HIP_CLANG_VERSION/include";,' \ 74 -e 's,^\([[:space:]]*$HIPCXXFLAGS .= " -isystem \\"$HIP_CLANG_INCLUDE_PATH/..\\"\)";,\1 -isystem ${rocm-runtime}/include";,' \ 75 -e 's,$HIP_CLANG_PATH/../lib/clang/$HIP_CLANG_VERSION,$HIP_CLANG_PATH/../resource-root,g' \ 76 -e 's,`file,`${file}/bin/file,g' \ 77 -e 's,`readelf,`${binutils-unwrapped}/bin/readelf,' \ 78 -e 's, ar , ${binutils-unwrapped}/bin/ar ,g' \ 79 -i bin/hipcc.pl 80 81 sed -e 's,^\($HSA_PATH=\).*$,\1"${rocm-runtime}";,' \ 82 -e 's,^\($HIP_CLANG_PATH=\).*$,\1"${clang}/bin";,' \ 83 -e 's,^\($HIP_PLATFORM=\).*$,\1"amd";,' \ 84 -e 's,$HIP_CLANG_PATH/llc,${llvm}/bin/llc,' \ 85 -e 's, abs_path, Cwd::abs_path,' \ 86 -i bin/hipconfig.pl 87 88 sed -e 's, abs_path, Cwd::abs_path,' -i bin/hipvars.pm 89 ''; 90 91 buildPhase = ""; 92 93 installPhase = '' 94 runHook preInstall 95 96 mkdir -p $out 97 cp -r * $out/ 98 99 runHook postInstall 100 ''; 101 102 meta = with lib; { 103 description = "C++ Heterogeneous-Compute Interface for Portability"; 104 homepage = "https://github.com/ROCm-Developer-Tools/HIP"; 105 license = licenses.mit; 106 maintainers = with maintainers; [ lovesegfault Flakebi ]; 107 platforms = platforms.linux; 108 }; 109 }; 110in 111stdenv.mkDerivation rec { 112 pname = "hip"; 113 version = "5.3.1"; 114 115 src = fetchFromGitHub { 116 owner = "ROCm-Developer-Tools"; 117 repo = "hipamd"; 118 rev = "rocm-${version}"; 119 hash = "sha256-i7hT/j+V0LT6Va2XcQyyKXF1guoIyhcOHvn842wCRx4="; 120 }; 121 122 nativeBuildInputs = [ cmake python3 makeWrapper perl ]; 123 buildInputs = [ libxml2 numactl libglvnd libX11 python3Packages.cppheaderparser ]; 124 propagatedBuildInputs = [ 125 clang 126 llvm 127 rocm-comgr 128 rocm-device-libs 129 rocm-runtime 130 rocm-thunk 131 rocminfo 132 ]; 133 134 patches = [ 135 (substituteAll { 136 src = ./hipamd-config-paths.patch; 137 inherit clang llvm hip; 138 rocm_runtime = rocm-runtime; 139 }) 140 ]; 141 142 prePatch = '' 143 sed -e 's,#!/bin/bash,#!${stdenv.shell},' \ 144 -i src/hip_embed_pch.sh 145 ''; 146 147 preConfigure = '' 148 export HIP_CLANG_PATH=${clang}/bin 149 export DEVICE_LIB_PATH=${rocm-device-libs}/lib 150 ''; 151 152 cmakeFlags = [ 153 "-DHIP_PLATFORM=amd" 154 "-DAMD_OPENCL_PATH=${rocm-opencl-runtime.src}" 155 "-DHIP_COMMON_DIR=${hip}" 156 "-DROCCLR_PATH=${rocclr}" 157 "-DHIP_VERSION_BUILD_ID=0" 158 # Temporarily set variables to work around upstream CMakeLists issue 159 # Can be removed once https://github.com/ROCm-Developer-Tools/hipamd/issues/55 is fixed 160 "-DCMAKE_INSTALL_BINDIR=bin" 161 "-DCMAKE_INSTALL_INCLUDEDIR=include" 162 "-DCMAKE_INSTALL_LIBDIR=lib" 163 ]; 164 165 postInstall = '' 166 patchShebangs $out/bin 167 wrapProgram $out/bin/hipcc --set HIP_PATH $out --set HSA_PATH ${rocm-runtime} --set HIP_CLANG_PATH ${clang}/bin --prefix PATH : ${llvm}/bin --set ROCM_PATH $out 168 wrapProgram $out/bin/hipconfig --set HIP_PATH $out --set HSA_PATH ${rocm-runtime} --set HIP_CLANG_PATH ${clang}/bin 169 ''; 170 171 passthru.updateScript = writeScript "update.sh" '' 172 #!/usr/bin/env nix-shell 173 #!nix-shell -i bash -p curl jq common-updater-scripts nix-prefetch-github 174 version="$(curl -sL "https://api.github.com/repos/ROCm-Developer-Tools/HIP/tags" | jq '.[].name | split("-") | .[1] | select( . != null )' --raw-output | sort -n | tail -1)" 175 current_version="$(grep "version =" pkgs/development/compilers/hip/default.nix | head -n1 | cut -d'"' -f2)" 176 if [[ "$version" != "$current_version" ]]; then 177 tarball_meta="$(nix-prefetch-github ROCm-Developer-Tools HIP --rev "rocm-$version")" 178 tarball_hash="$(nix to-base64 sha256-$(jq -r '.sha256' <<< "$tarball_meta"))" 179 sed -i -z "pkgs/development/compilers/hip/default.nix" \ 180 -e 's,version = "[^'"'"'"]*",version = "'"$version"'",1' \ 181 -e 's,hash = "[^'"'"'"]*",hash = "sha256-'"$tarball_hash"'",1' 182 else 183 echo hip already up-to-date 184 fi 185 186 version="$(curl -sL "https://api.github.com/repos/ROCm-Developer-Tools/hipamd/tags" | jq '.[].name | split("-") | .[1] | select( . != null )' --raw-output | sort -n | tail -1)" 187 current_version="$(grep "version =" pkgs/development/compilers/hip/default.nix | tail -n1 | cut -d'"' -f2)" 188 if [[ "$version" != "$current_version" ]]; then 189 tarball_meta="$(nix-prefetch-github ROCm-Developer-Tools hipamd --rev "rocm-$version")" 190 tarball_hash="$(nix to-base64 sha256-$(jq -r '.sha256' <<< "$tarball_meta"))" 191 sed -i -z "pkgs/development/compilers/hip/default.nix" \ 192 -e 's,version = "[^'"'"'"]*",version = "'"$version"'",2' \ 193 -e 's,hash = "[^'"'"'"]*",hash = "sha256-'"$tarball_hash"'",2' 194 else 195 echo hipamd already up-to-date 196 fi 197 ''; 198 199 meta = with lib; { 200 description = "C++ Heterogeneous-Compute Interface for Portability"; 201 homepage = "https://github.com/ROCm-Developer-Tools/hipamd"; 202 license = licenses.mit; 203 maintainers = with maintainers; [ lovesegfault Flakebi ]; 204 platforms = platforms.linux; 205 }; 206}