diff --git a/projects/hip/bin/hipcc b/projects/hip/bin/hipcc index 81f394102a..35fbb54397 100755 --- a/projects/hip/bin/hipcc +++ b/projects/hip/bin/hipcc @@ -22,8 +22,10 @@ use Cwd 'abs_path'; # Other environment variable controls: # HIP_PATH : Path to HIP directory, default is one dir level above location of this script # CUDA_PATH : Path to CUDA SDK (default /usr/local/cuda). Used on NVIDIA platforms only. -# HCC_HOME : Path to HCC SDK (default /opt/rocm/hcc). Used on AMD platforms only. -# HSA_PATH : Path to HSA dir (default /opt/rocm/hsa). Used on AMD platforms only. +# HCC_HOME : Path to HCC SDK (defaults to ../../hcc relative to this +# script's abs_path). Used on AMD platforms only. +# HSA_PATH : Path to HSA dir (defaults to ../../hsa relative to abs_path +# of this script). Used on AMD platforms only. # HIP_VDI_HOME : Path to HIP/VDI directory. Used on AMD platforms only. if(scalar @ARGV == 0){ @@ -58,7 +60,23 @@ $isWindows = $^O eq 'MSWin32'; $HIPCC_COMPILE_FLAGS_APPEND=$ENV{'HIPCC_COMPILE_FLAGS_APPEND'}; $HIPCC_LINK_FLAGS_APPEND=$ENV{'HIPCC_LINK_FLAGS_APPEND'}; -$HIP_PATH=$ENV{'HIP_PATH'} // dirname (dirname $0); # use parent directory of hipcc +# +# TODO: Fix rpath LDFLAGS settings +# +# Since this hipcc script gets installed at two uneven hierarchical levels, +# linked by symlink, the absolute path of this script should be used to +# derive HIP_PATH, as dirname $0 could be /opt/rocm/bin or /opt/rocm/hip/bin +# depending on how it gets invoked. +# ROCM_PATH which points to is determined based on whether +# we find .info/version in the parent of HIP_PATH or not. If it is found, +# ROCM_PATH is defined relative to HIP_PATH else it is hardcoded to /opt/rocm. +# +$HIP_PATH=$ENV{'HIP_PATH'} // dirname(Cwd::abs_path("$0/../")); # use parent directory of hipcc +if (-e "$HIP_PATH/../.info/version") { + $ROCM_PATH=$ENV{'ROCM_PATH'} // dirname("$HIP_PATH"); # use parent directory of HIP_PATH +} else { + $ROCM_PATH=$ENV{'ROCM_PATH'} // "/opt/rocm"; +} $HIP_VDI_HOME=$ENV{'HIP_VDI_HOME'}; $HIP_LIB_PATH=$ENV{'HIP_LIB_PATH'}; $HIP_CLANG_PATH=$ENV{'HIP_CLANG_PATH'}; @@ -68,7 +86,7 @@ $HIP_CLANG_HCC_COMPAT_MODE=$ENV{'HIP_CLANG_HCC_COMPAT_MODE'}; # HCC compatibilit if (defined $HIP_VDI_HOME) { $HIP_INFO_PATH= "$HIP_VDI_HOME/lib/.hipInfo"; } else { - $HIP_INFO_PATH= "$HIP_PATH/lib/.hipInfo"; + $HIP_INFO_PATH= "$HIP_PATH/lib/.hipInfo"; # use actual file } #--- @@ -112,7 +130,7 @@ if (defined $HIP_RUNTIME and $HIP_RUNTIME eq "VDI" and !defined $HIP_VDI_HOME) { if (-e "$hipcc_dir/../lib/bitcode") { $HIP_VDI_HOME = abs_path($hipcc_dir . "/.."); } else { - $HIP_VDI_HOME = "/opt/rocm/hip"; + $HIP_VDI_HOME = $HIP_PATH; # use HIP_PATH } } @@ -136,10 +154,10 @@ if (defined $HIP_VDI_HOME) { if (defined $HIP_COMPILER and $HIP_COMPILER eq "clang") { $HIP_PLATFORM = "clang"; if (!defined $HIP_CLANG_PATH) { - $HIP_CLANG_PATH = "/opt/rocm/llvm/bin"; + $HIP_CLANG_PATH = "$ROCM_PATH/llvm/bin"; } if (!defined $DEVICE_LIB_PATH) { - $DEVICE_LIB_PATH = "/opt/rocm/lib"; + $DEVICE_LIB_PATH = "$ROCM_PATH/lib"; } } @@ -163,7 +181,6 @@ $target_gfx1012 = 0; $default_amdgpu_target = 1; if ($HIP_PLATFORM eq "clang") { - $ROCM_PATH=$ENV{'ROCM_PATH'} // "/opt/rocm"; $HIPCC="$HIP_CLANG_PATH/clang++"; # If $HIPCC clang++ is not compiled, use clang instead @@ -215,7 +232,7 @@ if ($HIP_PLATFORM eq "clang") { } if ($HIP_RUNTIME eq "HCC" ) { - $HSA_PATH=$ENV{'HSA_PATH'} // "/opt/rocm/hsa"; + $HSA_PATH=$ENV{'HSA_PATH'} // "$ROCM_PATH/hsa"; $HIPCXXFLAGS .= " -isystem $HSA_PATH/include"; } @@ -224,9 +241,9 @@ if ($HIP_PLATFORM eq "clang") { if (! defined $HIP_LIB_PATH) { $HIP_LIB_PATH = "$HIP_PATH/lib"; } - $HSA_PATH=$ENV{'HSA_PATH'} // "/opt/rocm/hsa"; + $HSA_PATH=$ENV{'HSA_PATH'} // "$ROCM_PATH/hsa"; - $HCC_HOME=$ENV{'HCC_HOME'} // $hipConfig{'HCC_HOME'} // "/opt/rocm/hcc"; + $HCC_HOME=$ENV{'HCC_HOME'} // $hipConfig{'HCC_HOME'} // "$ROCM_PATH/hcc"; $HCC_VERSION=`${HCC_HOME}/bin/hcc --version`; $HCC_VERSION=~/.*based on HCC ([^ ]+).*/; @@ -234,8 +251,6 @@ if ($HIP_PLATFORM eq "clang") { $HCC_VERSION_MAJOR=$HCC_VERSION; $HCC_VERSION_MAJOR=~s/\..*//; - $ROCM_PATH=$ENV{'ROCM_PATH'} // "/opt/rocm"; - $HIP_ATP_MARKER=$ENV{'HIP_ATP_MARKER'} // 1; $marker_path = "$ROCM_PATH/profiler/CXLActivityLogger"; diff --git a/projects/hip/bin/hipconfig b/projects/hip/bin/hipconfig index 87da86f3b1..e4bf118c61 100755 --- a/projects/hip/bin/hipconfig +++ b/projects/hip/bin/hipconfig @@ -71,9 +71,17 @@ sub can_run { } } +# Define HIP_PATH based on location of the script. Same as hipcc. +# Derive ROCM_PATH same as hipcc does. Others are relative to ROCM_PATH. +$HIP_PATH=$ENV{'HIP_PATH'} // dirname(Cwd::abs_path("$0/../")); # use parent directory of hipcc +if (-e "$HIP_PATH/../.info/version") { + $ROCM_PATH=$ENV{'ROCM_PATH'} // dirname("$HIP_PATH"); # use parent directory of HIP_PATH +} else { + $ROCM_PATH=$ENV{'ROCM_PATH'} // "/opt/rocm"; +} $CUDA_PATH=$ENV{'CUDA_PATH'} // '/usr/local/cuda'; -$HCC_HOME=$ENV{'HCC_HOME'} // '/opt/rocm/hcc'; -$HSA_PATH=$ENV{'HSA_PATH'} // '/opt/rocm/hsa'; +$HCC_HOME=$ENV{'HCC_HOME'} // "$ROCM_PATH/hcc"; +$HSA_PATH=$ENV{'HSA_PATH'} // "$ROCM_PATH/hsa"; #--- #HIP_PLATFORM controls whether to use NVCC or HCC for compilation: @@ -89,8 +97,6 @@ if (not defined $HIP_PLATFORM) { } } -$HIP_PATH=$ENV{'HIP_PATH'} // Cwd::realpath (dirname (dirname $0)); # use parent directory of this tool - if ($HIP_PLATFORM eq "hcc") { $CPP_CONFIG= " -D__HIP_PLATFORM_HCC__= -I$HIP_PATH/include -I$HCC_HOME/include -I$HSA_PATH/include"; } @@ -181,7 +187,8 @@ if ($p_check) { print "\nCheck system installation:\n"; printf ("%-70s", "check hipconfig in PATH..."); - if (system ("hipconfig > /dev/null 2>&1") != 0) { + # Safer to use which hipconfig instead of invoking hipconfig + if (system ("which hipconfig > /dev/null 2>&1") != 0) { print "FAIL\n"; } else { printf "good\n"; diff --git a/projects/hip/packaging/hip_base.postinst b/projects/hip/packaging/hip_base.postinst index 7dfb0369d7..a8b3eed9fc 100755 --- a/projects/hip/packaging/hip_base.postinst +++ b/projects/hip/packaging/hip_base.postinst @@ -17,9 +17,9 @@ mkdir -p $ROCMBINDIR pushd $ROCMBINDIR for f in $HIPBINFILES do - ln -s -f $f $(basename $f) + ln -r -s -f $f $(basename $f) done - ln -s -f $HIPDIR/bin/.hipVersion .hipVersion + ln -r -s -f $HIPDIR/bin/.hipVersion .hipVersion popd # Soft-link to headers @@ -27,5 +27,5 @@ HIPINCDIR=$HIPDIR/include/hip ROCMINCDIR=$ROCMDIR/include mkdir -p $ROCMINCDIR pushd $ROCMINCDIR - ln -s -f $HIPINCDIR hip + ln -r -s -f $HIPINCDIR hip popd diff --git a/projects/hip/packaging/hip_hcc.postinst b/projects/hip/packaging/hip_hcc.postinst index b7c3e628ec..1cf21dd755 100755 --- a/projects/hip/packaging/hip_hcc.postinst +++ b/projects/hip/packaging/hip_hcc.postinst @@ -13,17 +13,17 @@ HIPDIR=$ROCMDIR/hip HIPLIBDIR=$ROCMDIR/hip/lib # Soft-link to library files -HIPLIBFILES=$(ls -aF $HIPLIBDIR | grep -v [-/$]) +HIPLIBFILES=$(ls -A $HIPLIBDIR | grep -v [-/$]) mkdir -p $ROCMLIBDIR mkdir -p $ROCMLIBDIR/cmake pushd $ROCMLIBDIR for f in $HIPLIBFILES do - ln -s -f $HIPLIBDIR/$f $(basename $f) + ln -s -r -f $HIPLIBDIR/$f $(basename $f) done # Make the hip cmake directory link. pushd cmake -ln -s -f $HIPLIBDIR/cmake/hip hip +ln -s -r -f $HIPLIBDIR/cmake/hip hip popd popd diff --git a/projects/hip/packaging/hip_hcc.prerm b/projects/hip/packaging/hip_hcc.prerm index 8d7d8b93b2..aab670eb4f 100755 --- a/projects/hip/packaging/hip_hcc.prerm +++ b/projects/hip/packaging/hip_hcc.prerm @@ -16,7 +16,7 @@ HIPLIBDIR=$ROCMDIR/hip/lib ([ ! -d $ROCMLIBDIR ] || [ ! -d $HIPLIBDIR ]) && exit 0 # Remove soft-links to libraries -HIPLIBFILES=$(ls -aF $HIPLIBDIR | grep -v [-/$]) +HIPLIBFILES=$(ls -A $HIPLIBDIR | grep -v [-/$]) pushd $ROCMLIBDIR for f in $HIPLIBFILES; do [ -e $f ] || continue