From a11397e769f71227cfc44353842ea90707610236 Mon Sep 17 00:00:00 2001 From: Jeremy Newton Date: Wed, 31 May 2023 10:37:08 -0400 Subject: [PATCH 1/2] Improve HIP_CLANG_INCLUDE detection Using: $HIP_CLANG_PATH."/../lib/clang/".$HIP_CLANG_VERSION; Isn't always correct, as the library and resource directory can be customized at build time in LLVM. E.g. Fedora, RHEL, and SLE uses "lib64/clang" instead of "lib/clang". So it's better to ask clang where its resource directory is instead. Change-Id: I026b245735af5e5310b9ee6188f3f080fac6eb51 Signed-off-by: Jeremy Newton --- bin/hipconfig.pl | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/bin/hipconfig.pl b/bin/hipconfig.pl index dd03ad6..5abdfbf 100755 --- a/bin/hipconfig.pl +++ b/bin/hipconfig.pl @@ -64,19 +64,16 @@ BEGIN ); if ($HIP_COMPILER eq "clang") { - $HIP_CLANG_VERSION = ""; + $HIP_CLANG_INCLUDE = ""; if($isWindows) { - $HIP_CLANG_VERSION = `\"$HIP_CLANG_PATH/clang++\" --version`; + $HIP_CLANG_INCLUDE = `\"$HIP_CLANG_PATH/clang++\" --print-resource-dir`; } else { - $HIP_CLANG_VERSION = `$HIP_CLANG_PATH/clang++ --version`; + $HIP_CLANG_INCLUDE = `$HIP_CLANG_PATH/clang++ --print-resource-dir`; } - $HIP_CLANG_VERSION=~/.*clang version (\S+).*/; - $HIP_CLANG_VERSION=$1; $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; if($isWindows) { $CPP_CONFIG .= " -I\"$HIP_PATH_INCLUDE\" -I\"$HIP_CLANG_INCLUDE\""; } else { From 560bee0df3b95d9cf18d5e52d7fa99ffe6b0f488 Mon Sep 17 00:00:00 2001 From: Jeremy Newton Date: Wed, 31 May 2023 10:51:27 -0400 Subject: [PATCH 2/2] Improve HIP_CLANG_PATH detection Instead of checking for windows, it seems better to detect the location of the clang binary. Normally distros put clang bin in the same directory as hipcc, so this will improve the experience there too. Change-Id: I506faa15c8cc69500436f2dec3cdfd3f86356fab Signed-off-by: Jeremy Newton --- bin/hipvars.pm | 4 ++-- src/hipBin_amd.h | 5 ++++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/bin/hipvars.pm b/bin/hipvars.pm index bea4ec7..0bf8c69 100644 --- a/bin/hipvars.pm +++ b/bin/hipvars.pm @@ -83,8 +83,8 @@ if (-e "$HIP_PATH/bin/rocm_agent_enumerator") { } $CUDA_PATH=$ENV{'CUDA_PATH'} // '/usr/local/cuda'; -# Windows has a different structure, all binaries are inside hip/bin -if ($isWindows) { +# Windows/Distro's have a different structure, all binaries are with hipcc +if (-e "$HIP_PATH/bin/clang" or -e "$HIP_PATH/bin/clang.exe") { $HIP_CLANG_PATH=$ENV{'HIP_CLANG_PATH'} // "$HIP_PATH/bin"; } else { $HIP_CLANG_PATH=$ENV{'HIP_CLANG_PATH'} // "$ROCM_PATH/llvm/bin"; diff --git a/src/hipBin_amd.h b/src/hipBin_amd.h index 21102bc..6401585 100644 --- a/src/hipBin_amd.h +++ b/src/hipBin_amd.h @@ -218,11 +218,14 @@ void HipBinAmd::constructCompilerPath() { if (osInfo == windows) { complierPath = getHipPath(); hipClangPath = complierPath; - hipClangPath /= "bin"; } else { complierPath = getRoccmPath(); hipClangPath = complierPath; + } + if (fs::exists("llvm/bin/clang++")) { hipClangPath /= "llvm/bin"; + } else { + hipClangPath /= "bin"; } complierPath = hipClangPath.string(); } else {