3
0
Fork 0
forked from mirrors/nixpkgs

hip: rewrite and separate

hip-common: init at 5.4.0

hipcc: init at 5.4.1
This commit is contained in:
Madoura 2022-12-14 02:04:14 -06:00
parent fb8a7b62bb
commit f6e28e2058
No known key found for this signature in database
GPG key ID: 3201136B3DB072F9
10 changed files with 595 additions and 283 deletions

View file

@ -0,0 +1,129 @@
diff --git a/bin/hipcc.pl b/bin/hipcc.pl
index da9559b..7aaa540 100755
--- a/bin/hipcc.pl
+++ b/bin/hipcc.pl
@@ -185,7 +185,7 @@ if ($HIP_PLATFORM eq "amd") {
chomp($HIP_CLANG_TARGET);
if (! defined $HIP_CLANG_INCLUDE_PATH) {
- $HIP_CLANG_INCLUDE_PATH = abs_path("$HIP_CLANG_PATH/../lib/clang/$HIP_CLANG_VERSION/include");
+ $HIP_CLANG_INCLUDE_PATH = abs_path("@clang@/resource-root/include");
}
if (! defined $HIP_INCLUDE_PATH) {
$HIP_INCLUDE_PATH = "$HIP_PATH/include";
@@ -206,8 +206,8 @@ if ($HIP_PLATFORM eq "amd") {
print ("HIP_CLANG_TARGET=$HIP_CLANG_TARGET\n");
}
- $HIPCXXFLAGS .= " -isystem \"$HIP_CLANG_INCLUDE_PATH/..\"";
- $HIPCFLAGS .= " -isystem \"$HIP_CLANG_INCLUDE_PATH/..\"";
+ $HIPCXXFLAGS .= " -isystem \"$HIP_CLANG_INCLUDE_PATH\"";
+ $HIPCFLAGS .= " -isystem \"$HIP_CLANG_INCLUDE_PATH\"";
$HIPLDFLAGS .= " -L\"$HIP_LIB_PATH\"";
if ($isWindows) {
$HIPLDFLAGS .= " -lamdhip64";
@@ -625,7 +625,7 @@ if($HIP_PLATFORM eq "amd"){
$targetsStr = $ENV{HCC_AMDGPU_TARGET};
} elsif (not $isWindows) {
# Else try using rocm_agent_enumerator
- $ROCM_AGENT_ENUM = "${ROCM_PATH}/bin/rocm_agent_enumerator";
+ $ROCM_AGENT_ENUM = "@rocminfo@/bin/rocm_agent_enumerator";
$targetsStr = `${ROCM_AGENT_ENUM} -t GPU`;
$targetsStr =~ s/\n/,/g;
}
@@ -724,16 +724,16 @@ if ($HIP_PLATFORM eq "amd") {
if (not $isWindows and not $compileOnly) {
if ($linkType eq 0) {
- $toolArgs = " -L$HIP_LIB_PATH -lamdhip64 -L$ROCM_PATH/lib -lhsa-runtime64 -ldl -lnuma " . ${toolArgs};
+ $toolArgs = " -L$HIP_LIB_PATH -lamdhip64 -L@rocm_runtime@/lib -lhsa-runtime64 -ldl -lnuma " . ${toolArgs};
} else {
$toolArgs = ${toolArgs} . " -Wl,-rpath=$HIP_LIB_PATH:$ROCM_PATH/lib -lamdhip64 ";
}
# To support __fp16 and _Float16, explicitly link with compiler-rt
- $HIP_CLANG_BUILTIN_LIB="$HIP_CLANG_PATH/../lib/clang/$HIP_CLANG_VERSION/lib/$HIP_CLANG_TARGET/libclang_rt.builtins.a";
+ $HIP_CLANG_BUILTIN_LIB="@clang@/resource-root/lib/$HIP_CLANG_TARGET/libclang_rt.builtins.a";
if (-e $HIP_CLANG_BUILTIN_LIB) {
- $toolArgs .= " -L$HIP_CLANG_PATH/../lib/clang/$HIP_CLANG_VERSION/lib/$HIP_CLANG_TARGET -lclang_rt.builtins "
+ $toolArgs .= " -L@clang@/resource-root/lib/$HIP_CLANG_TARGET -lclang_rt.builtins "
} else {
- $toolArgs .= " -L$HIP_CLANG_PATH/../lib/clang/$HIP_CLANG_VERSION/lib/linux -lclang_rt.builtins-x86_64 "
+ $toolArgs .= " -L@clang@/resource-root/lib/linux -lclang_rt.builtins-x86_64 "
}
}
}
diff --git a/bin/hipconfig.pl b/bin/hipconfig.pl
index 5ddb8e9..6a76a2e 100755
--- a/bin/hipconfig.pl
+++ b/bin/hipconfig.pl
@@ -77,7 +77,7 @@ if ($HIP_COMPILER eq "clang") {
$CPP_CONFIG = " -D__HIP_PLATFORM_HCC__= -D__HIP_PLATFORM_AMD__=";
$HIP_PATH_INCLUDE = $HIP_PATH."/include";
- $HIP_CLANG_INCLUDE = $HIP_CLANG_PATH."/../lib/clang/".$HIP_CLANG_VERSION;
+ $HIP_CLANG_INCLUDE = "@clang@/resource-root/include";
if($isWindows) {
$CPP_CONFIG .= " -I\"$HIP_PATH_INCLUDE\" -I\"$HIP_CLANG_INCLUDE\"";
} else {
@@ -168,7 +168,7 @@ if (!$printed or $p_full) {
print ("HIP_CLANG_PATH : $HIP_CLANG_PATH\n");
if ($isWindows) {
system("\"$HIP_CLANG_PATH/clang++\" --version");
- system("\"$HIP_CLANG_PATH/llc\" --version");
+ system("\"@llvm@/bin/llc\" --version");
printf("hip-clang-cxxflags : ");
$win_output = `perl \"$HIP_PATH/bin/hipcc\" --cxxflags`;
printf("$win_output \n");
@@ -177,7 +177,7 @@ if (!$printed or $p_full) {
printf("$win_output \n");
} else {
system("$HIP_CLANG_PATH/clang++ --version");
- system("$HIP_CLANG_PATH/llc --version");
+ system("@llvm@/bin/llc --version");
print ("hip-clang-cxxflags : ");
system("$HIP_PATH/bin/hipcc --cxxflags");
printf("\n");
@@ -219,8 +219,8 @@ if (!$printed or $p_full) {
system ("uname -a");
}
- if (-e "/usr/bin/lsb_release") {
- system ("/usr/bin/lsb_release -a");
+ if (-e "@lsb_release@/bin/lsb_release") {
+ system ("@lsb_release@/bin/lsb_release -a");
}
print "\n" ;
diff --git a/hip-lang-config.cmake.in b/hip-lang-config.cmake.in
index 9250a68..f6e27b7 100644
--- a/hip-lang-config.cmake.in
+++ b/hip-lang-config.cmake.in
@@ -71,8 +71,8 @@ get_filename_component(_IMPORT_PREFIX "${_DIR}/../../../" REALPATH)
#need _IMPORT_PREFIX to be set #FILE_REORG_BACKWARD_COMPATIBILITY
-file(GLOB HIP_CLANG_INCLUDE_SEARCH_PATHS "${_IMPORT_PREFIX}/../llvm/lib/clang/*/include")
-file(GLOB HIP_CLANG_INCLUDE_SEARCH_PATHS_REORG "${_IMPORT_PREFIX}/llvm/lib/clang/*/include")
+file(GLOB HIP_CLANG_INCLUDE_SEARCH_PATHS "@clang@/resource-root/include")
+file(GLOB HIP_CLANG_INCLUDE_SEARCH_PATHS_REORG "@clang@/resource-root/include")
find_path(HIP_CLANG_INCLUDE_PATH __clang_cuda_math.h
HINTS ${HIP_CLANG_INCLUDE_SEARCH_PATHS}
${HIP_CLANG_INCLUDE_SEARCH_PATHS_REORG}
@@ -89,7 +89,7 @@ find_path(HSA_HEADER hsa/hsa.h
PATHS
"${_IMPORT_PREFIX}/../include" #FILE_REORG_BACKWARD_COMPATIBILITY
"${_IMPORT_PREFIX}/include"
- "${ROCM_PATH}/include"
+ "@rocm_runtime@/include"
)
if (NOT HSA_HEADER)
@@ -97,7 +97,7 @@ if (NOT HSA_HEADER)
endif()
get_filename_component(HIP_COMPILER_INSTALL_PATH ${CMAKE_HIP_COMPILER} DIRECTORY)
-file(GLOB HIP_CLANGRT_LIB_SEARCH_PATHS "${HIP_COMPILER_INSTALL_PATH}/../lib/clang/*/lib/*")
+file(GLOB HIP_CLANGRT_LIB_SEARCH_PATHS "@clang@/resource-root/lib/*")
find_library(CLANGRT_BUILTINS
NAMES
clang_rt.builtins

View file

@ -0,0 +1,59 @@
{ lib
, stdenv
, fetchFromGitHub
, rocmUpdateScript
, substituteAll
, llvm
, rocm-runtime
, rocminfo
, lsb-release
}:
stdenv.mkDerivation (finalAttrs: {
pname = "hip-common";
version = "5.4.0";
src = fetchFromGitHub {
owner = "ROCm-Developer-Tools";
repo = "HIP";
rev = "rocm-${finalAttrs.version}";
hash = "sha256-34SJM2n3jZWIS2uwpboWOXVFhaVWGK5ELPKD/cJc1zw=";
};
patches = [
(substituteAll {
src = ./0000-fixup-paths.patch;
inherit llvm rocminfo;
clang = stdenv.cc;
rocm_runtime = rocm-runtime;
lsb_release = lsb-release;
})
];
dontConfigure = true;
dontBuild = true;
installPhase = ''
runHook preInstall
mkdir -p $out
mv * $out
runHook postInstall
'';
passthru.updateScript = rocmUpdateScript {
name = finalAttrs.pname;
owner = finalAttrs.src.owner;
repo = finalAttrs.src.repo;
};
meta = with lib; {
description = "C++ Heterogeneous-Compute Interface for Portability";
homepage = "https://github.com/ROCm-Developer-Tools/HIP";
license = with licenses; [ mit ];
maintainers = with maintainers; [ lovesegfault ] ++ teams.rocm.members;
platforms = platforms.linux;
broken = finalAttrs.version != stdenv.cc.version;
};
})

View file

@ -0,0 +1,62 @@
diff --git a/hip-config.cmake.in b/hip-config.cmake.in
index 89d1224..dc9ba05 100755
--- a/hip-config.cmake.in
+++ b/hip-config.cmake.in
@@ -142,7 +142,7 @@ if(HIP_COMPILER STREQUAL "clang")
file(TO_CMAKE_PATH "${HIP_PATH}/../lc" HIP_CLANG_ROOT)
endif()
else()
- set(HIP_CLANG_ROOT "${ROCM_PATH}/llvm")
+ set(HIP_CLANG_ROOT "@clang@")
endif()
if(NOT HIP_CXX_COMPILER)
set(HIP_CXX_COMPILER ${CMAKE_CXX_COMPILER})
@@ -171,7 +171,7 @@ if(HIP_COMPILER STREQUAL "clang")
get_filename_component(_HIP_CLANG_BIN_PATH "${_HIP_CLANG_REAL_PATH}" DIRECTORY)
get_filename_component(HIP_CLANG_ROOT "${_HIP_CLANG_BIN_PATH}" DIRECTORY)
endif()
- file(GLOB HIP_CLANG_INCLUDE_SEARCH_PATHS ${HIP_CLANG_ROOT}/lib/clang/*/include)
+ file(GLOB HIP_CLANG_INCLUDE_SEARCH_PATHS "@clang@/resource-root/include")
find_path(HIP_CLANG_INCLUDE_PATH stddef.h
HINTS
${HIP_CLANG_INCLUDE_SEARCH_PATHS}
@@ -209,7 +209,7 @@ if(NOT WIN32)
"${_IMPORT_PREFIX}/include"
#FILE_REORG_BACKWARD_COMPATIBILITY ${_IMPORT_PREFIX}/../include is for Backward compatibility
"${_IMPORT_PREFIX}/../include"
- ${ROCM_PATH}/include
+ "@rocm_runtime@/include"
)
if (NOT HSA_HEADER)
@@ -291,7 +291,7 @@ if(HIP_COMPILER STREQUAL "clang")
endif()
endif()
- file(GLOB HIP_CLANGRT_LIB_SEARCH_PATHS "${HIP_CLANG_ROOT}/lib/clang/*/lib/*")
+ file(GLOB HIP_CLANGRT_LIB_SEARCH_PATHS "@clang@/resource-root/lib/*")
find_library(CLANGRT_BUILTINS
NAMES
clang_rt.builtins
diff --git a/src/hip_embed_pch.sh b/src/hip_embed_pch.sh
index 0a1572b..2feb19a 100755
--- a/src/hip_embed_pch.sh
+++ b/src/hip_embed_pch.sh
@@ -149,7 +149,7 @@ EOF
$LLVM_DIR/bin/clang -cc1 -O3 -emit-pch -triple amdgcn-amd-amdhsa -aux-triple x86_64-unknown-linux-gnu -fcuda-is-device -std=c++17 -fgnuc-version=4.2.1 -o $tmp/hip_wave64.pch -x hip-cpp-output - <$tmp/pch_wave64.cui &&
- $LLVM_DIR/bin/llvm-mc -o hip_pch.o $tmp/hip_pch.mcin --filetype=obj &&
+ @llvm@/bin/llvm-mc -o hip_pch.o $tmp/hip_pch.mcin --filetype=obj &&
rm -rf $tmp
}
@@ -195,7 +195,7 @@ EOF
set -x
$LLVM_DIR/bin/clang -O3 --rocm-path=$HIP_INC_DIR/.. -std=c++14 -nogpulib --hip-version=4.4 -isystem $HIP_INC_DIR -isystem $HIP_BUILD_INC_DIR -isystem $HIP_AMD_INC_DIR --cuda-device-only -D__HIPCC_RTC__ -x hip $tmp/hipRTC_header.h -E -o $tmp/hiprtc &&
cat $macroFile >> $tmp/hiprtc &&
- $LLVM_DIR/bin/llvm-mc -o $tmp/hiprtc_header.o $tmp/hipRTC_header.mcin --filetype=obj &&
+ @llvm@/bin/llvm-mc -o $tmp/hiprtc_header.o $tmp/hipRTC_header.mcin --filetype=obj &&
$LLVM_DIR/bin/clang $tmp/hiprtc_header.o -o $rtc_shared_lib_out -shared &&
$LLVM_DIR/bin/clang -O3 --rocm-path=$HIP_INC_DIR/.. -std=c++14 -nogpulib -nogpuinc -emit-llvm -c -o $tmp/tmp.bc --cuda-device-only -D__HIPCC_RTC__ --offload-arch=gfx906 -x hip-cpp-output $tmp/hiprtc &&
rm -rf $tmp

View file

@ -1,114 +1,62 @@
{ stdenv
, binutils-unwrapped
, clang
, cmake
{ lib
, stdenv
, fetchFromGitHub
, fetchpatch
, file
, lib
, libglvnd
, libX11
, libxml2
, llvm
, rocmUpdateScript
, substituteAll
, makeWrapper
, numactl
, perl
, python3
, python3Packages
, hip-common
, hipcc
, rocclr
, roctracer
, cmake
, perl
, llvm
, rocminfo
, rocm-thunk
, rocm-comgr
, rocm-device-libs
, rocm-opencl-runtime
, rocm-runtime
, rocm-thunk
, rocminfo
, substituteAll
, writeScript
, writeText
, rocm-opencl-runtime
, cudatoolkit
, numactl
, libxml2
, libX11
, libglvnd
, doxygen
, graphviz
, fontconfig
, python3Packages
, buildDocs ? true
, buildTests ? false
, useNVIDIA ? false
}:
let
hip = stdenv.mkDerivation (finalAttrs: {
pname = "hip";
version = "5.4.0";
hipPlatform = if useNVIDIA then "nvidia" else "amd";
src = fetchFromGitHub {
owner = "ROCm-Developer-Tools";
repo = "HIP";
rev = "rocm-${finalAttrs.version}";
hash = "sha256-34SJM2n3jZWIS2uwpboWOXVFhaVWGK5ELPKD/cJc1zw=";
};
patches = [
(substituteAll {
src = ./hip-config-paths.patch;
inherit llvm;
rocm_runtime = rocm-runtime;
})
];
# - fix bash paths
# - fix path to rocm_agent_enumerator
# - fix hcc path
# - fix hcc version parsing
# - add linker flags for libhsa-runtime64 and hc_am since libhip_hcc
# refers to them.
prePatch = ''
for f in $(find bin -type f); do
sed -e 's,#!/usr/bin/perl,#!${perl}/bin/perl,' \
-e 's,#!/bin/bash,#!${stdenv.shell},' \
-i "$f"
done
sed 's,#!/usr/bin/python,#!${python3.interpreter},' -i hip_prof_gen.py
sed -e 's,$ROCM_AGENT_ENUM = "''${ROCM_PATH}/bin/rocm_agent_enumerator";,$ROCM_AGENT_ENUM = "${rocminfo}/bin/rocm_agent_enumerator";,' \
-e 's,^\($DEVICE_LIB_PATH=\).*$,\1"${rocm-device-libs}/amdgcn/bitcode";,' \
-e 's,^\($HIP_COMPILER=\).*$,\1"clang";,' \
-e 's,^\($HIP_RUNTIME=\).*$,\1"ROCclr";,' \
-e 's,^\([[:space:]]*$HSA_PATH=\).*$,\1"${rocm-runtime}";,'g \
-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";,' \
-e 's,^\([[:space:]]*$HIPCXXFLAGS .= " -isystem \\"$HIP_CLANG_INCLUDE_PATH/..\\"\)";,\1 -isystem ${rocm-runtime}/include";,' \
-e 's,$HIP_CLANG_PATH/../lib/clang/$HIP_CLANG_VERSION,$HIP_CLANG_PATH/../resource-root,g' \
-e 's,`file,`${file}/bin/file,g' \
-e 's,`readelf,`${binutils-unwrapped}/bin/readelf,' \
-e 's, ar , ${binutils-unwrapped}/bin/ar ,g' \
-i bin/hipcc.pl
sed -e 's,^\($HSA_PATH=\).*$,\1"${rocm-runtime}";,' \
-e 's,^\($HIP_CLANG_PATH=\).*$,\1"${clang}/bin";,' \
-e 's,^\($HIP_PLATFORM=\).*$,\1"amd";,' \
-e 's,$HIP_CLANG_PATH/llc,${llvm}/bin/llc,' \
-e 's, abs_path, Cwd::abs_path,' \
-i bin/hipconfig.pl
sed -e 's, abs_path, Cwd::abs_path,' -i bin/hipvars.pm
'';
buildPhase = "";
installPhase = ''
runHook preInstall
mkdir -p $out
cp -r * $out/
runHook postInstall
'';
meta = with lib; {
description = "C++ Heterogeneous-Compute Interface for Portability";
homepage = "https://github.com/ROCm-Developer-Tools/HIP";
license = licenses.mit;
maintainers = with maintainers; [ lovesegfault ] ++ teams.rocm.members;
platforms = platforms.linux;
};
});
in
stdenv.mkDerivation (finalAttrs: {
pname = "hip";
wrapperArgs = [
"--prefix PATH : $out/bin"
"--prefix LD_LIBRARY_PATH : ${rocm-runtime}"
"--set HIP_PLATFORM ${hipPlatform}"
"--set HIP_PATH $out"
"--set HIP_CLANG_PATH ${stdenv.cc}/bin"
"--set DEVICE_LIB_PATH ${rocm-device-libs}/amdgcn/bitcode"
"--set HSA_PATH ${rocm-runtime}"
"--set ROCM_PATH $out"
] ++ lib.optionals useNVIDIA [
"--set CUDA_PATH ${cudatoolkit}"
];
in stdenv.mkDerivation (finalAttrs: {
pname = "hip-${hipPlatform}";
version = "5.4.0";
outputs = [
"out"
] ++ lib.optionals buildDocs [
"doc"
];
src = fetchFromGitHub {
owner = "ROCm-Developer-Tools";
repo = "hipamd";
@ -116,105 +64,115 @@ stdenv.mkDerivation (finalAttrs: {
hash = "sha256-VL0vZVv099pZPX0J2pXPFvrhkVO/b6X+ZZDaD9B1hYI=";
};
nativeBuildInputs = [ cmake python3 makeWrapper perl ];
buildInputs = [ libxml2 numactl libglvnd libX11 python3Packages.cppheaderparser ];
propagatedBuildInputs = [
clang
llvm
rocm-comgr
rocm-device-libs
rocm-runtime
rocm-thunk
rocminfo
];
patches = [
(substituteAll {
src = ./hipamd-config-paths.patch;
inherit clang llvm hip;
src = ./0000-fixup-paths.patch;
inherit llvm;
clang = stdenv.cc;
rocm_runtime = rocm-runtime;
})
# https://github.com/ROCm-Developer-Tools/hipamd/commit/be33ec55acc104a59d01df5912261d007c7f3ee9
(fetchpatch {
url = "https://github.com/ROCm-Developer-Tools/hipamd/commit/be33ec55acc104a59d01df5912261d007c7f3ee9.patch";
hash = "sha256-eTC4mUIN1FwRce1n38uDOlITFL/vpcOhvnaZTo5R7lo=";
})
];
prePatch = ''
sed -e 's,#!/bin/bash,#!${stdenv.shell},' \
-i src/hip_embed_pch.sh
'';
nativeBuildInputs = [
makeWrapper
cmake
perl
python3Packages.python
python3Packages.cppheaderparser
] ++ lib.optionals buildDocs [
doxygen
graphviz
fontconfig
];
preConfigure = ''
export HIP_CLANG_PATH=${clang}/bin
export DEVICE_LIB_PATH=${rocm-device-libs}/lib
'';
buildInputs = [
numactl
libxml2
libX11
libglvnd
];
propagatedBuildInputs = [
stdenv.cc
llvm
rocminfo
rocm-thunk
rocm-comgr
rocm-device-libs
rocm-runtime
rocm-opencl-runtime
] ++ lib.optionals useNVIDIA [
cudatoolkit
];
cmakeFlags = [
"-DHIP_PLATFORM=amd"
"-DAMD_OPENCL_PATH=${rocm-opencl-runtime.src}"
"-DHIP_COMMON_DIR=${hip}"
"-DROCM_PATH=${rocminfo}"
"-DHIP_PLATFORM=${hipPlatform}"
"-DHIP_COMMON_DIR=${hip-common}"
"-DHIPCC_BIN_DIR=${hipcc}/bin"
"-DHIP_LLVM_ROOT=${stdenv.cc}"
"-DROCCLR_PATH=${rocclr}"
"-DHIP_VERSION_BUILD_ID=0"
"-DAMD_OPENCL_PATH=${rocm-opencl-runtime.src}"
"-DPROF_API_HEADER_PATH=${roctracer.src}/inc/ext"
# Temporarily set variables to work around upstream CMakeLists issue
# Can be removed once https://github.com/ROCm-Developer-Tools/hipamd/issues/55 is fixed
"-DCMAKE_INSTALL_BINDIR=bin"
"-DCMAKE_INSTALL_INCLUDEDIR=include"
"-DCMAKE_INSTALL_LIBDIR=lib"
] ++ lib.optionals buildTests [
"-DHIP_CATCH_TEST=1"
];
postPatch = ''
export HIP_CLANG_PATH=${stdenv.cc}/bin
patchShebangs src
'' + lib.optionalString buildDocs ''
export HOME=$(mktemp -d)
export FONTCONFIG_FILE=${fontconfig.out}/etc/fonts/fonts.conf
'';
doCheck = buildTests;
checkTarget = "build_tests";
preCheck = lib.optionalString buildTests ''
export ROCM_PATH=$PWD
export DEVICE_LIB_PATH=${rocm-device-libs}/amdgcn/bitcode
patchShebangs bin
'';
postInstall = ''
patchShebangs $out/bin
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
wrapProgram $out/bin/hipconfig --set HIP_PATH $out --set HSA_PATH ${rocm-runtime} --set HIP_CLANG_PATH ${clang}/bin
cp -a $out/bin/hipcc $out/bin/hipcc-pl
cp -a $out/bin/hipconfig $out/bin/hipconfig-pl
wrapProgram $out/bin/hipcc --set HIP_USE_PERL_SCRIPTS 0
wrapProgram $out/bin/hipconfig --set HIP_USE_PERL_SCRIPTS 0
wrapProgram $out/bin/hipcc.bin ${lib.concatStringsSep " " wrapperArgs}
wrapProgram $out/bin/hipconfig.bin ${lib.concatStringsSep " " wrapperArgs}
wrapProgram $out/bin/hipcc-pl --set HIP_USE_PERL_SCRIPTS 1
wrapProgram $out/bin/hipconfig-pl --set HIP_USE_PERL_SCRIPTS 1
wrapProgram $out/bin/hipcc.pl ${lib.concatStringsSep " " wrapperArgs}
wrapProgram $out/bin/hipconfig.pl ${lib.concatStringsSep " " wrapperArgs}
'';
# TODO: Separate HIP and hipamd into separate derivations
passthru.updateScript = writeScript "update.sh" ''
#!/usr/bin/env nix-shell
#!nix-shell -i bash -p curl jq common-updater-scripts nix-prefetch-github
version="$(curl ''${GITHUB_TOKEN:+-u ":$GITHUB_TOKEN"} \
-sL "https://api.github.com/repos/ROCm-Developer-Tools/HIP/releases?per_page=1" | jq '.[0].tag_name | split("-") | .[1]' --raw-output)"
IFS='.' read -a version_arr <<< "$version"
if [ "''${#version_arr[*]}" == 2 ]; then
version="''${version}.0"
fi
current_version="$(grep "version =" pkgs/development/compilers/hip/default.nix | head -n1 | cut -d'"' -f2)"
if [[ "$version" != "$current_version" ]]; then
tarball_meta="$(nix-prefetch-github ROCm-Developer-Tools HIP --rev "rocm-$version")"
tarball_hash="$(nix to-base64 sha256-$(jq -r '.sha256' <<< "$tarball_meta"))"
sed -i -z "pkgs/development/compilers/hip/default.nix" \
-e 's,version = "[^'"'"'"]*",version = "'"$version"'",1' \
-e 's,hash = "[^'"'"'"]*",hash = "sha256-'"$tarball_hash"'",1'
else
echo hip already up-to-date
fi
version="$(curl ''${GITHUB_TOKEN:+-u ":$GITHUB_TOKEN"} \
-sL "https://api.github.com/repos/ROCm-Developer-Tools/hipamd/releases?per_page=1" | jq '.[0].tag_name | split("-") | .[1]' --raw-output)"
IFS='.' read -a version_arr <<< "$version"
if [ "''${#version_arr[*]}" == 2 ]; then
version="''${version}.0"
fi
current_version="$(grep "version =" pkgs/development/compilers/hip/default.nix | tail -n1 | cut -d'"' -f2)"
if [[ "$version" != "$current_version" ]]; then
tarball_meta="$(nix-prefetch-github ROCm-Developer-Tools hipamd --rev "rocm-$version")"
tarball_hash="$(nix to-base64 sha256-$(jq -r '.sha256' <<< "$tarball_meta"))"
sed -i -z "pkgs/development/compilers/hip/default.nix" \
-e 's,version = "[^'"'"'"]*",version = "'"$version"'",2' \
-e 's,hash = "[^'"'"'"]*",hash = "sha256-'"$tarball_hash"'",2'
else
echo hipamd already up-to-date
fi
'';
passthru.updateScript = rocmUpdateScript {
name = finalAttrs.pname;
owner = finalAttrs.src.owner;
repo = finalAttrs.src.repo;
};
meta = with lib; {
description = "C++ Heterogeneous-Compute Interface for Portability";
description = "C++ Heterogeneous-Compute Interface for Portability specifically for AMD platform";
homepage = "https://github.com/ROCm-Developer-Tools/hipamd";
license = licenses.mit;
license = with licenses; [ mit ];
maintainers = with maintainers; [ lovesegfault ] ++ teams.rocm.members;
platforms = platforms.linux;
# Tests require GPU, also include issues
broken = finalAttrs.version != hip-common.version || finalAttrs.version != hipcc.version || buildTests;
};
})

View file

@ -1,35 +0,0 @@
diff --git a/hip-lang-config.cmake.in b/hip-lang-config.cmake.in
index 1a72643a..7f35031f 100644
--- a/hip-lang-config.cmake.in
+++ b/hip-lang-config.cmake.in
@@ -71,8 +71,8 @@ get_filename_component(_IMPORT_PREFIX "${_DIR}/../../../" REALPATH)
#need _IMPORT_PREFIX to be set #FILE_REORG_BACKWARD_COMPATIBILITY
-file(GLOB HIP_CLANG_INCLUDE_SEARCH_PATHS "${_IMPORT_PREFIX}/../llvm/lib/clang/*/include")
-file(GLOB HIP_CLANG_INCLUDE_SEARCH_PATHS_REORG "${_IMPORT_PREFIX}/llvm/lib/clang/*/include")
+file(GLOB HIP_CLANG_INCLUDE_SEARCH_PATHS "@llvm@/lib/clang/*/include")
+file(GLOB HIP_CLANG_INCLUDE_SEARCH_PATHS_REORG "@llvm@/lib/clang/*/include")
find_path(HIP_CLANG_INCLUDE_PATH __clang_cuda_math.h
HINTS ${HIP_CLANG_INCLUDE_SEARCH_PATHS}
${HIP_CLANG_INCLUDE_SEARCH_PATHS_REORG}
@@ -87,9 +87,7 @@ endif()
#if HSA is not under ROCm then provide CMAKE_PREFIX_PATH=<HSA_PATH>
find_path(HSA_HEADER hsa/hsa.h
PATHS
- "${_IMPORT_PREFIX}/../include" #FILE_REORG_BACKWARD_COMPATIBILITY
- "${_IMPORT_PREFIX}/include"
- "${ROCM_PATH}/include"
+ "@rocm_runtime@/include"
)
if (NOT HSA_HEADER)
@@ -97,7 +94,7 @@ if (HSA_HEADER-NOTFOUND)
endif()
get_filename_component(HIP_COMPILER_INSTALL_PATH ${CMAKE_HIP_COMPILER} DIRECTORY)
-file(GLOB HIP_CLANGRT_LIB_SEARCH_PATHS "${HIP_COMPILER_INSTALL_PATH}/../lib/clang/*/lib/*")
+file(GLOB HIP_CLANGRT_LIB_SEARCH_PATHS "@llvm@/lib/clang/*/lib/*")
find_library(CLANGRT_BUILTINS
NAMES
clang_rt.builtins

View file

@ -1,73 +0,0 @@
diff --git a/hip-config.cmake.in b/hip-config.cmake.in
index 89d1224e..120b68c6 100755
--- a/hip-config.cmake.in
+++ b/hip-config.cmake.in
@@ -142,7 +142,7 @@ if(HIP_COMPILER STREQUAL "clang")
file(TO_CMAKE_PATH "${HIP_PATH}/../lc" HIP_CLANG_ROOT)
endif()
else()
- set(HIP_CLANG_ROOT "${ROCM_PATH}/llvm")
+ set(HIP_CLANG_ROOT "@clang@")
endif()
if(NOT HIP_CXX_COMPILER)
set(HIP_CXX_COMPILER ${CMAKE_CXX_COMPILER})
@@ -206,10 +206,7 @@ if(NOT WIN32)
#if HSA is not under ROCm then provide CMAKE_PREFIX_PATH=<HSA_PATH>
find_path(HSA_HEADER hsa/hsa.h
PATHS
- "${_IMPORT_PREFIX}/include"
- #FILE_REORG_BACKWARD_COMPATIBILITY ${_IMPORT_PREFIX}/../include is for Backward compatibility
- "${_IMPORT_PREFIX}/../include"
- ${ROCM_PATH}/include
+ "@rocm_runtime@/include"
)
if (NOT HSA_HEADER)
@@ -224,8 +221,8 @@ set_target_properties(hip::host PROPERTIES
if(HIP_RUNTIME MATCHES "rocclr")
set_target_properties(hip::amdhip64 PROPERTIES
- INTERFACE_INCLUDE_DIRECTORIES "${_IMPORT_PREFIX}/include;${HSA_HEADER}"
- INTERFACE_SYSTEM_INCLUDE_DIRECTORIES "${_IMPORT_PREFIX}/include;${HSA_HEADER}"
+ INTERFACE_INCLUDE_DIRECTORIES "@hip@/include;${HSA_HEADER}"
+ INTERFACE_SYSTEM_INCLUDE_DIRECTORIES "@hip@/include;${HSA_HEADER}"
)
get_target_property(amdhip64_type hip::amdhip64 TYPE)
@@ -233,8 +230,8 @@ if(HIP_RUNTIME MATCHES "rocclr")
if(NOT WIN32)
set_target_properties(hip::device PROPERTIES
- INTERFACE_INCLUDE_DIRECTORIES "${_IMPORT_PREFIX}/include"
- INTERFACE_SYSTEM_INCLUDE_DIRECTORIES "${_IMPORT_PREFIX}/include"
+ INTERFACE_INCLUDE_DIRECTORIES "@hip@/include"
+ INTERFACE_SYSTEM_INCLUDE_DIRECTORIES "@hip@/include"
)
endif()
endif()
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 83866d83..4125d3aa 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -178,7 +178,7 @@ if(__HIP_ENABLE_PCH)
${ROCM_PATH}/llvm)
# find_package(LLVM) returns the lib/cmake/llvm location. We require the root.
if(NOT DEFINED HIP_LLVM_ROOT)
- set(HIP_LLVM_ROOT "${LLVM_DIR}/../../..")
+ set(HIP_LLVM_ROOT "@clang@")
endif()
execute_process(COMMAND sh -c "${CMAKE_CURRENT_SOURCE_DIR}/hip_embed_pch.sh ${HIP_COMMON_INCLUDE_DIR} ${PROJECT_BINARY_DIR}/include ${PROJECT_SOURCE_DIR}/include ${HIP_LLVM_ROOT}" COMMAND_ECHO STDERR RESULT_VARIABLE EMBED_PCH_RC)
diff --git a/src/hip_embed_pch.sh b/src/hip_embed_pch.sh
index 0a1572b2..aa855d63 100755
--- a/src/hip_embed_pch.sh
+++ b/src/hip_embed_pch.sh
@@ -149,7 +149,7 @@ EOF
$LLVM_DIR/bin/clang -cc1 -O3 -emit-pch -triple amdgcn-amd-amdhsa -aux-triple x86_64-unknown-linux-gnu -fcuda-is-device -std=c++17 -fgnuc-version=4.2.1 -o $tmp/hip_wave64.pch -x hip-cpp-output - <$tmp/pch_wave64.cui &&
- $LLVM_DIR/bin/llvm-mc -o hip_pch.o $tmp/hip_pch.mcin --filetype=obj &&
+ @llvm@/bin/llvm-mc -o hip_pch.o $tmp/hip_pch.mcin --filetype=obj &&
rm -rf $tmp
}

View file

@ -0,0 +1,130 @@
diff --git a/CMakeLists.txt b/CMakeLists.txt
index c21f247..5bd3e45 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -17,6 +17,6 @@ if (NOT WIN32) # C++17 does not require the std lib linking
target_link_libraries(hipconfig.bin ${LINK_LIBS} ) # for hipconfig.bin
endif()
-set(HIP_VERSION_MAJOR 4 PARENT_SCOPE)
-set(HIP_VERSION_MINOR 4 PARENT_SCOPE)
-set(HIP_VERSION_PATCH 4 PARENT_SCOPE)
+set(HIP_VERSION_MAJOR @version_major@)
+set(HIP_VERSION_MINOR @version_minor@)
+set(HIP_VERSION_PATCH @version_patch@)
diff --git a/src/hipBin_amd.h b/src/hipBin_amd.h
index f94e4a5..f0b1b83 100644
--- a/src/hipBin_amd.h
+++ b/src/hipBin_amd.h
@@ -207,7 +207,7 @@ void HipBinAmd::initializeHipCXXFlags() {
hipClangIncludePath = getCompilerIncludePath();
hipCXXFlags += " -isystem \"" + hipClangIncludePath;
fs::path hipCXXFlagsTempFs = hipCXXFlags;
- hipCXXFlagsTempFs /= "..\"";
+ hipCXXFlagsTempFs /= "\"";
hipCXXFlags = hipCXXFlagsTempFs.string();
const EnvVariables& var = getEnvVariables();
// Allow __fp16 as function parameter and return type.
@@ -266,7 +266,7 @@ void HipBinAmd::printCompilerInfo() const {
string cmd = hipClangPath + "/clang++ --version";
system(cmd.c_str()); // hipclang version
cout << "llc-version :" << endl;
- cmd = hipClangPath + "/llc --version";
+ cmd = "@llvm@/bin/llc --version";
system(cmd.c_str()); // llc version
cout << "hip-clang-cxxflags :" << endl;
cmd = hipPath + "/bin/hipcc --cxxflags";
@@ -278,7 +278,7 @@ void HipBinAmd::printCompilerInfo() const {
} else {
string cmd = hipClangPath + "/clang++ --version";
system(cmd.c_str()); // hipclang version
- cmd = hipClangPath + "/llc --version";
+ cmd = "@llvm@/bin/llc --version";
system(cmd.c_str()); // llc version
cout << "hip-clang-cxxflags :" << endl;
cmd = hipPath + "/bin/hipcc --cxxflags";
@@ -331,10 +331,7 @@ string HipBinAmd::getCppConfig() {
hipPathInclude /= "include";
const string& compilerPath = getCompilerPath();
- hipClangInclude = compilerPath;
- hipClangInclude = hipClangInclude.parent_path();
- hipClangInclude /= "lib/clang/";
- hipClangInclude /= compilerVersion;
+ hipClangInclude = "@clang@/resource-root/include";
string hipClangPath = hipClangInclude.string();
const OsType& osInfo = getOSInfo();
@@ -442,17 +439,7 @@ string HipBinAmd::getHipCC() const {
string HipBinAmd::getCompilerIncludePath() {
- string hipClangVersion, includePath, compilerIncludePath;
- const string& hipClangPath = getCompilerPath();
- hipClangVersion = getCompilerVersion();
- fs::path includePathfs = hipClangPath;
- includePathfs = includePathfs.parent_path();
- includePathfs /= "lib/clang/";
- includePathfs /= hipClangVersion;
- includePathfs /= "include";
- includePathfs = fs::absolute(includePathfs).string();
- compilerIncludePath = includePathfs.string();
- return compilerIncludePath;
+ return "@clang@/resource-root/include";
}
@@ -506,8 +493,8 @@ void HipBinAmd::printFull() {
cout << endl << "== Envirnoment Variables" << endl;
printEnvironmentVariables();
getSystemInfo();
- if (fs::exists("/usr/bin/lsb_release"))
- system("/usr/bin/lsb_release -a");
+ if (fs::exists("@lsb_release@/bin/lsb_release"))
+ system("@lsb_release@/bin/lsb_release -a");
cout << endl;
}
@@ -993,7 +980,7 @@ void HipBinAmd::executeHipCCCmd(vector<string> argv) {
} else if (os != windows) {
// Else try using rocm_agent_enumerator
string ROCM_AGENT_ENUM;
- ROCM_AGENT_ENUM = roccmPath + "/bin/rocm_agent_enumerator";
+ ROCM_AGENT_ENUM = "@rocminfo@/bin/rocm_agent_enumerator";
targetsStr = ROCM_AGENT_ENUM +" -t GPU";
SystemCmdOut sysOut = hipBinUtilPtr_->exec(targetsStr.c_str());
regex toReplace("\n+");
@@ -1097,7 +1084,7 @@ void HipBinAmd::executeHipCCCmd(vector<string> argv) {
string hipClangVersion, toolArgTemp;
if (linkType == 0) {
toolArgTemp = " -L"+ hipLibPath + "-lamdhip64 -L" +
- roccmPath+ "/lib -lhsa-runtime64 -ldl -lnuma " + toolArgs;
+ "@rocm_runtime@/lib -lhsa-runtime64 -ldl -lnuma " + toolArgs;
toolArgs = toolArgTemp;
} else {
toolArgTemp = toolArgs + " -Wl,--enable-new-dtags -Wl,-rpath=" + hipLibPath + ":"
@@ -1107,8 +1094,7 @@ void HipBinAmd::executeHipCCCmd(vector<string> argv) {
hipClangVersion = getCompilerVersion();
// To support __fp16 and _Float16, explicitly link with compiler-rt
- toolArgs += " -L" + hipClangPath + "/../lib/clang/" +
- hipClangVersion + "/lib/linux -lclang_rt.builtins-x86_64 ";
+ toolArgs += " -L@clang@/resource-root/lib/linux -lclang_rt.builtins-x86_64 ";
}
if (!var.hipccCompileFlagsAppendEnv_.empty()) {
HIPCXXFLAGS += " " + var.hipccCompileFlagsAppendEnv_ + " ";
diff --git a/src/hipBin_nvidia.h b/src/hipBin_nvidia.h
index 6feb315..b61739d 100644
--- a/src/hipBin_nvidia.h
+++ b/src/hipBin_nvidia.h
@@ -157,8 +157,8 @@ void HipBinNvidia::printFull() {
cout << endl << "== Envirnoment Variables" << endl;
printEnvironmentVariables();
getSystemInfo();
- if (fs::exists("/usr/bin/lsb_release"))
- system("/usr/bin/lsb_release -a");
+ if (fs::exists("@lsb_release@/bin/lsb_release"))
+ system("@lsb_release@/bin/lsb_release -a");
}
// returns hip include

View file

@ -0,0 +1,62 @@
{ lib
, stdenv
, fetchFromGitHub
, rocmUpdateScript
, substituteAll
, cmake
, llvm
, rocm-runtime
, rocminfo
, lsb-release
}:
stdenv.mkDerivation (finalAttrs: {
pname = "hipcc";
version = "5.4.1";
src = fetchFromGitHub {
owner = "ROCm-Developer-Tools";
repo = "HIPCC";
rev = "rocm-${finalAttrs.version}";
hash = "sha256-PEwue4O43MiMkF8UmTeHsmlikBG2V3/nFQLKmtHrRWQ=";
};
patches = [
(substituteAll {
src = ./0000-fixup-paths.patch;
inherit llvm rocminfo;
version_major = lib.versions.major finalAttrs.version;
version_minor = lib.versions.minor finalAttrs.version;
version_patch = lib.versions.patch finalAttrs.version;
clang = stdenv.cc;
rocm_runtime = rocm-runtime;
lsb_release = lsb-release;
})
];
nativeBuildInputs = [ cmake ];
installPhase = ''
runHook preInstall
mkdir -p $out/bin
mv *.bin $out/bin
runHook postInstall
'';
passthru.updateScript = rocmUpdateScript {
name = finalAttrs.pname;
owner = finalAttrs.src.owner;
repo = finalAttrs.src.repo;
};
meta = with lib; {
description = "Compiler driver utility that calls clang or nvcc";
homepage = "https://github.com/ROCm-Developer-Tools/HIPCC";
license = with licenses; [ mit ];
maintainers = with maintainers; [ lovesegfault ] ++ teams.rocm.members;
platforms = platforms.linux;
broken = finalAttrs.version != stdenv.cc.version;
};
})

View file

@ -12,7 +12,7 @@
, swig
, lua5_3
, gtest
, hipcc
, hip
, rocm-comgr
, vulkan-loader
, vulkan-headers
@ -471,7 +471,7 @@ in rec {
buildMan = false; # No man pages to build
targetName = "mlir";
targetDir = targetName;
extraNativeBuildInputs = [ hipcc ];
extraNativeBuildInputs = [ hip ];
extraBuildInputs = [
rocm-comgr

View file

@ -15147,8 +15147,28 @@ with pkgs;
stdenv = rocmClangStdenv;
};
hip-common = callPackage ../development/compilers/hip-common {
inherit (llvmPackages_rocm) llvm;
stdenv = rocmClangStdenv;
};
hipcc = callPackage ../development/compilers/hipcc {
inherit (llvmPackages_rocm) llvm;
stdenv = rocmClangStdenv;
};
hip = callPackage ../development/compilers/hip {
inherit (llvmPackages_rocm) clang llvm;
inherit (llvmPackages_rocm) llvm;
inherit (cudaPackages) cudatoolkit;
stdenv = rocmClangStdenv;
};
hip-amd = hip.override {
useNVIDIA = false;
};
hip-nvidia = hip.override {
useNVIDIA = true;
};
hipcub = callPackage ../development/libraries/hipcub {