diff options
author | Artem Belevich <tra@google.com> | 2016-08-02 22:37:47 +0000 |
---|---|---|
committer | Artem Belevich <tra@google.com> | 2016-08-02 22:37:47 +0000 |
commit | f981e30b45a88dda761100909940167648db42e6 (patch) | |
tree | ce3e52bf7584d7c143356dde0f2bb4c894f94b9b | |
parent | 707894b09270dc072f734d2a28567db58bc36b34 (diff) | |
download | bcm5719-llvm-f981e30b45a88dda761100909940167648db42e6.tar.gz bcm5719-llvm-f981e30b45a88dda761100909940167648db42e6.zip |
[CUDA] Do not allow using NVPTX target for host compilation.
Differential Revision: https://reviews.llvm.org/D23042
llvm-svn: 277537
-rw-r--r-- | clang/include/clang/Basic/DiagnosticDriverKinds.td | 1 | ||||
-rw-r--r-- | clang/lib/Driver/Driver.cpp | 19 | ||||
-rw-r--r-- | clang/test/Driver/cuda-bad-arch.cu | 5 | ||||
-rw-r--r-- | clang/test/Preprocessor/cuda-types.cu | 6 | ||||
-rw-r--r-- | clang/unittests/ASTMatchers/ASTMatchersTest.h | 2 |
5 files changed, 20 insertions, 13 deletions
diff --git a/clang/include/clang/Basic/DiagnosticDriverKinds.td b/clang/include/clang/Basic/DiagnosticDriverKinds.td index 6b8db6963da..09c7af678d9 100644 --- a/clang/include/clang/Basic/DiagnosticDriverKinds.td +++ b/clang/include/clang/Basic/DiagnosticDriverKinds.td @@ -30,6 +30,7 @@ def err_drv_cuda_version_too_low : Error< "GPU arch %1 requires CUDA version at least %3, but installation at %0 is %2. " "Use --cuda-path to specify a different CUDA install, or pass " "--no-cuda-version-check.">; +def err_drv_cuda_nvptx_host : Error<"unsupported use of NVPTX for host compilation.">; def err_drv_invalid_thread_model_for_target : Error< "invalid thread model '%0' in '%1' for this target">; def err_drv_invalid_linker_name : Error< diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp index 43ec2164a48..db7825adc58 100644 --- a/clang/lib/Driver/Driver.cpp +++ b/clang/lib/Driver/Driver.cpp @@ -1407,11 +1407,19 @@ static Action *buildCudaActions(Compilation &C, DerivedArgList &Args, bool CompileDeviceOnly = PartialCompilationArg && PartialCompilationArg->getOption().matches(options::OPT_cuda_device_only); + const ToolChain *HostTC = C.getSingleOffloadToolChain<Action::OFK_Host>(); + assert(HostTC && "No toolchain for host compilation."); + if (HostTC->getTriple().isNVPTX()) { + // We do not support targeting NVPTX for host compilation. Throw + // an error and abort pipeline construction early so we don't trip + // asserts that assume device-side compilation. + C.getDriver().Diag(diag::err_drv_cuda_nvptx_host); + return nullptr; + } if (CompileHostOnly) { - OffloadAction::HostDependence HDep( - *HostAction, *C.getSingleOffloadToolChain<Action::OFK_Host>(), - /*BoundArch=*/nullptr, Action::OFK_Cuda); + OffloadAction::HostDependence HDep(*HostAction, *HostTC, + /*BoundArch=*/nullptr, Action::OFK_Cuda); return C.MakeAction<OffloadAction>(HDep); } @@ -1507,9 +1515,8 @@ static Action *buildCudaActions(Compilation &C, DerivedArgList &Args, // Return a new host action that incorporates original host action and all // device actions. - OffloadAction::HostDependence HDep( - *HostAction, *C.getSingleOffloadToolChain<Action::OFK_Host>(), - /*BoundArch=*/nullptr, Action::OFK_Cuda); + OffloadAction::HostDependence HDep(*HostAction, *HostTC, + /*BoundArch=*/nullptr, Action::OFK_Cuda); OffloadAction::DeviceDependences DDep; DDep.add(*FatbinAction, *CudaTC, /*BoundArch=*/nullptr, Action::OFK_Cuda); return C.MakeAction<OffloadAction>(HDep, DDep); diff --git a/clang/test/Driver/cuda-bad-arch.cu b/clang/test/Driver/cuda-bad-arch.cu index f92bdcebd0d..cbc2d11f90e 100644 --- a/clang/test/Driver/cuda-bad-arch.cu +++ b/clang/test/Driver/cuda-bad-arch.cu @@ -19,4 +19,9 @@ // RUN: %clang -### -target x86_64-linux-gnu -c %s 2>&1 \ // RUN: | FileCheck -check-prefix OK %s +// We don't allow using NVPTX for host compilation. +// RUN: %clang -### --cuda-host-only -target nvptx-nvidia-cuda -c %s 2>&1 \ +// RUN: | FileCheck -check-prefix HOST_NVPTX %s + // OK-NOT: error: Unsupported CUDA gpu architecture +// HOST_NVPTX: error: unsupported use of NVPTX for host compilation. diff --git a/clang/test/Preprocessor/cuda-types.cu b/clang/test/Preprocessor/cuda-types.cu index dd8eef4aaef..26b4995d037 100644 --- a/clang/test/Preprocessor/cuda-types.cu +++ b/clang/test/Preprocessor/cuda-types.cu @@ -19,9 +19,3 @@ // RUN: grep 'define __[^ ]*\(TYPE\|MAX\|SIZEOF\|WIDTH\)' %T/powerpc64-host-defines | grep -v '__LDBL\|_LONG_DOUBLE' > %T/powerpc64-host-defines-filtered // RUN: grep 'define __[^ ]*\(TYPE\|MAX\|SIZEOF\|WIDTH\)' %T/powerpc64-device-defines | grep -v '__LDBL\|_LONG_DOUBLE' > %T/powerpc64-device-defines-filtered // RUN: diff %T/powerpc64-host-defines-filtered %T/powerpc64-device-defines-filtered - -// RUN: %clang --cuda-host-only -nocudainc -target nvptx-nvidia-cuda -x cuda -E -dM -o - /dev/null > %T/nvptx-host-defines -// RUN: %clang --cuda-device-only -nocudainc -target nvptx-nvidia-cuda -x cuda -E -dM -o - /dev/null > %T/nvptx-device-defines -// RUN: grep 'define __[^ ]*\(TYPE\|MAX\|SIZEOF\|WIDTH\)' %T/nvptx-host-defines | grep -v '__LDBL\|_LONG_DOUBLE' > %T/nvptx-host-defines-filtered -// RUN: grep 'define __[^ ]*\(TYPE\|MAX\|SIZEOF\|WIDTH\)' %T/nvptx-device-defines | grep -v '__LDBL\|_LONG_DOUBLE' > %T/nvptx-device-defines-filtered -// RUN: diff %T/nvptx-host-defines-filtered %T/nvptx-device-defines-filtered diff --git a/clang/unittests/ASTMatchers/ASTMatchersTest.h b/clang/unittests/ASTMatchers/ASTMatchersTest.h index 4b3387c0ba7..fdb273c672d 100644 --- a/clang/unittests/ASTMatchers/ASTMatchersTest.h +++ b/clang/unittests/ASTMatchers/ASTMatchersTest.h @@ -189,7 +189,7 @@ testing::AssertionResult matchesConditionallyWithCuda( // avoid constructing a full system triple. std::vector<std::string> Args = { "-xcuda", "-fno-ms-extensions", "--cuda-host-only", "-nocudainc", - "-target", "nvptx64-unknown-unknown", CompileArg}; + "-target", "x86_64-unknown-unknown", CompileArg}; if (!runToolOnCodeWithArgs(Factory->create(), CudaHeader + Code, Args)) { return testing::AssertionFailure() << "Parsing error in \"" << Code << "\""; |