Merge branch 'amd-master-next' into amd-npi-next

Change-Id: Id97c6b8c875731250049a5b9dc8062311ae291ad
This commit is contained in:
Vlad Sytchenko
2020-05-07 17:17:21 -04:00
melakukan 88172bac72
98 mengubah file dengan 618 tambahan dan 962 penghapusan
+59 -71
Melihat File
@@ -20,13 +20,15 @@ use Cwd 'abs_path';
# If HIP_PLATFORM is not set hipcc will attempt auto-detect based on if nvcc is found.
#
# 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 (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.
# 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 (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_ROCclr_HOME : Path to HIP/ROCclr directory. Used on AMD platforms only.
# HIP_CLANG_PATH : Path to HIP-Clang (default to ../../llvm/bin relative to this
# script's abs_path). Used on AMD platforms only.
if(scalar @ARGV == 0){
print "No Arguments passed, exiting ...\n";
@@ -80,15 +82,15 @@ if (-e "$HIP_PATH/../.info/version") {
} else {
$ROCM_PATH=$ENV{'ROCM_PATH'} // "/opt/rocm";
}
$HIP_VDI_HOME=$ENV{'HIP_VDI_HOME'};
$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";
if (defined $HIP_VDI_HOME) {
$HIP_INFO_PATH= "$HIP_VDI_HOME/lib/.hipInfo";
if (defined $HIP_ROCclr_HOME) {
$HIP_INFO_PATH= "$HIP_ROCclr_HOME/lib/.hipInfo";
} else {
$HIP_INFO_PATH= "$HIP_PATH/lib/.hipInfo"; # use actual file
}
@@ -120,39 +122,40 @@ sub delete_temp_dirs {
}
#---
#HIP_PLATFORM controls whether to use NVCC or HCC for compilation:
#HIP_PLATFORM controls whether to use hcc (AMD) or nvcc as the platform:
$HIP_PLATFORM= `$HIP_PATH/bin/hipconfig --platform` // "hcc";
$HIP_VERSION= `$HIP_PATH/bin/hipconfig --version`;
$HIP_COMPILER= $hipConfig{'HIP_COMPILER'};
$HIP_RUNTIME= $hipConfig{'HIP_RUNTIME'};
#HIP_COMPILER controls whether to use hcc, clang or nvcc for compilation:
$HIP_COMPILER= `$HIP_PATH/bin/hipconfig --compiler`;
#HIP_RUNTIME controls whether to use HCC, ROCclr, or NVCC as the runtime:
$HIP_RUNTIME= `$HIP_PATH/bin/hipconfig --runtime`;
# If using VDI runtime, need to find HIP_VDI_HOME
if (defined $HIP_RUNTIME and $HIP_RUNTIME eq "VDI" and !defined $HIP_VDI_HOME) {
# 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 $hipcc_dir = dirname($0);
if (-e "$hipcc_dir/../lib/bitcode") {
$HIP_VDI_HOME = abs_path($hipcc_dir . "/..");
$HIP_ROCclr_HOME = abs_path($hipcc_dir . "/..");
} else {
$HIP_VDI_HOME = $HIP_PATH; # use HIP_PATH
$HIP_ROCclr_HOME = $HIP_PATH; # use HIP_PATH
}
$HIPCXXFLAGS .= "-D__HIP_VDI__";
$HIPCFLAGS .= "-D__HIP_VDI__";
$HIPCXXFLAGS .= "-D__HIP_ROCclr__";
$HIPCFLAGS .= "-D__HIP_ROCclr__";
}
if (defined $HIP_VDI_HOME) {
if (!defined $HIP_CLANG_PATH and (-e "$HIP_VDI_HOME/bin/clang" or -e "$HIP_VDI_HOME/bin/clang.exe")) {
$HIP_CLANG_PATH = "$HIP_VDI_HOME/bin";
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_VDI_HOME/lib/bitcode") {
$DEVICE_LIB_PATH = "$HIP_VDI_HOME/lib/bitcode";
if (!defined $DEVICE_LIB_PATH and -e "$HIP_ROCclr_HOME/lib/bitcode") {
$DEVICE_LIB_PATH = "$HIP_ROCclr_HOME/lib/bitcode";
}
$HIP_INCLUDE_PATH = "$HIP_VDI_HOME/include";
$HIP_INCLUDE_PATH = "$HIP_ROCclr_HOME/include";
if (!defined $HIP_LIB_PATH) {
$HIP_LIB_PATH = "$HIP_VDI_HOME/lib";
$HIP_LIB_PATH = "$HIP_ROCclr_HOME/lib";
}
}
if (defined $HIP_COMPILER and $HIP_COMPILER eq "clang") {
$HIP_PLATFORM = "clang";
if (defined $HIP_COMPILER and $HIP_PLATFORM eq "hcc" and $HIP_COMPILER eq "clang") {
if (!defined $HIP_CLANG_PATH) {
$HIP_CLANG_PATH = "$ROCM_PATH/llvm/bin";
}
@@ -164,6 +167,8 @@ if (defined $HIP_COMPILER and $HIP_COMPILER eq "clang") {
if ($verbose & 0x2) {
print ("HIP_PATH=$HIP_PATH\n");
print ("HIP_PLATFORM=$HIP_PLATFORM\n");
print ("HIP_COMPILER=$HIP_COMPILER\n");
print ("HIP_RUNTIME=$HIP_RUNTIME\n");
}
# set if user explicitly requests -stdlib=libc++. (else we default to libstdc++ for better interop with g++):
@@ -171,7 +176,7 @@ $setStdLib = 0; # TODO - set to 0
$default_amdgpu_target = 1;
if ($HIP_PLATFORM eq "clang") {
if ($HIP_PLATFORM eq "hcc" and $HIP_COMPILER eq "clang") {
$HIPCC="$HIP_CLANG_PATH/clang++";
# If $HIPCC clang++ is not compiled, use clang instead
@@ -194,8 +199,8 @@ if ($HIP_PLATFORM eq "clang") {
$HIP_LIB_PATH = "$HIP_PATH/lib";
}
if ($verbose & 0x2) {
if (defined $HIP_VDI_HOME) {
print ("HIP_VDI_HOME=$HIP_VDI_HOME\n");
if (defined $HIP_ROCclr_HOME) {
print ("HIP_ROCclr_HOME=$HIP_ROCclr_HOME\n");
}
print ("HIP_CLANG_PATH=$HIP_CLANG_PATH\n");
print ("HIP_CLANG_INCLUDE_PATH=$HIP_CLANG_INCLUDE_PATH\n");
@@ -224,11 +229,11 @@ if ($HIP_PLATFORM eq "clang") {
$HIPCXXFLAGS .= " -isystem $HSA_PATH/include";
$HIPCFLAGS .= " -isystem $HSA_PATH/include";
if ($HIP_RUNTIME ne "HCC" ) {
$HIPCXXFLAGS .= " -D__HIP_VDI__";
$HIPCFLAGS .= " -D__HIP_VDI__";
$HIPCXXFLAGS .= " -D__HIP_ROCclr__";
$HIPCFLAGS .= " -D__HIP_ROCclr__";
}
} elsif ($HIP_PLATFORM eq "hcc") {
} elsif ($HIP_PLATFORM eq "hcc" and $HIP_COMPILER eq "hcc") {
$HIP_INCLUDE_PATH = "$HIP_PATH/include";
if (! defined $HIP_LIB_PATH) {
$HIP_LIB_PATH = "$HIP_PATH/lib";
@@ -243,9 +248,6 @@ if ($HIP_PLATFORM eq "clang") {
$HCC_VERSION_MAJOR=$HCC_VERSION;
$HCC_VERSION_MAJOR=~s/\..*//;
$HIP_ATP_MARKER=$ENV{'HIP_ATP_MARKER'} // 1;
$marker_path = "$ROCM_PATH/profiler/CXLActivityLogger";
# HCC* may be used to compile src/hip_hcc.o (and also feed the HIPCXXFLAGS below)
$HCC = "$HCC_HOME/bin/hcc";
$HCCFLAGS = "-hc -D__HIPCC__ -isystem $HCC_HOME/include ";
@@ -293,20 +295,6 @@ if ($HIP_PLATFORM eq "clang") {
$HIPLDFLAGS .= " -L$HSA_PATH/lib -L$ROCM_PATH/lib -lhsa-runtime64 -lhc_am ";
# $HIPLDFLAGS .= " -L$HCC_HOME/compiler/lib -lLLVMAMDGPUDesc -lLLVMAMDGPUUtils -lLLVMMC -lLLVMCore -lLLVMSupport ";
# Add trace marker library:
# TODO - once we cleanly separate the HIP API headers from HIP library headers this logic should move to CMakebuild option - apps do not need to see the marker library.
if ($HIP_ATP_MARKER) {
$marker_inc_path = "$marker_path/include";
if (-e $marker_inc_path) {
$HIPCXXFLAGS .= " -isystem $marker_inc_path";
}
}
$marker_lib_path = "$marker_path/bin/x86_64";
if (-e $marker_lib_path) {
$HIPLDFLAGS .= " -L$marker_lib_path -lCXLActivityLogger -Wl,--rpath=$marker_lib_path";
}
if (not $isWindows) {
$HIPLDFLAGS .= " -lm";
}
@@ -331,6 +319,7 @@ if ($HIP_PLATFORM eq "clang") {
$HIPLDFLAGS = " -Wno-deprecated-gpu-targets -lcuda -lcudart -L$CUDA_PATH/lib64";
} else {
printf ("error: unknown HIP_PLATFORM = '$HIP_PLATFORM'");
printf (" or HIP_COMPILER = '$HIP_COMPILER'");
exit (-1);
}
@@ -346,7 +335,7 @@ my $hasC = 0; # options contain a c-style file
my $hasCXX = 0; # options contain a cpp-style file (NVCC must force recognition as GPU file)
my $hasCU = 0; # options contain a cu-style file (HCC must force recognition as GPU file)
my $hasHIP = 0; # options contain a hip-style file (HIP-Clang must pass offloading options)
my $needHipHcc = ($HIP_PLATFORM eq 'hcc'); # set if we need to link hip_hcc.o from src tree. (some builds, ie cmake, provide their own)
my $needHipHcc = ($HIP_PLATFORM eq 'hcc' and $HIP_COMPILER eq 'hcc'); # set if we need to link hip_hcc.o from src tree. (some builds, ie cmake, provide their own)
my $printHipVersion = 0; # print HIP version
my $printCXXFlags = 0; # print HIPCXXFLAGS
my $printLDFlags = 0; # print HIPLDFLAGS
@@ -370,7 +359,7 @@ if ($verbose & 0x4) {
# Handle code object generation
my $ISACMD="";
if($HIP_PLATFORM eq "hcc"){
if($HIP_PLATFORM eq "hcc" and $HIP_COMPILER eq "hcc"){
$ISACMD .= "$HIP_PATH/bin/lpl ";
if($ARGV[0] eq "--genco"){
foreach $isaarg (@ARGV[1..$#ARGV]){
@@ -385,7 +374,7 @@ if($HIP_PLATFORM eq "hcc"){
}
}
if(($HIP_PLATFORM eq "hcc")){
if(($HIP_PLATFORM eq "hcc" and $HIP_COMPILER eq "hcc")){
$ENV{HCC_EXTRA_LIBRARIES}="\n";
}
@@ -416,7 +405,7 @@ foreach $arg (@ARGV)
$trimarg = $arg;
$trimarg =~ s/^\s+|\s+$//g; # Remive whitespace
my $swallowArg = 0;
if ($arg eq '-c' or $arg eq '--genco') {
if ($arg eq '-c' or $arg eq '--genco' or $arg eq '-E') {
$compileOnly = 1;
$needLDFLAGS = 0;
}
@@ -446,7 +435,7 @@ foreach $arg (@ARGV)
$targetsStr .= substr($arg, length($targetOpt));
$default_amdgpu_target = 0;
# hip-clang does not accept --amdgpu-target= options.
if ($HIP_PLATFORM eq 'clang') {
if ($HIP_PLATFORM eq "hcc" and $HIP_COMPILER eq "clang") {
$swallowArg = 1;
}
}
@@ -459,7 +448,7 @@ foreach $arg (@ARGV)
$coFormatv3 = 0;
}
if (($arg =~ /--genco/) and $HIP_PLATFORM eq 'clang' ) {
if (($arg =~ /--genco/) and $HIP_PLATFORM eq 'hcc' and $HIP_COMPILER eq 'clang' ) {
$arg = "--cuda-device-only";
}
@@ -512,7 +501,7 @@ foreach $arg (@ARGV)
## hip-clang in command line.
## ToDo: Remove this after hip-clang switch to lto and lld is able to
## handle clang-offload-bundler bundles.
if ($arg =~ m/^-Wl,@/ and $HIP_PLATFORM eq 'clang') {
if ($arg =~ m/^-Wl,@/ and $HIP_PLATFORM eq 'hcc' and $HIP_COMPILER eq 'clang') {
my $file = substr $arg, 5;
open my $in, "<:encoding(utf8)", $file or die "$file: $!";
my $new_arg = "";
@@ -568,13 +557,12 @@ foreach $arg (@ARGV)
close $out;
$arg = "$new_arg -Wl,\@$new_file";
} elsif (($arg =~ m/\.a$/ || $arg =~ m/\.lo$/) &&
$HIP_PLATFORM eq 'clang') {
$HIP_PLATFORM eq 'hcc' and $HIP_COMPILER eq 'clang') {
## process static library for hip-clang
## extract object files from static library and pass them directly to
## hip-clang.
## ToDo: Remove this after hip-clang switch to lto and lld is able to
## handle clang-offload-bundler bundles.
my $new_arg = "";
my $tmpdir = get_temp_dir ();
my $libFile = $arg;
@@ -661,7 +649,7 @@ foreach $arg (@ARGV)
}
elsif ((($arg =~ /\.cu$/ or $arg =~ /\.cuh$/) and $HIP_COMPILE_CXX_AS_HIP ne '0') or ($arg =~ /\.hip$/)) {
$needCXXFLAGS = 1;
if ($HIP_COMPILER eq "clang") {
if ($HIP_PLATFORM eq "hcc" and $HIP_COMPILER eq "clang") {
$hasHIP = 1;
$toolArgs .= " -x hip";
} else {
@@ -675,7 +663,7 @@ foreach $arg (@ARGV)
$prevArg = $arg;
}
if($HIP_PLATFORM eq "hcc" or $HIP_PLATFORM eq "clang"){
if($HIP_PLATFORM eq "hcc"){
# No AMDGPU target specified at commandline. So look for HCC_AMDGPU_TARGET
if($default_amdgpu_target eq 1) {
if (defined $ENV{HCC_AMDGPU_TARGET}) {
@@ -692,7 +680,7 @@ if($HIP_PLATFORM eq "hcc" or $HIP_PLATFORM eq "clang"){
# Parse the targets collected in targetStr and set corresponding compiler options.
my @targets = split(',', $targetsStr);
if($HIP_PLATFORM eq "hcc") {
if($HIP_COMPILER eq "hcc") {
$GPU_ARCH_OPT = " --amdgpu-target=";
} else {
$GPU_ARCH_OPT = " --cuda-gpu-arch=";
@@ -708,7 +696,7 @@ if($HIP_PLATFORM eq "hcc" or $HIP_PLATFORM eq "clang"){
$GPU_ARCH_ARG = $GPU_ARCH_OPT . $val;
$HIPLDARCHFLAGS .= $GPU_ARCH_ARG;
$HIPCXXFLAGS .= $archMacro;
if ($HIP_PLATFORM eq 'clang' and $hasHIP) {
if ($HIP_COMPILER eq 'clang' and $hasHIP) {
$HIPCXXFLAGS .= $GPU_ARCH_ARG;
}
@@ -729,7 +717,7 @@ if($HIP_PLATFORM eq "hcc" or $HIP_PLATFORM eq "clang"){
# hcc defaults to v2, so we need to convert to the appropriate flag
# hip-clang defaults to v3, so we don't need to do anything
if ($coFormatv3 and $HIP_PLATFORM eq 'hcc') {
if ($coFormatv3 and $HIP_PLATFORM eq 'hcc' and $HIP_COMPILER eq 'hcc') {
$HIPLDFLAGS .= " -mcode-object-v3";
$HIPCXXFLAGS .= " -mcode-object-v3";
}
@@ -737,7 +725,7 @@ if ($coFormatv3 and $HIP_PLATFORM eq 'hcc') {
if ($hasCXX and $HIP_PLATFORM eq 'nvcc') {
$HIPCXXFLAGS .= " -x cu";
}
if ($hasCU and $HIP_PLATFORM eq 'hcc') {
if ($hasCU and $HIP_PLATFORM eq 'hcc' and $HIP_COMPILER eq 'hcc') {
$HIPCXXFLAGS .= " -x c++";
}
@@ -746,17 +734,17 @@ if ($buildDeps and $HIP_PLATFORM eq 'nvcc') {
$HIPCFLAGS .= " -M -D__CUDACC__";
}
if ($buildDeps and $HIP_PLATFORM eq 'clang') {
if ($buildDeps and $HIP_PLATFORM eq 'hcc' and $HIP_COMPILER eq 'clang') {
$HIPCXXFLAGS .= " --cuda-host-only";
}
# Add --hip-link only if it is compile only and -fgpu-rdc is on.
if ($rdc and !$compileOnly and $HIP_PLATFORM eq 'clang') {
if ($rdc and !$compileOnly and $HIP_PLATFORM eq 'hcc' and $HIP_COMPILER eq 'clang') {
$HIPLDFLAGS .= " --hip-link";
$HIPLDFLAGS .= $HIPLDARCHFLAGS;
}
if ($setStdLib eq 0 and $HIP_PLATFORM eq 'hcc')
if ($setStdLib eq 0 and $HIP_PLATFORM eq 'hcc' and $HIP_COMPILER eq 'hcc')
{
$HIPCXXFLAGS .= $HCC_WA_FLAGS;
}
@@ -774,7 +762,7 @@ if ($needHipHcc) {
# Reason is that NVCC uses the file extension to determine whether to compile in CUDA mode or
# pass-through CPP mode.
if ($HIP_PLATFORM eq "clang") {
if ($HIP_PLATFORM eq "hcc" and $HIP_COMPILER eq "clang") {
# Set default optimization level to -O3 for hip-clang.
if ($optArg eq "") {
$HIPCXXFLAGS .= " -O3";
@@ -849,7 +837,7 @@ if ($printLDFlags) {
print $HIPLDFLAGS;
}
if ($runCmd) {
if ($HIP_PLATFORM eq "hcc" and exists($hipConfig{'HCC_VERSION'}) and $HCC_VERSION ne $hipConfig{'HCC_VERSION'}) {
if ($HIP_PLATFORM eq "hcc" and $HIP_COMPILER eq "hcc" and exists($hipConfig{'HCC_VERSION'}) and $HCC_VERSION ne $hipConfig{'HCC_VERSION'}) {
print ("HIP ($HIP_PATH) was built using hcc $hipConfig{'HCC_VERSION'}, but you are using $HCC_HOME/hcc with version $HCC_VERSION from hipcc. Please rebuild HIP including cmake or update HCC_HOME variable.\n") ;
die unless $ENV{'HIP_IGNORE_HCC_VERSION'};
}