From 09fb75d8315b219005dff0ee841ef513581c19d8 Mon Sep 17 00:00:00 2001 From: Konstantin Zhuravlyov Date: Thu, 6 Jul 2023 15:14:02 -0400 Subject: [PATCH 1/6] SWDEV-409068 - Fix paths with spaces in it --- amd/hipcc/bin/hipcc.pl | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/amd/hipcc/bin/hipcc.pl b/amd/hipcc/bin/hipcc.pl index 56dcda2d59870b..14e725fe8ab5d1 100755 --- a/amd/hipcc/bin/hipcc.pl +++ b/amd/hipcc/bin/hipcc.pl @@ -155,20 +155,17 @@ BEGIN if($isWindows) { $execExtension = ".exe"; } - $HIPCC="$HIP_CLANG_PATH/clang++" . $execExtension; + $HIPCC="\"$HIP_CLANG_PATH/clang++" . $execExtension . "\""; # If $HIPCC clang++ is not compiled, use clang instead if ( ! -e $HIPCC ) { - $HIPCC="$HIP_CLANG_PATH/clang" . $execExtension; + $HIPCC="\"$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"; - - # escape possible spaces in path name - $HIPCC =~ s/\s/\\$&/g; + $HIPLDFLAGS .= " --ld-path=\"$HIP_CLANG_PATH/lld-link.exe\""; } # get Clang RT Builtin path @@ -204,12 +201,12 @@ BEGIN print ("CUDA_PATH=$CUDA_PATH\n"); } - $HIPCC="$CUDA_PATH/bin/nvcc"; + $HIPCC="\"$CUDA_PATH/bin/nvcc\""; $HIPCXXFLAGS .= " -Wno-deprecated-gpu-targets "; - $HIPCXXFLAGS .= " -isystem $CUDA_PATH/include"; - $HIPCFLAGS .= " -isystem $CUDA_PATH/include"; + $HIPCXXFLAGS .= " -isystem \"$CUDA_PATH/include\""; + $HIPCFLAGS .= " -isystem \"$CUDA_PATH/include\""; - $HIPLDFLAGS = " -Wno-deprecated-gpu-targets -lcuda -lcudart -L$CUDA_PATH/lib64"; + $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'"); From c51685e67e0d6735bda99790ea276c9e723a1942 Mon Sep 17 00:00:00 2001 From: Konstantin Zhuravlyov Date: Thu, 6 Jul 2023 21:09:37 -0400 Subject: [PATCH 2/6] SWDEV-409068 - Also fix input args --- amd/hipcc/bin/hipcc.pl | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/amd/hipcc/bin/hipcc.pl b/amd/hipcc/bin/hipcc.pl index 14e725fe8ab5d1..90e23339d21e11 100755 --- a/amd/hipcc/bin/hipcc.pl +++ b/amd/hipcc/bin/hipcc.pl @@ -466,10 +466,7 @@ BEGIN if (not $isWindows and $escapeArg) { $arg =~ s/[^-a-zA-Z0-9_=+,.\/]/\\$&/g; } - if ($isWindows and $escapeArg) { - $arg =~ s/[^-a-zA-Z0-9_=+,.:\/\\]/\\$&/g; - } - $toolArgs .= " $arg" unless $swallowArg; + $toolArgs .= " \"$arg\"" unless $swallowArg; $prevArg = $arg; } From 65c6ffbc4600540c572a688315476402ac853ba1 Mon Sep 17 00:00:00 2001 From: Konstantin Zhuravlyov Date: Fri, 7 Jul 2023 17:07:52 -0400 Subject: [PATCH 3/6] SWDEV-409068 - Also fix HIP_PATH --- amd/hipcc/bin/hipvars.pm | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/amd/hipcc/bin/hipvars.pm b/amd/hipcc/bin/hipvars.pm index 0bf8c6927b06b1..34661123ad62b1 100644 --- a/amd/hipcc/bin/hipvars.pm +++ b/amd/hipcc/bin/hipvars.pm @@ -74,6 +74,10 @@ $isWindows = ($^O eq 'MSWin32' or $^O eq 'msys'); # 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 (defined $ENV{'HIP_PATH'}) { + ($HIP_PATH) = $HIP_PATH =~ /"([^"]*)"/; + $HIP_PATH =~ s/\\/\//g; +} if (-e "$HIP_PATH/bin/rocm_agent_enumerator") { $ROCM_PATH=$ENV{'ROCM_PATH'} // "$HIP_PATH"; # use HIP_PATH }elsif (-e "$HIP_PATH/../bin/rocm_agent_enumerator") { # case for backward compatibility @@ -84,7 +88,7 @@ if (-e "$HIP_PATH/bin/rocm_agent_enumerator") { $CUDA_PATH=$ENV{'CUDA_PATH'} // '/usr/local/cuda'; # Windows/Distro's have a different structure, all binaries are with hipcc -if (-e "$HIP_PATH/bin/clang" or -e "$HIP_PATH/bin/clang.exe") { +if ($isWindows or -e "$HIP_PATH/bin/clang") { $HIP_CLANG_PATH=$ENV{'HIP_CLANG_PATH'} // "$HIP_PATH/bin"; } else { $HIP_CLANG_PATH=$ENV{'HIP_CLANG_PATH'} // "$ROCM_PATH/llvm/bin"; From bcfc327691a77003d1c52d336cd5bdf1373805ef Mon Sep 17 00:00:00 2001 From: Konstantin Zhuravlyov Date: Fri, 7 Jul 2023 17:27:49 -0400 Subject: [PATCH 4/6] SWDEV-409068 - Restrict paths manipulations to windows --- amd/hipcc/bin/hipvars.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/amd/hipcc/bin/hipvars.pm b/amd/hipcc/bin/hipvars.pm index 34661123ad62b1..6410a754cffa3e 100644 --- a/amd/hipcc/bin/hipvars.pm +++ b/amd/hipcc/bin/hipvars.pm @@ -74,7 +74,7 @@ $isWindows = ($^O eq 'MSWin32' or $^O eq 'msys'); # 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 (defined $ENV{'HIP_PATH'}) { +if ($isWindows and defined $ENV{'HIP_PATH'}) { ($HIP_PATH) = $HIP_PATH =~ /"([^"]*)"/; $HIP_PATH =~ s/\\/\//g; } From 7ef705f22278cfaf58b8e7930ac4e894308a77e2 Mon Sep 17 00:00:00 2001 From: Konstantin Zhuravlyov Date: Mon, 10 Jul 2023 15:15:16 -0400 Subject: [PATCH 5/6] SWDEV-409068 - Fix " substition --- amd/hipcc/bin/hipvars.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/amd/hipcc/bin/hipvars.pm b/amd/hipcc/bin/hipvars.pm index 6410a754cffa3e..0d5abf0016be36 100644 --- a/amd/hipcc/bin/hipvars.pm +++ b/amd/hipcc/bin/hipvars.pm @@ -75,7 +75,7 @@ $isWindows = ($^O eq 'MSWin32' or $^O eq 'msys'); # $HIP_PATH=$ENV{'HIP_PATH'} // dirname(Cwd::abs_path("$0/../")); # use parent directory of hipcc if ($isWindows and defined $ENV{'HIP_PATH'}) { - ($HIP_PATH) = $HIP_PATH =~ /"([^"]*)"/; + $HIP_PATH =~ s/^"(.*)"$/$1/; $HIP_PATH =~ s/\\/\//g; } if (-e "$HIP_PATH/bin/rocm_agent_enumerator") { From ea296b35f462fdd6dd25a8ad2c12cebd08410f51 Mon Sep 17 00:00:00 2001 From: Konstantin Zhuravlyov Date: Tue, 11 Jul 2023 11:35:44 -0400 Subject: [PATCH 6/6] SWDEV-409068 - Fix can_run arg --- amd/hipcc/bin/hipvars.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/amd/hipcc/bin/hipvars.pm b/amd/hipcc/bin/hipvars.pm index 0d5abf0016be36..c4b37d5ad877fc 100644 --- a/amd/hipcc/bin/hipvars.pm +++ b/amd/hipcc/bin/hipvars.pm @@ -124,7 +124,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("\"$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";