Files
rocm-systems/bin/hipconfig
T

193 строки
5.2 KiB
Perl
Исходник Обычный вид История

2016-01-26 20:14:33 -06:00
#!/usr/bin/perl -w
2016-07-11 16:38:41 +05:30
$HIP_BASE_VERSION_MAJOR = "0";
$HIP_BASE_VERSION_MINOR = "92";
# Need perl > 5.10 to use logic-defined or
use 5.006; use v5.10.1;
2016-01-26 20:14:33 -06:00
use Getopt::Long;
use Cwd;
# Return name of HIP compiler - either 'nvcc' or 'hcc'
#
use Getopt::Long;
use File::Basename;
Getopt::Long::Configure ( qw{bundling no_ignore_case});
GetOptions(
"help|h" => \$p_help
,"path|p" => \$p_path
,"compiler|c" => \$p_compiler
,"platform|P" => \$p_platform
,"cpp_config|cxx_config|C" => \$p_cpp_config
2016-02-25 23:07:18 -06:00
,"full|f|info" => \$p_full,
2016-07-11 16:38:41 +05:30
,"version|v" => \$p_version,
2016-02-27 21:26:40 -06:00
,"check" => \$p_check,
2016-01-26 20:14:33 -06:00
,"newline|n" => \$p_newline
);
if ($p_help) {
2016-02-09 11:51:26 +05:30
print "usage: hipconfig [OPTIONS]\n";
2016-01-26 20:14:33 -06:00
print " --path, -p : print HIP_PATH (use env var if set, else determine from hipconfig path)\n";
print " --cpp_config, -C : print C++ compiler options\n";
print " --compiler, -c : print compiler (hcc or nvcc)\n";
print " --platform, -P : print platform (hcc or nvcc)\n";
2016-01-28 20:16:43 -06:00
print " --full, -f : print full config\n";
2016-07-11 16:38:41 +05:30
print " --version, -v : print hip version\n";
2016-02-27 21:26:40 -06:00
print " --check : check configuration\n";
2016-01-26 20:14:33 -06:00
print " --newline, -n : print newline\n";
print " --help, -h : print help message\n";
exit();
}
#---
# Function to parse config file
sub parse_config_file {
my ($file, $config) = @_;
if (open (CONFIG, "$file")) {
while (<CONFIG>) {
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);
}
}
2016-01-26 20:14:33 -06:00
$CUDA_PATH=$ENV{'CUDA_PATH'} // '/usr/local/cuda';
$HCC_HOME=$ENV{'HCC_HOME'} // '/opt/rocm/hcc';
$HSA_PATH=$ENV{'HSA_PATH'} // '/opt/rocm/hsa';
2016-02-27 21:26:40 -06:00
2016-01-26 20:14:33 -06:00
#---
#HIP_PLATFORM controls whether to use NVCC or HCC for compilation:
$HIP_PLATFORM=$ENV{'HIP_PLATFORM'};
2016-03-25 17:08:34 -05:00
if (not defined $HIP_PLATFORM) {
$NAMDGPUNODES=`cat /sys/class/kfd/kfd/topology/nodes/*/properties 2>/dev/null | grep -c 'simd_count [1-9]'`;
2016-08-12 23:21:37 +05:30
2016-03-25 17:08:34 -05:00
if ($NAMDGPUNODES > 0) {
$HIP_PLATFORM = "hcc"
} else {
$HIP_PLATFORM = "nvcc";
}
2016-01-26 20:14:33 -06:00
}
$HIP_PATH=$ENV{'HIP_PATH'} // Cwd::realpath (dirname (dirname $0)); # use parent directory of this tool
2016-01-26 20:14:33 -06:00
2016-01-28 20:16:43 -06:00
if ($HIP_PLATFORM eq "hcc") {
$CPP_CONFIG= " -D__HIP_PLATFORM_HCC__= -I$HIP_PATH/include -I$HCC_HOME/include";
}
if ($HIP_PLATFORM eq "nvcc") {
$CPP_CONFIG = " -D__HIP_PLATFORM_NVCC__= -I$HIP_PATH/include -I$CUDA_PATH/include";
};
2016-01-26 20:14:33 -06:00
2016-08-12 23:21:37 +05:30
#---
# Read .version
my %hipVersion = ();
parse_config_file("$HIP_PATH/bin/.version", \%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";
2016-08-12 23:21:37 +05:30
$HIP_VERSION="$HIP_VERSION_MAJOR.$HIP_VERSION_MINOR.$HIP_VERSION_PATCH";
2016-01-26 20:14:33 -06:00
if ($p_path) {
print "$HIP_PATH";
$printed = 1;
}
2016-08-12 23:21:37 +05:30
2016-01-26 20:14:33 -06:00
if ($p_cpp_config) {
2016-01-28 20:16:43 -06:00
print $CPP_CONFIG;
2016-01-26 20:14:33 -06:00
$printed = 1;
}
2016-02-27 20:34:33 -06:00
if ($p_compiler or $p_platform) {
print $HIP_PLATFORM;
$printed = 1;
}
2016-07-11 16:38:41 +05:30
if ($p_version) {
print $HIP_VERSION;
$printed = 1;
}
2016-02-27 21:26:40 -06:00
2016-02-27 20:34:33 -06:00
if (!$printed or $p_full) {
2016-07-11 16:38:41 +05:30
print "HIP version : ", $HIP_VERSION, "\n\n";
2016-01-28 20:16:43 -06:00
print "== hipconfig\n";
print "HIP_PATH : ", $HIP_PATH, "\n";
print "HIP_PLATFORM : ", $HIP_PLATFORM, "\n";
print "CPP_CONFIG : ", $CPP_CONFIG, "\n";
2016-08-12 23:21:37 +05:30
if ($HIP_PLATFORM eq "hcc")
2016-01-28 20:16:43 -06:00
{
print "\n" ;
print "== hcc\n";
2016-02-27 21:26:40 -06:00
print ("HSA_PATH : $HSA_PATH\n");
2016-01-28 20:16:43 -06:00
print ("HCC_HOME : $HCC_HOME\n");
system("$HCC_HOME/bin/hcc --version");
2016-08-12 23:21:37 +05:30
print ("HCC-cxxflags : ");
2016-02-03 09:48:44 -06:00
system("$HCC_HOME/bin/hcc-config --cxxflags");
2016-08-12 23:21:37 +05:30
print ("HCC-ldflags : ");
2016-02-03 09:48:44 -06:00
system("$HCC_HOME/bin/hcc-config --ldflags");
2016-02-17 21:22:31 -06:00
printf("\n");
2016-01-28 20:16:43 -06:00
}
if ($HIP_PLATFORM eq "nvcc") {
print "\n" ;
print "== nvcc\n";
#print "CUDA_PATH :", $CUDA_PATH";
system("nvcc --version");
}
print "\n" ;
print "=== Environment Variables\n";
2016-02-25 23:07:18 -06:00
system("echo PATH=\$PATH");
system("env | egrep '^HIP|^HSA|^HCC|^CUDA|^LD_LIBRARY_PATH'");
2016-01-28 20:16:43 -06:00
print "\n" ;
print "== Linux Kernel\n";
2016-04-25 15:13:23 -05:00
print "Hostname : "; system ("hostname");
2016-01-28 20:16:43 -06:00
system ("uname -a");
2016-02-17 21:22:31 -06:00
2016-03-24 22:12:41 -05:00
if (-e "/usr/bin/lsb_release") {
system ("/usr/bin/lsb_release -a");
}
2016-02-17 21:22:31 -06:00
print "\n" ;
2016-01-28 20:16:43 -06:00
$printed = 1;
}
2016-01-26 20:14:33 -06:00
2016-02-27 21:26:40 -06:00
if ($p_check) {
print "\nCheck system installation:\n";
printf ("%-70s", "check hipconfig in PATH...");
if (system ("hipconfig > /dev/null 2>&1") != 0) {
print "FAIL\n";
} else {
printf "good\n";
}
if ($HIP_PLATFORM eq "hcc") {
$LD_LIBRARY_PATH=$ENV{'LD_LIBRARY_PATH'};
printf("%-70s", "check LD_LIBRARY_PATH ($LD_LIBRARY_PATH) contains HSA_PATH ($HSA_PATH)...");
if (index($LD_LIBRARY_PATH, $HSA_PATH) == -1) {
print "FAIL\n";
} else {
printf "good\n";
}
# TODO - check hipcc / nvcc found and executable.
}
}
2016-01-26 20:14:33 -06:00
if ($p_newline) {
print "\n";
}