From d17268afb3f72031fc3cd267f5264ac656326d3e Mon Sep 17 00:00:00 2001 From: Armin Wehrfritz Date: Tue, 23 Aug 2022 10:01:44 +0300 Subject: [PATCH 1/5] Detect correct lib directory (i.e. 'lib64' or 'lib') and set DEVICE_LIB_PATH correctly for system installation (e.g. in /usr/lib64/amdgcn/bitcode/) --- bin/hipcc.pl | 14 ++++++++------ bin/hipvars.pm | 16 ++++++++++++++-- 2 files changed, 22 insertions(+), 8 deletions(-) diff --git a/bin/hipcc.pl b/bin/hipcc.pl index fa833c023d..a96da615cb 100755 --- a/bin/hipcc.pl +++ b/bin/hipcc.pl @@ -105,6 +105,7 @@ BEGIN $HIP_VERSION = $hipvars::HIP_VERSION; $HSA_PATH = $hipvars::HSA_PATH; $HIP_ROCCLR_HOME = $hipvars::HIP_ROCCLR_HOME; +$LIB = $hipvars::LIB; if ($HIP_PLATFORM eq "amd") { # If using ROCclr runtime, need to find HIP_ROCCLR_HOME @@ -113,14 +114,15 @@ BEGIN } $HIP_INCLUDE_PATH = "$HIP_ROCCLR_HOME/include"; if (!defined $HIP_LIB_PATH) { - $HIP_LIB_PATH = "$HIP_ROCCLR_HOME/lib"; + $HIP_LIB_PATH = "$HIP_ROCCLR_HOME/$LIB"; } if (!defined $DEVICE_LIB_PATH) { if (-e "$ROCM_PATH/amdgcn/bitcode") { $DEVICE_LIB_PATH = "$ROCM_PATH/amdgcn/bitcode"; - } - else { + } elsif (-e "$ROCM_PATH/$LIB/amdgcn/bitcode") { + $DEVICE_LIB_PATH = "$ROCM_PATH/$LIB/amdgcn/bitcode"; + } else { # This path is to support an older build of the device library # TODO: To be removed in the future. $DEVICE_LIB_PATH = "$ROCM_PATH/lib"; @@ -172,7 +174,7 @@ BEGIN $HIP_INCLUDE_PATH = "$HIP_PATH/include"; } if (! defined $HIP_LIB_PATH) { - $HIP_LIB_PATH = "$HIP_PATH/lib"; + $HIP_LIB_PATH = "$HIP_PATH/$LIB"; } if ($verbose & 0x2) { print ("ROCM_PATH=$ROCM_PATH\n"); @@ -706,9 +708,9 @@ BEGIN 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_PATH/$LIB -lhsa-runtime64 -ldl -lnuma " . ${toolArgs}; } else { - $toolArgs = ${toolArgs} . " -Wl,--enable-new-dtags -Wl,-rpath=$HIP_LIB_PATH:$ROCM_PATH/lib -lamdhip64 "; + $toolArgs = ${toolArgs} . " -Wl,--enable-new-dtags -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"; diff --git a/bin/hipvars.pm b/bin/hipvars.pm index 19656a11f3..630cd970db 100644 --- a/bin/hipvars.pm +++ b/bin/hipvars.pm @@ -94,9 +94,21 @@ if ($isWindows) { $HIP_ROCCLR_HOME=$ENV{'HIP_ROCCLR_HOME'}; if (defined $HIP_ROCCLR_HOME) { - $HIP_INFO_PATH= "$HIP_ROCCLR_HOME/lib/.hipInfo"; + # Only used for Windows builds + $LIB = "lib"; + $HIP_INFO_PATH = "$HIP_ROCCLR_HOME/lib/.hipInfo"; } else { - $HIP_INFO_PATH= "$HIP_PATH/lib/.hipInfo"; # use actual file + # Detect lib directory (i.e. 'lib64' or 'lib') + if (-e "$HIP_PATH/lib64/.hipInfo") { + $LIB = "lib64"; + } else { + $LIB = "lib"; + } + $HIP_INFO_PATH = "$HIP_PATH/$LIB/.hipInfo"; +} +if (! -f $HIP_INFO_PATH) { + printf ("error: HIP_INFO_PATH does not exist ('$HIP_INFO_PATH')\n"); + exit (-1); } #--- #HIP_PLATFORM controls whether to use nvidia or amd platform: From 6148151ec3c41e8b42adee353ab69242a268b7e6 Mon Sep 17 00:00:00 2001 From: Armin Wehrfritz Date: Tue, 23 Aug 2022 10:05:47 +0300 Subject: [PATCH 2/5] Do not overwide HSA_PATH or CUDA_PATH set in hipvars.pm --- bin/hipcc.pl | 2 -- 1 file changed, 2 deletions(-) diff --git a/bin/hipcc.pl b/bin/hipcc.pl index a96da615cb..1f6f076992 100755 --- a/bin/hipcc.pl +++ b/bin/hipcc.pl @@ -201,13 +201,11 @@ BEGIN } if (not $isWindows) { - $HSA_PATH=$ENV{'HSA_PATH'} // "$ROCM_PATH/hsa"; $HIPCXXFLAGS .= " -isystem $HSA_PATH/include"; $HIPCFLAGS .= " -isystem $HSA_PATH/include"; } } elsif ($HIP_PLATFORM eq "nvidia") { - $CUDA_PATH=$ENV{'CUDA_PATH'} // '/usr/local/cuda'; $HIP_INCLUDE_PATH = "$HIP_PATH/include"; if ($verbose & 0x2) { print ("CUDA_PATH=$CUDA_PATH\n"); From 453cd9105bf52841f8e05680f0cc66f1ea8057fc Mon Sep 17 00:00:00 2001 From: Armin Wehrfritz Date: Sat, 10 Sep 2022 16:36:36 +0300 Subject: [PATCH 3/5] Change the lib directory detection to looking for the HSA runtime library instead of .hipInfo --- bin/hipvars.pm | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/bin/hipvars.pm b/bin/hipvars.pm index 630cd970db..c47e6b888c 100644 --- a/bin/hipvars.pm +++ b/bin/hipvars.pm @@ -93,22 +93,19 @@ if ($isWindows) { # HIP_ROCCLR_HOME is used by Windows builds $HIP_ROCCLR_HOME=$ENV{'HIP_ROCCLR_HOME'}; -if (defined $HIP_ROCCLR_HOME) { - # Only used for Windows builds +if ($isWindows) { $LIB = "lib"; - $HIP_INFO_PATH = "$HIP_ROCCLR_HOME/lib/.hipInfo"; } else { - # Detect lib directory (i.e. 'lib64' or 'lib') - if (-e "$HIP_PATH/lib64/.hipInfo") { - $LIB = "lib64"; - } else { - $LIB = "lib"; - } - $HIP_INFO_PATH = "$HIP_PATH/$LIB/.hipInfo"; + # Look for the HSA runtime library to determine the lib directory name + $LIB = `find $HIP_PATH/lib $HIP_PATH/lib64 -name libhsa-runtime64* | grep -m1 -o '.*/lib.*/'`; + chomp($LIB); # Remove trailing newline characters + $LIB = basename($LIB); # Get the lib directory name } -if (! -f $HIP_INFO_PATH) { - printf ("error: HIP_INFO_PATH does not exist ('$HIP_INFO_PATH')\n"); - exit (-1); + +if (defined $HIP_ROCCLR_HOME) { + $HIP_INFO_PATH= "$HIP_ROCCLR_HOME/$LIB/.hipInfo"; +} else { + $HIP_INFO_PATH= "$HIP_PATH/$LIB/.hipInfo"; # use actual file } #--- #HIP_PLATFORM controls whether to use nvidia or amd platform: From 6f074262cca719e112c451cf8ff58431fa4baf4c Mon Sep 17 00:00:00 2001 From: Armin Wehrfritz Date: Sun, 11 Sep 2022 12:45:02 +0300 Subject: [PATCH 4/5] Change the lib directory detection to looking for the AMD HIP library and account for the Debian multi-arch filesystem layout --- bin/hipvars.pm | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/bin/hipvars.pm b/bin/hipvars.pm index c47e6b888c..e8a41bbfca 100644 --- a/bin/hipvars.pm +++ b/bin/hipvars.pm @@ -96,10 +96,18 @@ $HIP_ROCCLR_HOME=$ENV{'HIP_ROCCLR_HOME'}; if ($isWindows) { $LIB = "lib"; } else { - # Look for the HSA runtime library to determine the lib directory name - $LIB = `find $HIP_PATH/lib $HIP_PATH/lib64 -name libhsa-runtime64* | grep -m1 -o '.*/lib.*/'`; - chomp($LIB); # Remove trailing newline characters - $LIB = basename($LIB); # Get the lib directory name + # Look for the AMD HIP library to determine the lib directory name + if (my @libs = glob("\E$HIP_PATH/lib*/*libamdhip64*.so*")) { + # Multi-lib layout (Fedora and others: /usr/lib64) + $LIB = basename(dirname($libs[0])); + } elsif (my @libs = glob("\E$HIP_PATH/lib/*/*libamdhip64*.so*")) { + # Multi-arch layout (Debian: /usr/lib/x86_64-linux-gnu) + $LIB = "lib/" . basename(dirname($libs[0])); + } else { + # Set to 'lib' for backwards compatibility with cases that are not + # caught in the above checks + $LIB = "lib"; + } } if (defined $HIP_ROCCLR_HOME) { From 03fa43880f3bd9683e1ee7265ec4b0ee79b1b883 Mon Sep 17 00:00:00 2001 From: Armin Wehrfritz Date: Mon, 12 Sep 2022 00:30:58 +0300 Subject: [PATCH 5/5] Minor cleanups and fixes --- bin/hipcc.pl | 8 ++++---- bin/hipvars.pm | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/bin/hipcc.pl b/bin/hipcc.pl index 1f6f076992..60a7734734 100755 --- a/bin/hipcc.pl +++ b/bin/hipcc.pl @@ -168,7 +168,7 @@ BEGIN $HIP_CLANG_TARGET = 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("$HIP_CLANG_PATH/../$LIB/clang/$HIP_CLANG_VERSION/include"); } if (! defined $HIP_INCLUDE_PATH) { $HIP_INCLUDE_PATH = "$HIP_PATH/include"; @@ -711,11 +711,11 @@ BEGIN $toolArgs = ${toolArgs} . " -Wl,--enable-new-dtags -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="$HIP_CLANG_PATH/../$LIB/clang/$HIP_CLANG_VERSION/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$HIP_CLANG_PATH/../$LIB/clang/$HIP_CLANG_VERSION/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$HIP_CLANG_PATH/../$LIB/clang/$HIP_CLANG_VERSION/lib/linux -lclang_rt.builtins-x86_64 " } } } diff --git a/bin/hipvars.pm b/bin/hipvars.pm index e8a41bbfca..b750af3c29 100644 --- a/bin/hipvars.pm +++ b/bin/hipvars.pm @@ -97,10 +97,10 @@ if ($isWindows) { $LIB = "lib"; } else { # Look for the AMD HIP library to determine the lib directory name - if (my @libs = glob("\E$HIP_PATH/lib*/*libamdhip64*.so*")) { + if (my @libs = glob("$HIP_PATH/lib*/libamdhip64*.so*")) { # Multi-lib layout (Fedora and others: /usr/lib64) $LIB = basename(dirname($libs[0])); - } elsif (my @libs = glob("\E$HIP_PATH/lib/*/*libamdhip64*.so*")) { + } elsif (@libs = glob("$HIP_PATH/lib/*/libamdhip64*.so*")) { # Multi-arch layout (Debian: /usr/lib/x86_64-linux-gnu) $LIB = "lib/" . basename(dirname($libs[0])); } else {