Skip to content
This repository has been archived by the owner on May 14, 2024. It is now read-only.

Commit

Permalink
Cleanup existing double quote handling
Browse files Browse the repository at this point in the history
  • Loading branch information
kzhuravl committed Jul 20, 2023
1 parent aef7540 commit 1915078
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 14 deletions.
35 changes: 22 additions & 13 deletions bin/hipcc.pl
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ BEGIN

use hipvars;
$isWindows = $hipvars::isWindows;
$doubleQuote = $hipvars::doubleQuote;
$HIP_RUNTIME = $hipvars::HIP_RUNTIME;
$HIP_PLATFORM = $hipvars::HIP_PLATFORM;
$HIP_COMPILER = $hipvars::HIP_COMPILER;
Expand All @@ -131,6 +132,14 @@ BEGIN
$HIP_VERSION = $hipvars::HIP_VERSION;
$HIP_ROCCLR_HOME = $hipvars::HIP_ROCCLR_HOME;

sub get_normalized_path {
if ($isWindows) {
return $doubleQuote . $_[0] . $doubleQuote;
} else {
return $_[0];
}
}

if ($HIP_PLATFORM eq "amd") {
$HIP_INCLUDE_PATH = "$HIP_ROCCLR_HOME/include";
if (!defined $HIP_LIB_PATH) {
Expand All @@ -155,17 +164,17 @@ BEGIN
if($isWindows) {
$execExtension = ".exe";
}
$HIPCC="\"$HIP_CLANG_PATH/clang++" . $execExtension . "\"";
$HIPCC=get_normalized_path("$HIP_CLANG_PATH/clang++" . $execExtension);

# If $HIPCC clang++ is not compiled, use clang instead
if ( ! -e $HIPCC ) {
$HIPCC="\"$HIP_CLANG_PATH/clang" . $execExtension . "\"";
$HIPCC=get_normalized_path("$HIP_CLANG_PATH/clang" . $execExtension);
$HIPLDFLAGS = "--driver-mode=g++";
}
# to avoid using dk linker or MSVC linker
if($isWindows) {
$HIPLDFLAGS .= " -fuse-ld=lld";
$HIPLDFLAGS .= " --ld-path=\"$HIP_CLANG_PATH/lld-link.exe\"";
$HIPLDFLAGS .= " --ld-path=" . get_normalized_path("$HIP_CLANG_PATH/lld-link.exe");
}

# get Clang RT Builtin path
Expand Down Expand Up @@ -201,21 +210,21 @@ BEGIN
print ("CUDA_PATH=$CUDA_PATH\n");
}

$HIPCC="\"$CUDA_PATH/bin/nvcc\"";
$HIPCC=get_normalized_path("$CUDA_PATH/bin/nvcc");
$HIPCXXFLAGS .= " -Wno-deprecated-gpu-targets ";
$HIPCXXFLAGS .= " -isystem \"$CUDA_PATH/include\"";
$HIPCFLAGS .= " -isystem \"$CUDA_PATH/include\"";
$HIPCXXFLAGS .= " -isystem " . get_normalized_path("$CUDA_PATH/include");
$HIPCFLAGS .= " -isystem " . get_normalized_path("$CUDA_PATH/include");

$HIPLDFLAGS = " -Wno-deprecated-gpu-targets -lcuda -lcudart -L\"$CUDA_PATH/lib64\"";
$HIPLDFLAGS = " -Wno-deprecated-gpu-targets -lcuda -lcudart -L" . get_normalized_path("$CUDA_PATH/lib64");
} else {
printf ("error: unknown HIP_PLATFORM = '$HIP_PLATFORM'");
printf (" or HIP_COMPILER = '$HIP_COMPILER'");
exit (-1);
}

# Add paths to common HIP includes:
$HIPCXXFLAGS .= " -isystem \"$HIP_INCLUDE_PATH\"" ;
$HIPCFLAGS .= " -isystem \"$HIP_INCLUDE_PATH\"" ;
$HIPCXXFLAGS .= " -isystem " . get_normalized_path("$HIP_INCLUDE_PATH");
$HIPCFLAGS .= " -isystem " . get_normalized_path("$HIP_INCLUDE_PATH");

my $compileOnly = 0;
my $needCXXFLAGS = 0; # need to add CXX flags to compile step
Expand Down Expand Up @@ -294,7 +303,7 @@ BEGIN

if ($skipOutputFile) {
# TODO: handle filename with shell metacharacters
$toolArgs .= " \"$arg\"";
$toolArgs .= " " . get_normalized_path("$arg");
$prevArg = $arg;
$skipOutputFile = 0;
next;
Expand Down Expand Up @@ -466,7 +475,7 @@ BEGIN
if (not $isWindows and $escapeArg) {
$arg =~ s/[^-a-zA-Z0-9_=+,.\/]/\\$&/g;
}
$toolArgs .= " \"$arg\"" unless $swallowArg;
$toolArgs .= " " . get_normalized_path("$arg") unless $swallowArg;
$prevArg = $arg;
}

Expand Down Expand Up @@ -561,14 +570,14 @@ BEGIN

# If the HIP_PATH env var is defined, pass that path to Clang
if ($ENV{'HIP_PATH'}) {
my $hip_path_flag = " --hip-path=\"$HIP_PATH\"";
my $hip_path_flag = " --hip-path=" . get_normalized_path("$HIP_PATH");
$HIPCXXFLAGS .= $hip_path_flag;
$HIPLDFLAGS .= $hip_path_flag;
}

if ($hasHIP) {
if (defined $DEVICE_LIB_PATH) {
$HIPCXXFLAGS .= " --hip-device-lib-path=\"$DEVICE_LIB_PATH\"";
$HIPCXXFLAGS .= " --hip-device-lib-path=" . get_normalized_path("$DEVICE_LIB_PATH");
}
}

Expand Down
6 changes: 5 additions & 1 deletion bin/hipvars.pm
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ sub can_run {
}

$isWindows = ($^O eq 'MSWin32' or $^O eq 'msys');
$doubleQuote = "";
if ($isWindows) {
$doubleQuote = "\"";
}

#
# TODO: Fix rpath LDFLAGS settings
Expand Down Expand Up @@ -124,7 +128,7 @@ if (defined $HIP_RUNTIME and $HIP_RUNTIME eq "rocclr" and !defined $HIP_ROCCLR_H
}

if (not defined $HIP_PLATFORM) {
if (can_run("\"$HIP_CLANG_PATH/clang++\"") or can_run("clang++")) {
if (can_run($doubleQuote . "$HIP_CLANG_PATH/clang++" . $doubleQuote) or can_run("clang++")) {
$HIP_PLATFORM = "amd";
} elsif (can_run("$CUDA_PATH/bin/nvcc") or can_run("nvcc")) {
$HIP_PLATFORM = "nvidia";
Expand Down

0 comments on commit 1915078

Please sign in to comment.