diff --git a/projects/hip/bin/hipcc b/projects/hip/bin/hipcc index 80d28a7b8e..38be6fb5ef 100755 --- a/projects/hip/bin/hipcc +++ b/projects/hip/bin/hipcc @@ -134,6 +134,7 @@ if (defined $HIP_RUNTIME and $HIP_RUNTIME eq "VDI" and !defined $HIP_VDI_HOME) { $HIP_VDI_HOME = $HIP_PATH; # use HIP_PATH } $HIPCXXFLAGS .= "-D__HIP_VDI__"; + $HIPCFLAGS .= "-D__HIP_VDI__"; } if (defined $HIP_VDI_HOME) { @@ -208,6 +209,7 @@ if ($HIP_PLATFORM eq "clang") { $HIPCXXFLAGS .= " -std=c++11"; } $HIPCXXFLAGS .= " -isystem $HIP_CLANG_INCLUDE_PATH/.."; + $HIPCFLAGS .= " -isystem $HIP_CLANG_INCLUDE_PATH/.."; $HIPLDFLAGS .= " -L$HIP_LIB_PATH"; if (not $isWindows) { $HIPLDFLAGS .= " -Wl,--rpath-link=$HIP_LIB_PATH"; @@ -223,6 +225,7 @@ if ($HIP_PLATFORM eq "clang") { if ($HIP_RUNTIME eq "HCC" ) { $HSA_PATH=$ENV{'HSA_PATH'} // "$ROCM_PATH/hsa"; $HIPCXXFLAGS .= " -isystem $HSA_PATH/include"; + $HIPCFLAGS .= " -isystem $HSA_PATH/include"; } else { $HIPCXXFLAGS .= " -fhip-new-launch-api"; } @@ -280,8 +283,11 @@ if ($HIP_PLATFORM eq "clang") { } $HIPCXXFLAGS .= " -isystem $HIP_PATH/include/hip/hcc_detail/cuda"; + $HIPCFLAGS .= " -isystem $HIP_PATH/include/hip/hcc_detail/cuda"; $HIPCXXFLAGS .= " -isystem $HSA_PATH/include"; + $HIPCFLAGS .= " -isystem $HSA_PATH/include"; $HIPCXXFLAGS .= " -Wno-deprecated-register"; + $HIPCFLAGS .= " -Wno-deprecated-register"; $HIPLDFLAGS .= " -L$HSA_PATH/lib -L$ROCM_PATH/lib -lhsa-runtime64 -lhc_am "; # $HIPLDFLAGS .= " -L$HCC_HOME/compiler/lib -lLLVMAMDGPUDesc -lLLVMAMDGPUUtils -lLLVMMC -lLLVMCore -lLLVMSupport "; @@ -305,6 +311,7 @@ if ($HIP_PLATFORM eq "clang") { $HIPCC="$CUDA_PATH/bin/nvcc"; $HIPCXXFLAGS .= " -Wno-deprecated-gpu-targets "; $HIPCXXFLAGS .= " -isystem $CUDA_PATH/include"; + $HIPCFLAGS .= " -isystem $CUDA_PATH/include"; $HIPLDFLAGS = " -Wno-deprecated-gpu-targets -lcuda -lcudart -L$CUDA_PATH/lib64"; } else { @@ -314,11 +321,14 @@ if ($HIP_PLATFORM eq "clang") { # Add paths to common HIP includes: $HIPCXXFLAGS .= " -isystem $HIP_INCLUDE_PATH" ; +$HIPCFLAGS .= " -isystem $HIP_INCLUDE_PATH" ; my $compileOnly = 0; my $needCXXFLAGS = 0; # need to add CXX flags to compile step +my $needCFLAGS = 0; # need to add C flags to compile step my $needLDFLAGS = 1; # need to add LDFLAGS to compile step. -my $hasC = 0; # options contain a c-style file (NVCC must force recognition as GPU file) +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 $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 $printHipVersion = 0; # print HIP version @@ -384,7 +394,6 @@ foreach $arg (@ARGV) my $swallowArg = 0; if ($arg eq '-c' or $arg eq '--genco') { $compileOnly = 1; - $needCXXFLAGS = 1; $needLDFLAGS = 0; } @@ -447,6 +456,7 @@ foreach $arg (@ARGV) } if($trimarg eq '-use_fast_math') { $HIPCXXFLAGS .= " -DHIP_FAST_MATH "; + $HIPCFLAGS .= " -DHIP_FAST_MATH "; } if(($trimarg eq '-use-staticlib') and ($setLinkType eq 0)) { @@ -596,14 +606,19 @@ foreach $arg (@ARGV) #print "O: <$arg>\n"; } else { # input files and libraries - if (($arg =~ /\.cpp$/) or ($arg =~ /\.cxx$/) or ($arg =~ /\.c$/) or ($arg =~ /\.cc$/) ) { + if ($arg =~ /\.c$/) { $hasC = 1; + $needCFLAGS = 1; + $toolArgs .= " -x c" + } + elsif (($arg =~ /\.cpp$/) or ($arg =~ /\.cxx$/) or ($arg =~ /\.cc$/) ) { + $hasCXX = 1; $needCXXFLAGS = 1; - if ($HIP_PLATFORM eq 'clang') { + if ($HIP_PLATFORM eq 'clang' and not $arg =~ /\.c$/) { $toolArgs .= " -x hip" } } - if (($arg =~ /\.cu$/) or ($arg =~ /\.cuh$/) or ($arg =~ /\.hip$/)) { + elsif (($arg =~ /\.cu$/) or ($arg =~ /\.cuh$/) or ($arg =~ /\.hip$/)) { $hasCU = 1; $needCXXFLAGS = 1; if ($HIP_PLATFORM eq 'clang') { @@ -648,7 +663,7 @@ if($HIP_PLATFORM eq "hcc" or $HIP_PLATFORM eq "clang"){ my $archMacro = ' -D__HIP_ARCH_' . uc($val) . '__=1 '; # Add the arch option and macro to the compiler options. $GPU_ARCH_ARG = $GPU_ARCH_OPT . $val; - $HIPLDFLAGS .= $GPU_ARCH_ARG; + $HIPLDARCHFLAGS .= $GPU_ARCH_ARG; $HIPCXXFLAGS .= $archMacro; if ($HIP_PLATFORM eq 'clang') { $HIPCXXFLAGS .= $GPU_ARCH_ARG; @@ -676,7 +691,7 @@ if ($coFormatv3 and $HIP_PLATFORM eq 'hcc') { $HIPCXXFLAGS .= " -mcode-object-v3"; } -if ($hasC and $HIP_PLATFORM eq 'nvcc') { +if ($hasCXX and $HIP_PLATFORM eq 'nvcc') { $HIPCXXFLAGS .= " -x cu"; } if ($hasCU and $HIP_PLATFORM eq 'hcc') { @@ -685,6 +700,7 @@ if ($hasCU and $HIP_PLATFORM eq 'hcc') { if ($buildDeps and $HIP_PLATFORM eq 'nvcc') { $HIPCXXFLAGS .= " -M -D__CUDACC__"; + $HIPCFLAGS .= " -M -D__CUDACC__"; } if ($buildDeps and $HIP_PLATFORM eq 'clang') { @@ -692,10 +708,14 @@ if ($buildDeps and $HIP_PLATFORM eq 'clang') { } # Add --hip-link only if there are no source files. -if (!$needCXXFLAGS and $HIP_PLATFORM eq 'clang') { +if (!$needCXXFLAGS and !$needCFLAGS and $HIP_PLATFORM eq 'clang') { $HIPLDFLAGS .= " --hip-link"; } +if (!$needCFLAGS and $HIP_PLATFORM eq 'clang') { + $HIPLDFLAGS .= $HIPLDARCHFLAGS; +} + if ($setStdLib eq 0 and $HIP_PLATFORM eq 'hcc') { $HIPCXXFLAGS .= $HCC_WA_FLAGS; @@ -718,6 +738,7 @@ if ($HIP_PLATFORM eq "clang") { # Set default optimization level to -O3 for hip-clang. if ($optArg eq "") { $HIPCXXFLAGS .= " -O3"; + $HIPCFLAGS .= " -O3"; $HIPLDFLAGS .= " -O3"; } # Do not pass -mllvm on Windows since there is a clang bug causing duplicate -mllvm options in clang -cc1 on Windows. @@ -738,6 +759,7 @@ if ($HIP_PLATFORM eq "clang") { if ($HIPCC_COMPILE_FLAGS_APPEND) { $HIPCXXFLAGS .= " $HIPCC_COMPILE_FLAGS_APPEND"; + $HIPCFLAGS .= " $HIPCC_COMPILE_FLAGS_APPEND"; } if ($HIPCC_LINK_FLAGS_APPEND) { $HIPLDFLAGS .= " $HIPCC_LINK_FLAGS_APPEND"; @@ -747,6 +769,9 @@ my $CMD="$HIPCC"; if ($needLDFLAGS and not $compileOnly) { $CMD .= " $HIPLDFLAGS"; } +if ($needCFLAGS) { + $CMD .= " $HIPCFLAGS"; +} if ($needCXXFLAGS) { $CMD .= " $HIPCXXFLAGS"; }