@@ -738,9 +738,22 @@ NVPTXToolChain::TranslateArgs(const llvm::opt::DerivedArgList &Args,
738
738
if (!llvm::is_contained (*DAL, A))
739
739
DAL->append (A);
740
740
741
- if (!DAL->hasArg (options::OPT_march_EQ))
741
+ if (!DAL->hasArg (options::OPT_march_EQ)) {
742
742
DAL->AddJoinedArg (nullptr , Opts.getOption (options::OPT_march_EQ),
743
743
CudaArchToString (CudaArch::CudaDefault));
744
+ } else if (DAL->getLastArgValue (options::OPT_march_EQ) == " native" ) {
745
+ auto GPUsOrErr = getSystemGPUArchs (Args);
746
+ if (!GPUsOrErr) {
747
+ getDriver ().Diag (diag::err_drv_undetermined_gpu_arch)
748
+ << getArchName () << llvm::toString (GPUsOrErr.takeError ()) << " -march" ;
749
+ } else {
750
+ if (GPUsOrErr->size () > 1 )
751
+ getDriver ().Diag (diag::warn_drv_multi_gpu_arch)
752
+ << getArchName () << llvm::join (*GPUsOrErr, " , " ) << " -march" ;
753
+ DAL->AddJoinedArg (nullptr , Opts.getOption (options::OPT_march_EQ),
754
+ Args.MakeArgString (GPUsOrErr->front ()));
755
+ }
756
+ }
744
757
745
758
return DAL;
746
759
}
@@ -783,6 +796,31 @@ void NVPTXToolChain::adjustDebugInfoKind(
783
796
}
784
797
}
785
798
799
+ Expected<SmallVector<std::string>>
800
+ NVPTXToolChain::getSystemGPUArchs (const ArgList &Args) const {
801
+ // Detect NVIDIA GPUs availible on the system.
802
+ std::string Program;
803
+ if (Arg *A = Args.getLastArg (options::OPT_nvptx_arch_tool_EQ))
804
+ Program = A->getValue ();
805
+ else
806
+ Program = GetProgramPath (" nvptx-arch" );
807
+
808
+ auto StdoutOrErr = executeToolChainProgram (Program);
809
+ if (!StdoutOrErr)
810
+ return StdoutOrErr.takeError ();
811
+
812
+ SmallVector<std::string, 1 > GPUArchs;
813
+ for (StringRef Arch : llvm::split ((*StdoutOrErr)->getBuffer (), " \n " ))
814
+ if (!Arch.empty ())
815
+ GPUArchs.push_back (Arch.str ());
816
+
817
+ if (GPUArchs.empty ())
818
+ return llvm::createStringError (std::error_code (),
819
+ " No NVIDIA GPU detected in the system" );
820
+
821
+ return std::move (GPUArchs);
822
+ }
823
+
786
824
// / CUDA toolchain. Our assembler is ptxas, and our "linker" is fatbinary,
787
825
// / which isn't properly a linker but nonetheless performs the step of stitching
788
826
// / together object files from the assembler into a single blob.
@@ -948,31 +986,6 @@ CudaToolChain::TranslateArgs(const llvm::opt::DerivedArgList &Args,
948
986
return DAL;
949
987
}
950
988
951
- Expected<SmallVector<std::string>>
952
- CudaToolChain::getSystemGPUArchs (const ArgList &Args) const {
953
- // Detect NVIDIA GPUs availible on the system.
954
- std::string Program;
955
- if (Arg *A = Args.getLastArg (options::OPT_nvptx_arch_tool_EQ))
956
- Program = A->getValue ();
957
- else
958
- Program = GetProgramPath (" nvptx-arch" );
959
-
960
- auto StdoutOrErr = executeToolChainProgram (Program);
961
- if (!StdoutOrErr)
962
- return StdoutOrErr.takeError ();
963
-
964
- SmallVector<std::string, 1 > GPUArchs;
965
- for (StringRef Arch : llvm::split ((*StdoutOrErr)->getBuffer (), " \n " ))
966
- if (!Arch.empty ())
967
- GPUArchs.push_back (Arch.str ());
968
-
969
- if (GPUArchs.empty ())
970
- return llvm::createStringError (std::error_code (),
971
- " No NVIDIA GPU detected in the system" );
972
-
973
- return std::move (GPUArchs);
974
- }
975
-
976
989
Tool *NVPTXToolChain::buildAssembler () const {
977
990
return new tools::NVPTX::Assembler (*this );
978
991
}
0 commit comments