From cd95e22afe4e9e52714c65134976711a2cb0a668 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 --- bin/hipcc.pl | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/bin/hipcc.pl b/bin/hipcc.pl index 56dcda2..14e725f 100755 --- a/bin/hipcc.pl +++ b/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 2b81cd84c848ff94e8eed790a26237c131bc24e4 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 --- bin/hipcc.pl | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/bin/hipcc.pl b/bin/hipcc.pl index 14e725f..90e2333 100755 --- a/bin/hipcc.pl +++ b/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 2705c38bbe6760674218ee58e82946c530c46d86 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 --- bin/hipvars.pm | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/bin/hipvars.pm b/bin/hipvars.pm index 0bf8c69..3466112 100644 --- a/bin/hipvars.pm +++ b/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 878fd2addd9c167b9bb46f58113901d759590752 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 --- bin/hipvars.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/hipvars.pm b/bin/hipvars.pm index 3466112..6410a75 100644 --- a/bin/hipvars.pm +++ b/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 ee309ae102eafcd0a47eb020cf716d57310e2833 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 --- bin/hipvars.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/hipvars.pm b/bin/hipvars.pm index 6410a75..0d5abf0 100644 --- a/bin/hipvars.pm +++ b/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 3d2264902ade0a2dfceded17f5ec11f3a3aff88f 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 --- bin/hipvars.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/hipvars.pm b/bin/hipvars.pm index 0d5abf0..c4b37d5 100644 --- a/bin/hipvars.pm +++ b/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";