diff --git a/hipamd/bin/extractkernel b/hipamd/bin/extractkernel
index d12645a996..43d9627646 100755
--- a/hipamd/bin/extractkernel
+++ b/hipamd/bin/extractkernel
@@ -8,6 +8,22 @@ use Cwd 'realpath';
use Getopt::Std;
use List::Util qw(max);
+my $base_dir;
+BEGIN {
+ $base_dir = Cwd::realpath( dirname(__FILE__) );
+}
+use lib "$base_dir/";
+use hipvars;
+
+$HIP_COMPILER = $hipvars::HIP_COMPILER;
+$HIP_CLANG_PATH = $hipvars::HIP_CLANG_PATH;
+$CUDA_PATH = $hipvars::CUDA_PATH;
+$HIP_PATH = $hipvars::HIP_PATH;
+$ROCM_PATH = $hipvars::ROCM_PATH;
+$HIP_VERSION = $hipvars::HIP_VERSION;
+$HSA_PATH = $hipvars::HSA_PATH;
+$HIP_ROCCLR_HOME = $hipvars::HIP_ROCCLR_HOME;
+
sub usage {
print("Usage: $0 [OPTION]... -i \n");
print("Extract the device kernels from an hcc executable.\n\n");
@@ -34,32 +50,14 @@ defined $options{i} || die("input not specified");
$input_file = $options{i};
(-f $input_file) || die("can't find $input_file");
-# derive HIP_PATH via env var or use parent directory of extractkernel
-my $HIP_PATH=$ENV{'HIP_PATH'} // dirname(Cwd::abs_path("$0/../"));
-my $HIP_COMPILER = `$HIP_PATH/bin/hipconfig --compiler`;
-my $ROCM_PATH = `$HIP_PATH/bin/hipconfig --rocmpath`;
-my $HIP_CLANG_PATH = `$HIP_PATH/bin/hipconfig --hipclangpath`;
-
# look for llvm-objdump and clang-offload-bundler
my $tools_path_prefix;
my $llvm_objdump;
my $clang_offload_bundler;
-if (defined $HIP_COMPILER and $HIP_COMPILER eq "clang"){
- # Search the path with respect to HIP_CLANG_PATH
- $tools_path_prefix = $HIP_CLANG_PATH;
-}
-else {
- if (defined $HIP_COMPILER and $HIP_COMPILER eq "hcc") {
- # Search the path with respect to HCC_HOME if it is set, else search in ROCM_PATH
- if (defined $ENV{'HCC_HOME'}) {
- $tools_path_prefix = File::Spec->catfile($ENV{'HCC_HOME'}, "bin");
- }
- else {
- $tools_path_prefix = realpath($ROCM_PATH."/hcc/bin");
- }
- }
-}
+# Search the path with respect to HIP_CLANG_PATH
+$tools_path_prefix = $HIP_CLANG_PATH;
+
# Find llvm-objdump and clang-offload-bundler in the path set above
$llvm_objdump = File::Spec->catfile($tools_path_prefix, "llvm-objdump");
$clang_offload_bundler = File::Spec->catfile($tools_path_prefix, "clang-offload-bundler");
diff --git a/hipamd/bin/hipcc b/hipamd/bin/hipcc
index 7fcc63c6fe..75b209c931 100755
--- a/hipamd/bin/hipcc
+++ b/hipamd/bin/hipcc
@@ -67,26 +67,7 @@ $HIPCC_LINK_FLAGS_APPEND=$ENV{'HIPCC_LINK_FLAGS_APPEND'};
# Known Features
@knownFeatures = ('sramecc-', 'sramecc+', 'xnack-', 'xnack+');
-#
-# 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 bin/rocm_agent_enumerator 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/../bin/rocm_agent_enumerator") {
- $ROCM_PATH=$ENV{'ROCM_PATH'} // dirname("$HIP_PATH"); # use parent directory of HIP_PATH
-} else {
- $ROCM_PATH=$ENV{'ROCM_PATH'} // "/opt/rocm";
-}
-$HIP_ROCCLR_HOME=$ENV{'HIP_ROCCLR_HOME'};
$HIP_LIB_PATH=$ENV{'HIP_LIB_PATH'};
-$HIP_CLANG_PATH=$ENV{'HIP_CLANG_PATH'};
$DEVICE_LIB_PATH=$ENV{'DEVICE_LIB_PATH'};
$HIP_CLANG_HCC_COMPAT_MODE=$ENV{'HIP_CLANG_HCC_COMPAT_MODE'}; # HCC compatibility mode
$HIP_COMPILE_CXX_AS_HIP=$ENV{'HIP_COMPILE_CXX_AS_HIP'} // "1";
@@ -112,52 +93,39 @@ sub delete_temp_dirs {
return 0;
}
-#---
-#HIP_PLATFORM controls whether to use amd or nvidia as the platform:
-#HIP_COMPILER controls whether to use clang or nvcc for compilation:
-#HIP_RUNTIME controls whether to use rocclr or cuda as the runtime:
-if ($isWindows) {
- # Windows cannot run perl natively, so hipcc will explicitly call perl
- $HIP_PLATFORM= `perl $HIP_PATH/bin/hipconfig --platform`;
- $HIP_VERSION= `perl $HIP_PATH/bin/hipconfig --version`;
- $HIP_COMPILER= `perl $HIP_PATH/bin/hipconfig --compiler`;
- $HIP_RUNTIME= `perl $HIP_PATH/bin/hipconfig --runtime`;
-} else {
- $HIP_PLATFORM= `$HIP_PATH/bin/hipconfig --platform`;
- $HIP_VERSION= `$HIP_PATH/bin/hipconfig --version`;
- $HIP_COMPILER= `$HIP_PATH/bin/hipconfig --compiler`;
- $HIP_RUNTIME= `$HIP_PATH/bin/hipconfig --runtime`;
+my $base_dir;
+BEGIN {
+ $base_dir = Cwd::realpath( dirname(__FILE__) );
}
+use lib "$base_dir/";
+use hipvars;
+
+$HIP_RUNTIME = $hipvars::HIP_RUNTIME;
+$HIP_PLATFORM = $hipvars::HIP_PLATFORM;
+$HIP_COMPILER = $hipvars::HIP_COMPILER;
+$HIP_CLANG_PATH = $hipvars::HIP_CLANG_PATH;
+$CUDA_PATH = $hipvars::CUDA_PATH;
+$HIP_PATH = $hipvars::HIP_PATH;
+$ROCM_PATH = $hipvars::ROCM_PATH;
+$HIP_VERSION = $hipvars::HIP_VERSION;
+$HSA_PATH = $hipvars::HSA_PATH;
+$HIP_ROCCLR_HOME = $hipvars::HIP_ROCCLR_HOME;
# If using ROCclr runtime, need to find HIP_ROCCLR_HOME
-if ($HIP_PLATFORM eq "amd" and !defined $HIP_ROCCLR_HOME) {
- my $hipcc_dir = dirname($0);
- if (-e "$hipcc_dir/../lib/bitcode") {
- $HIP_ROCCLR_HOME = abs_path($hipcc_dir . "/..");
- } else {
- $HIP_ROCCLR_HOME = $HIP_PATH; # use HIP_PATH
- }
+if ($HIP_PLATFORM eq "amd") {
$HIPCXXFLAGS .= "-D__HIP_ROCclr__";
$HIPCFLAGS .= "-D__HIP_ROCclr__";
}
-if (defined $HIP_ROCCLR_HOME) {
- if (!defined $HIP_CLANG_PATH and (-e "$HIP_ROCCLR_HOME/bin/clang" or -e "$HIP_ROCCLR_HOME/bin/clang.exe")) {
- $HIP_CLANG_PATH = "$HIP_ROCCLR_HOME/bin";
- }
- if (!defined $DEVICE_LIB_PATH and -e "$HIP_ROCCLR_HOME/lib/bitcode") {
- $DEVICE_LIB_PATH = "$HIP_ROCCLR_HOME/lib/bitcode";
- }
- $HIP_INCLUDE_PATH = "$HIP_ROCCLR_HOME/include";
- if (!defined $HIP_LIB_PATH) {
- $HIP_LIB_PATH = "$HIP_ROCCLR_HOME/lib";
- }
+if (!defined $DEVICE_LIB_PATH and -e "$HIP_ROCCLR_HOME/lib/bitcode") {
+ $DEVICE_LIB_PATH = "$HIP_ROCCLR_HOME/lib/bitcode";
+}
+$HIP_INCLUDE_PATH = "$HIP_ROCCLR_HOME/include";
+if (!defined $HIP_LIB_PATH) {
+ $HIP_LIB_PATH = "$HIP_ROCCLR_HOME/lib";
}
if ($HIP_PLATFORM eq "amd") {
- if (!defined $HIP_CLANG_PATH) {
- $HIP_CLANG_PATH = "$ROCM_PATH/llvm/bin";
- }
if (!defined $DEVICE_LIB_PATH) {
if (-e "$ROCM_PATH/amdgcn/bitcode") {
$DEVICE_LIB_PATH = "$ROCM_PATH/amdgcn/bitcode";
diff --git a/hipamd/bin/hipconfig b/hipamd/bin/hipconfig
index b0c446380c..976eb51c0f 100755
--- a/hipamd/bin/hipconfig
+++ b/hipamd/bin/hipconfig
@@ -1,8 +1,5 @@
#!/usr/bin/perl -w
-$HIP_BASE_VERSION_MAJOR = "4";
-$HIP_BASE_VERSION_MINOR = "0";
-
# Need perl > 5.10 to use logic-defined or
use 5.006; use v5.10.1;
use Getopt::Long;
@@ -13,6 +10,23 @@ use Cwd;
use Getopt::Long;
use File::Basename;
+my $base_dir;
+BEGIN {
+ $base_dir = Cwd::realpath( dirname(__FILE__) );
+}
+use lib "$base_dir/";
+use hipvars;
+
+$HIP_RUNTIME = $hipvars::HIP_RUNTIME;
+$HIP_PLATFORM = $hipvars::HIP_PLATFORM;
+$HIP_COMPILER = $hipvars::HIP_COMPILER;
+$HIP_CLANG_PATH = $hipvars::HIP_CLANG_PATH;
+$CUDA_PATH = $hipvars::CUDA_PATH;
+$HIP_PATH = $hipvars::HIP_PATH;
+$ROCM_PATH = $hipvars::ROCM_PATH;
+$HIP_VERSION = $hipvars::HIP_VERSION;
+$HSA_PATH = $hipvars::HSA_PATH;
+
Getopt::Long::Configure ( qw{bundling no_ignore_case});
GetOptions(
"help|h" => \$p_help
@@ -29,6 +43,20 @@ GetOptions(
,"newline|n" => \$p_newline
);
+if ($HIP_COMPILER eq "clang") {
+ $HIP_CLANG_VERSION = `$HIP_CLANG_PATH/clang++ --version`;
+ $HIP_CLANG_VERSION=~/.*clang version (\S+).*/;
+ $HIP_CLANG_VERSION=$1;
+
+ $CPP_CONFIG = " -D__HIP_PLATFORM_HCC__= -I$HIP_PATH/include -I$HIP_CLANG_PATH/../lib/clang/$HIP_CLANG_VERSION -I$HSA_PATH/include";
+}
+if ($HIP_RUNTIME eq "rocclr") {
+ $CPP_CONFIG .= " -D__HIP_ROCclr__";
+}
+if ($HIP_PLATFORM eq "nvidia") {
+ $CPP_CONFIG = " -D__HIP_PLATFORM_NVCC__= -I$HIP_PATH/include -I$CUDA_PATH/include";
+};
+
if ($p_help) {
print "usage: hipconfig [OPTIONS]\n";
print " --path, -p : print HIP_PATH (use env var if set, else determine from hipconfig path)\n";
@@ -46,116 +74,6 @@ if ($p_help) {
exit();
}
-#---
-# Function to parse config file
-sub parse_config_file {
- my ($file, $config) = @_;
- if (open (CONFIG, "$file")) {
- while () {
- my $config_line=$_;
- chop ($config_line);
- $config_line =~ s/^\s*//;
- $config_line =~ s/\s*$//;
- if (($config_line !~ /^#/) && ($config_line ne "")) {
- my ($name, $value) = split (/=/, $config_line);
- $$config{$name} = $value;
- }
- }
- close(CONFIG);
- }
-}
-
-#---
-# Function to check if executable can be run
-sub can_run {
- my ($exe) = @_;
- `$exe --version 2>&1`;
- if ($? == 0) {
- return 1;
- } else {
- return 0;
- }
-}
-
-# 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/../bin/rocm_agent_enumerator") {
- $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';
-$HSA_PATH=$ENV{'HSA_PATH'} // "$ROCM_PATH/hsa";
-$HIP_CLANG_PATH=$ENV{'HIP_CLANG_PATH'} // "$ROCM_PATH/llvm/bin";
-# HIP_ROCCLR_HOME is used by Windows builds
-$HIP_ROCCLR_HOME=$ENV{'HIP_ROCCLR_HOME'};
-
-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:
-$HIP_PLATFORM=$ENV{'HIP_PLATFORM'};
-# Read .hipInfo
-my %hipInfo = ();
-parse_config_file("$HIP_INFO_PATH", \%hipInfo);
-# Prioritize Env first, otherwise use the hipInfo config file
-$HIP_COMPILER = $ENV{'HIP_COMPILER'} // $hipInfo{'HIP_COMPILER'} // "clang";
-$HIP_RUNTIME = $ENV{'HIP_RUNTIME'} // $hipInfo{'HIP_RUNTIME'} // "rocclr";
-
-# If using ROCclr runtime, need to find HIP_ROCCLR_HOME
-if (defined $HIP_RUNTIME and $HIP_RUNTIME eq "rocclr" and !defined $HIP_ROCCLR_HOME) {
- my $hipconfig_dir = dirname($0);
- if (-e "$hipconfig_dir/../lib/bitcode") {
- $HIP_ROCCLR_HOME = abs_path($hipconfig_dir . "/..");
- } else {
- $HIP_ROCCLR_HOME = $HIP_PATH; # use HIP_PATH
- }
-}
-
-if (not defined $HIP_PLATFORM) {
- if (can_run("$HIP_CLANG_PATH/clang++") or can_run("clang++")) {
- $HIP_PLATFORM = "amd";
- } elsif (can_run("$CUDA_PATH/bin/nvcc") or can_run("nvcc")) {
- $HIP_PLATFORM = "nvidia";
- $HIP_COMPILER = "nvcc";
- $HIP_RUNTIME = "cuda";
- } else {
- # Default to amd for now
- $HIP_PLATFORM = "amd";
- }
-}
-
-if ($HIP_COMPILER eq "clang") {
- # Windows does not have clang at linux default path
- if (defined $HIP_ROCCLR_HOME and (-e "$HIP_ROCCLR_HOME/bin/clang" or -e "$HIP_ROCCLR_HOME/bin/clang.exe")) {
- $HIP_CLANG_PATH = "$HIP_ROCCLR_HOME/bin";
- }
- $HIP_CLANG_VERSION = `$HIP_CLANG_PATH/clang++ --version`;
- $HIP_CLANG_VERSION=~/.*clang version (\S+).*/;
- $HIP_CLANG_VERSION=$1;
-
- $CPP_CONFIG = " -D__HIP_PLATFORM_HCC__= -I$HIP_PATH/include -I$HIP_CLANG_PATH/../lib/clang/$HIP_CLANG_VERSION -I$HSA_PATH/include";
-}
-if ($HIP_RUNTIME eq "rocclr") {
- $CPP_CONFIG .= " -D__HIP_ROCclr__";
-}
-if ($HIP_PLATFORM eq "nvidia") {
- $CPP_CONFIG = " -D__HIP_PLATFORM_NVCC__= -I$HIP_PATH/include -I$CUDA_PATH/include";
-};
-
-#---
-# Read .hipVersion
-my %hipVersion = ();
-parse_config_file("$HIP_PATH/bin/.hipVersion", \%hipVersion);
-$HIP_VERSION_MAJOR = $hipVersion{'HIP_VERSION_MAJOR'} // $HIP_BASE_VERSION_MAJOR;
-$HIP_VERSION_MINOR = $hipVersion{'HIP_VERSION_MINOR'} // $HIP_BASE_VERSION_MINOR;
-$HIP_VERSION_PATCH = $hipVersion{'HIP_VERSION_PATCH'} // "0";
-$HIP_VERSION="$HIP_VERSION_MAJOR.$HIP_VERSION_MINOR.$HIP_VERSION_PATCH";
-
if ($p_path) {
print "$HIP_PATH";
$printed = 1;
diff --git a/hipamd/bin/hipvars.pm b/hipamd/bin/hipvars.pm
new file mode 100644
index 0000000000..5ab99909eb
--- /dev/null
+++ b/hipamd/bin/hipvars.pm
@@ -0,0 +1,116 @@
+#!/usr/bin/perl -w
+package hipvars;
+use Getopt::Long;
+use Cwd;
+use File::Basename;
+
+$HIP_BASE_VERSION_MAJOR = "4";
+$HIP_BASE_VERSION_MINOR = "0";
+
+#---
+# Function to parse config file
+sub parse_config_file {
+ my ($file, $config) = @_;
+ if (open (CONFIG, "$file")) {
+ while () {
+ my $config_line=$_;
+ chop ($config_line);
+ $config_line =~ s/^\s*//;
+ $config_line =~ s/\s*$//;
+ if (($config_line !~ /^#/) && ($config_line ne "")) {
+ my ($name, $value) = split (/=/, $config_line);
+ $$config{$name} = $value;
+ }
+ }
+ close(CONFIG);
+ }
+}
+
+#---
+# Function to check if executable can be run
+sub can_run {
+ my ($exe) = @_;
+ `$exe --version 2>&1`;
+ if ($? == 0) {
+ return 1;
+ } else {
+ return 0;
+ }
+}
+
+#
+# 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 bin/rocm_agent_enumerator 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/../bin/rocm_agent_enumerator") {
+ $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';
+$HSA_PATH=$ENV{'HSA_PATH'} // "$ROCM_PATH/hsa";
+$HIP_CLANG_PATH=$ENV{'HIP_CLANG_PATH'} // "$ROCM_PATH/llvm/bin";
+# HIP_ROCCLR_HOME is used by Windows builds
+$HIP_ROCCLR_HOME=$ENV{'HIP_ROCCLR_HOME'};
+
+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:
+$HIP_PLATFORM=$ENV{'HIP_PLATFORM'};
+# Read .hipInfo
+my %hipInfo = ();
+parse_config_file("$HIP_INFO_PATH", \%hipInfo);
+# Prioritize Env first, otherwise use the hipInfo config file
+$HIP_COMPILER = $ENV{'HIP_COMPILER'} // $hipInfo{'HIP_COMPILER'} // "clang";
+$HIP_RUNTIME = $ENV{'HIP_RUNTIME'} // $hipInfo{'HIP_RUNTIME'} // "rocclr";
+
+# If using ROCclr runtime, need to find HIP_ROCCLR_HOME
+if (defined $HIP_RUNTIME and $HIP_RUNTIME eq "rocclr" and !defined $HIP_ROCCLR_HOME) {
+ my $hipvars_dir = dirname($0);
+ if (-e "$hipvars_dir/../lib/bitcode") {
+ $HIP_ROCCLR_HOME = abs_path($hipvars_dir . "/..");
+ } else {
+ $HIP_ROCCLR_HOME = $HIP_PATH; # use HIP_PATH
+ }
+}
+
+if (not defined $HIP_PLATFORM) {
+ if (can_run("$HIP_CLANG_PATH/clang++") or can_run("clang++")) {
+ $HIP_PLATFORM = "amd";
+ } elsif (can_run("$CUDA_PATH/bin/nvcc") or can_run("nvcc")) {
+ $HIP_PLATFORM = "nvidia";
+ $HIP_COMPILER = "nvcc";
+ $HIP_RUNTIME = "cuda";
+ } else {
+ # Default to amd for now
+ $HIP_PLATFORM = "amd";
+ }
+}
+
+if ($HIP_COMPILER eq "clang") {
+ # Windows does not have clang at linux default path
+ if (defined $HIP_ROCCLR_HOME and (-e "$HIP_ROCCLR_HOME/bin/clang" or -e "$HIP_ROCCLR_HOME/bin/clang.exe")) {
+ $HIP_CLANG_PATH = "$HIP_ROCCLR_HOME/bin";
+ }
+}
+
+#---
+# Read .hipVersion
+my %hipVersion = ();
+parse_config_file("$hipvars::HIP_PATH/bin/.hipVersion", \%hipVersion);
+$HIP_VERSION_MAJOR = $hipVersion{'HIP_VERSION_MAJOR'} // $HIP_BASE_VERSION_MAJOR;
+$HIP_VERSION_MINOR = $hipVersion{'HIP_VERSION_MINOR'} // $HIP_BASE_VERSION_MINOR;
+$HIP_VERSION_PATCH = $hipVersion{'HIP_VERSION_PATCH'} // "0";
+$HIP_VERSION="$HIP_VERSION_MAJOR.$HIP_VERSION_MINOR.$HIP_VERSION_PATCH";
\ No newline at end of file