diff options
author | Joseph Huber <jhuber6@vols.utk.edu> | 2022-07-15 13:52:27 -0400 |
---|---|---|
committer | Joseph Huber <jhuber6@vols.utk.edu> | 2022-07-15 17:38:34 -0400 |
commit | bb957a8d524cd38d6c5f7d547302258026049438 (patch) | |
tree | 0b5e8998af8eef21fc71075cd78d36fd5a401e1f | |
parent | f32ccc2cca1df39e0f5b5aac0ec30d490104b58c (diff) | |
download | llvm-bb957a8d524cd38d6c5f7d547302258026049438.zip llvm-bb957a8d524cd38d6c5f7d547302258026049438.tar.gz llvm-bb957a8d524cd38d6c5f7d547302258026049438.tar.bz2 |
[CUDA] Make the new driver properly ignore non-CUDA inputs
The new driver generated offloadinga actions for each active toolchain.
However, for CUDA and HIP it is possible for the toolchain to be active
but one of the files is not a valid input. This can occur if the user
compiles both a CUDA and C source file in the same compiler invocation.
This patch adds some simple logic to quit if the input is not valid as
well.
Reviewed By: tra, MaskRay
Differential Revision: https://reviews.llvm.org/D129885
-rw-r--r-- | clang/lib/Driver/Driver.cpp | 8 | ||||
-rw-r--r-- | clang/test/Driver/cuda-phases.cu | 114 |
2 files changed, 79 insertions, 43 deletions
diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp index 3a8400a..bd2b9a5 100644 --- a/clang/lib/Driver/Driver.cpp +++ b/clang/lib/Driver/Driver.cpp @@ -4432,6 +4432,11 @@ Action *Driver::BuildOffloadingActions(Compilation &C, types::ID InputType = Input.first; const Arg *InputArg = Input.second; + // The toolchain can be active for unsupported file types. + if ((Kind == Action::OFK_Cuda && !types::isCuda(InputType)) || + (Kind == Action::OFK_HIP && !types::isHIP(InputType))) + continue; + // Get the product of all bound architectures and toolchains. SmallVector<std::pair<const ToolChain *, StringRef>> TCAndArchs; for (const ToolChain *TC : ToolChains) @@ -4486,6 +4491,9 @@ Action *Driver::BuildOffloadingActions(Compilation &C, if (offloadDeviceOnly()) return C.MakeAction<OffloadAction>(DDeps, types::TY_Nothing); + if (OffloadActions.empty()) + return HostAction; + OffloadAction::DeviceDependences DDep; if (C.isOffloadingHostKind(Action::OFK_Cuda) && !Args.hasFlag(options::OPT_fgpu_rdc, options::OPT_fno_gpu_rdc, false)) { diff --git a/clang/test/Driver/cuda-phases.cu b/clang/test/Driver/cuda-phases.cu index dc469f1..4e0c66a 100644 --- a/clang/test/Driver/cuda-phases.cu +++ b/clang/test/Driver/cuda-phases.cu @@ -221,48 +221,76 @@ // // Test the phases generated when using the new offloading driver. // -// RUN: %clang -### -target powerpc64le-ibm-linux-gnu -ccc-print-phases --offload-new-driver -fgpu-rdc \ -// RUN: --offload-arch=sm_52 --offload-arch=sm_70 %s 2>&1 | FileCheck --check-prefix=NEW-DRIVER-RDC %s -// NEW-DRIVER-RDC: 0: input, "[[INPUT:.+]]", cuda -// NEW-DRIVER-RDC: 1: preprocessor, {0}, cuda-cpp-output -// NEW-DRIVER-RDC: 2: compiler, {1}, ir -// NEW-DRIVER-RDC: 3: input, "[[INPUT]]", cuda, (device-cuda, sm_52) -// NEW-DRIVER-RDC: 4: preprocessor, {3}, cuda-cpp-output, (device-cuda, sm_52) -// NEW-DRIVER-RDC: 5: compiler, {4}, ir, (device-cuda, sm_52) -// NEW-DRIVER-RDC: 6: backend, {5}, assembler, (device-cuda, sm_52) -// NEW-DRIVER-RDC: 7: assembler, {6}, object, (device-cuda, sm_52) -// NEW-DRIVER-RDC: 8: offload, "device-cuda (nvptx64-nvidia-cuda:sm_52)" {7}, object -// NEW-DRIVER-RDC: 9: input, "[[INPUT]]", cuda, (device-cuda, sm_70) -// NEW-DRIVER-RDC: 10: preprocessor, {9}, cuda-cpp-output, (device-cuda, sm_70) -// NEW-DRIVER-RDC: 11: compiler, {10}, ir, (device-cuda, sm_70) -// NEW-DRIVER-RDC: 12: backend, {11}, assembler, (device-cuda, sm_70) -// NEW-DRIVER-RDC: 13: assembler, {12}, object, (device-cuda, sm_70) -// NEW-DRIVER-RDC: 14: offload, "device-cuda (nvptx64-nvidia-cuda:sm_70)" {13}, object -// NEW-DRIVER-RDC: 15: clang-offload-packager, {8, 14}, image -// NEW-DRIVER-RDC: 16: offload, " (powerpc64le-ibm-linux-gnu)" {2}, " (powerpc64le-ibm-linux-gnu)" {15}, ir -// NEW-DRIVER-RDC: 17: backend, {16}, assembler, (host-cuda) -// NEW-DRIVER-RDC: 18: assembler, {17}, object, (host-cuda) -// NEW-DRIVER-RDC: 19: clang-linker-wrapper, {18}, image, (host-cuda) +// RUN: %clang -### --target=powerpc64le-ibm-linux-gnu -ccc-print-phases --offload-new-driver -fgpu-rdc \ +// RUN: --offload-arch=sm_52 --offload-arch=sm_70 %s 2>&1 | FileCheck --check-prefix=NEW-DRIVER-RDC %s +// NEW-DRIVER-RDC: 0: input, "[[INPUT:.+]]", cuda +// NEW-DRIVER-RDC-NEXT: 1: preprocessor, {0}, cuda-cpp-output +// NEW-DRIVER-RDC-NEXT: 2: compiler, {1}, ir +// NEW-DRIVER-RDC-NEXT: 3: input, "[[INPUT]]", cuda, (device-cuda, sm_52) +// NEW-DRIVER-RDC-NEXT: 4: preprocessor, {3}, cuda-cpp-output, (device-cuda, sm_52) +// NEW-DRIVER-RDC-NEXT: 5: compiler, {4}, ir, (device-cuda, sm_52) +// NEW-DRIVER-RDC-NEXT: 6: backend, {5}, assembler, (device-cuda, sm_52) +// NEW-DRIVER-RDC-NEXT: 7: assembler, {6}, object, (device-cuda, sm_52) +// NEW-DRIVER-RDC-NEXT: 8: offload, "device-cuda (nvptx64-nvidia-cuda:sm_52)" {7}, object +// NEW-DRIVER-RDC-NEXT: 9: input, "[[INPUT]]", cuda, (device-cuda, sm_70) +// NEW-DRIVER-RDC-NEXT: 10: preprocessor, {9}, cuda-cpp-output, (device-cuda, sm_70) +// NEW-DRIVER-RDC-NEXT: 11: compiler, {10}, ir, (device-cuda, sm_70) +// NEW-DRIVER-RDC-NEXT: 12: backend, {11}, assembler, (device-cuda, sm_70) +// NEW-DRIVER-RDC-NEXT: 13: assembler, {12}, object, (device-cuda, sm_70) +// NEW-DRIVER-RDC-NEXT: 14: offload, "device-cuda (nvptx64-nvidia-cuda:sm_70)" {13}, object +// NEW-DRIVER-RDC-NEXT: 15: clang-offload-packager, {8, 14}, image +// NEW-DRIVER-RDC-NEXT: 16: offload, " (powerpc64le-ibm-linux-gnu)" {2}, " (powerpc64le-ibm-linux-gnu)" {15}, ir +// NEW-DRIVER-RDC-NEXT: 17: backend, {16}, assembler, (host-cuda) +// NEW-DRIVER-RDC-NEXT: 18: assembler, {17}, object, (host-cuda) +// NEW-DRIVER-RDC-NEXT: 19: clang-linker-wrapper, {18}, image, (host-cuda) // RUN: %clang -### -target powerpc64le-ibm-linux-gnu -ccc-print-phases --offload-new-driver -fgpu-rdc \ -// RUN: --offload-arch=sm_52 --offload-arch=sm_70 %s 2>&1 | FileCheck --check-prefix=NEW-DRIVER %s -// NEW-DRIVER: 0: input, "[[INPUT:.+]]", cuda -// NEW-DRIVER: 1: preprocessor, {0}, cuda-cpp-output -// NEW-DRIVER: 2: compiler, {1}, ir -// NEW-DRIVER: 3: input, "[[INPUT]]", cuda, (device-cuda, sm_52) -// NEW-DRIVER: 4: preprocessor, {3}, cuda-cpp-output, (device-cuda, sm_52) -// NEW-DRIVER: 5: compiler, {4}, ir, (device-cuda, sm_52) -// NEW-DRIVER: 6: backend, {5}, assembler, (device-cuda, sm_52) -// NEW-DRIVER: 7: assembler, {6}, object, (device-cuda, sm_52) -// NEW-DRIVER: 8: offload, "device-cuda (nvptx64-nvidia-cuda:sm_52)" {7}, object -// NEW-DRIVER: 9: input, "[[INPUT]]", cuda, (device-cuda, sm_70) -// NEW-DRIVER: 10: preprocessor, {9}, cuda-cpp-output, (device-cuda, sm_70) -// NEW-DRIVER: 11: compiler, {10}, ir, (device-cuda, sm_70) -// NEW-DRIVER: 12: backend, {11}, assembler, (device-cuda, sm_70) -// NEW-DRIVER: 13: assembler, {12}, object, (device-cuda, sm_70) -// NEW-DRIVER: 14: offload, "device-cuda (nvptx64-nvidia-cuda:sm_70)" {13}, object -// NEW-DRIVER: 15: clang-offload-packager, {8, 14}, image -// NEW-DRIVER: 16: offload, " (powerpc64le-ibm-linux-gnu)" {2}, " (powerpc64le-ibm-linux-gnu)" {15}, ir -// NEW-DRIVER: 17: backend, {16}, assembler, (host-cuda) -// NEW-DRIVER: 18: assembler, {17}, object, (host-cuda) -// NEW-DRIVER: 19: clang-linker-wrapper, {18}, image, (host-cuda) +// RUN: --offload-arch=sm_52 --offload-arch=sm_70 %s 2>&1 | FileCheck --check-prefix=NEW-DRIVER %s +// NEW-DRIVER: 0: input, "[[INPUT:.+]]", cuda +// NEW-DRIVER-NEXT: 1: preprocessor, {0}, cuda-cpp-output +// NEW-DRIVER-NEXT: 2: compiler, {1}, ir +// NEW-DRIVER-NEXT: 3: input, "[[INPUT]]", cuda, (device-cuda, sm_52) +// NEW-DRIVER-NEXT: 4: preprocessor, {3}, cuda-cpp-output, (device-cuda, sm_52) +// NEW-DRIVER-NEXT: 5: compiler, {4}, ir, (device-cuda, sm_52) +// NEW-DRIVER-NEXT: 6: backend, {5}, assembler, (device-cuda, sm_52) +// NEW-DRIVER-NEXT: 7: assembler, {6}, object, (device-cuda, sm_52) +// NEW-DRIVER-NEXT: 8: offload, "device-cuda (nvptx64-nvidia-cuda:sm_52)" {7}, object +// NEW-DRIVER-NEXT: 9: input, "[[INPUT]]", cuda, (device-cuda, sm_70) +// NEW-DRIVER-NEXT: 10: preprocessor, {9}, cuda-cpp-output, (device-cuda, sm_70) +// NEW-DRIVER-NEXT: 11: compiler, {10}, ir, (device-cuda, sm_70) +// NEW-DRIVER-NEXT: 12: backend, {11}, assembler, (device-cuda, sm_70) +// NEW-DRIVER-NEXT: 13: assembler, {12}, object, (device-cuda, sm_70) +// NEW-DRIVER-NEXT: 14: offload, "device-cuda (nvptx64-nvidia-cuda:sm_70)" {13}, object +// NEW-DRIVER-NEXT: 15: clang-offload-packager, {8, 14}, image +// NEW-DRIVER-NEXT: 16: offload, " (powerpc64le-ibm-linux-gnu)" {2}, " (powerpc64le-ibm-linux-gnu)" {15}, ir +// NEW-DRIVER-NEXT: 17: backend, {16}, assembler, (host-cuda) +// NEW-DRIVER-NEXT: 18: assembler, {17}, object, (host-cuda) +// NEW-DRIVER-NEXT: 19: clang-linker-wrapper, {18}, image, (host-cuda) + +// RUN: %clang -### --target=powerpc64le-ibm-linux-gnu -ccc-print-phases --offload-new-driver \ +// RUN: --offload-arch=sm_52 --offload-arch=sm_70 %s %S/Inputs/empty.cpp 2>&1 | FileCheck --check-prefix=NON-CUDA-INPUT %s +// NON-CUDA-INPUT: 0: input, "[[CUDA:.+]]", cuda, (host-cuda) +// NON-CUDA-INPUT-NEXT: 1: preprocessor, {0}, cuda-cpp-output, (host-cuda) +// NON-CUDA-INPUT-NEXT: 2: compiler, {1}, ir, (host-cuda) +// NON-CUDA-INPUT-NEXT: 3: input, "[[CUDA]]", cuda, (device-cuda, sm_52) +// NON-CUDA-INPUT-NEXT: 4: preprocessor, {3}, cuda-cpp-output, (device-cuda, sm_52) +// NON-CUDA-INPUT-NEXT: 5: compiler, {4}, ir, (device-cuda, sm_52) +// NON-CUDA-INPUT-NEXT: 6: backend, {5}, assembler, (device-cuda, sm_52) +// NON-CUDA-INPUT-NEXT: 7: assembler, {6}, object, (device-cuda, sm_52) +// NON-CUDA-INPUT-NEXT: 8: offload, "device-cuda (nvptx64-nvidia-cuda:sm_52)" {7}, object +// NON-CUDA-INPUT-NEXT: 9: input, "[[CUDA]]", cuda, (device-cuda, sm_70) +// NON-CUDA-INPUT-NEXT: 10: preprocessor, {9}, cuda-cpp-output, (device-cuda, sm_70) +// NON-CUDA-INPUT-NEXT: 11: compiler, {10}, ir, (device-cuda, sm_70) +// NON-CUDA-INPUT-NEXT: 12: backend, {11}, assembler, (device-cuda, sm_70) +// NON-CUDA-INPUT-NEXT: 13: assembler, {12}, object, (device-cuda, sm_70) +// NON-CUDA-INPUT-NEXT: 14: offload, "device-cuda (nvptx64-nvidia-cuda:sm_70)" {13}, object +// NON-CUDA-INPUT-NEXT: 15: linker, {8, 14}, cuda-fatbin, (device-cuda) +// NON-CUDA-INPUT-NEXT: 16: offload, "host-cuda (powerpc64le-ibm-linux-gnu)" {2}, "device-cuda (nvptx64-nvidia-cuda)" {15}, ir +// NON-CUDA-INPUT-NEXT: 17: backend, {16}, assembler, (host-cuda) +// NON-CUDA-INPUT-NEXT: 18: assembler, {17}, object, (host-cuda) +// NON-CUDA-INPUT-NEXT: 19: input, "[[CPP:.+]]", c++, (host-cuda) +// NON-CUDA-INPUT-NEXT: 20: preprocessor, {19}, c++-cpp-output, (host-cuda) +// NON-CUDA-INPUT-NEXT: 21: compiler, {20}, ir, (host-cuda) +// NON-CUDA-INPUT-NEXT: 22: backend, {21}, assembler, (host-cuda) +// NON-CUDA-INPUT-NEXT: 23: assembler, {22}, object, (host-cuda) +// NON-CUDA-INPUT-NEXT: 24: clang-linker-wrapper, {18, 23}, image, (host-cuda) |