jhuber6 created this revision. jhuber6 added reviewers: jdoerfert, tra, yaxunl. Herald added subscribers: mattd, carlosgalvezp. Herald added a project: All. jhuber6 requested review of this revision. Herald added subscribers: cfe-commits, MaskRay. Herald added a project: clang.
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. Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D129885 Files: clang/lib/Driver/Driver.cpp clang/test/Driver/cuda-phases.cu Index: clang/test/Driver/cuda-phases.cu =================================================================== --- clang/test/Driver/cuda-phases.cu +++ clang/test/Driver/cuda-phases.cu @@ -266,3 +266,32 @@ // 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: %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: 1: preprocessor, {0}, cuda-cpp-output, (host-cuda) +// NON-CUDA-INPUT: 2: compiler, {1}, ir, (host-cuda) +// NON-CUDA-INPUT: 3: input, "[[CUDA]]", cuda, (device-cuda, sm_52) +// NON-CUDA-INPUT: 4: preprocessor, {3}, cuda-cpp-output, (device-cuda, sm_52) +// NON-CUDA-INPUT: 5: compiler, {4}, ir, (device-cuda, sm_52) +// NON-CUDA-INPUT: 6: backend, {5}, assembler, (device-cuda, sm_52) +// NON-CUDA-INPUT: 7: assembler, {6}, object, (device-cuda, sm_52) +// NON-CUDA-INPUT: 8: offload, "device-cuda (nvptx64-nvidia-cuda:sm_52)" {7}, object +// NON-CUDA-INPUT: 9: input, "[[CUDA]]", cuda, (device-cuda, sm_70) +// NON-CUDA-INPUT: 10: preprocessor, {9}, cuda-cpp-output, (device-cuda, sm_70) +// NON-CUDA-INPUT: 11: compiler, {10}, ir, (device-cuda, sm_70) +// NON-CUDA-INPUT: 12: backend, {11}, assembler, (device-cuda, sm_70) +// NON-CUDA-INPUT: 13: assembler, {12}, object, (device-cuda, sm_70) +// NON-CUDA-INPUT: 14: offload, "device-cuda (nvptx64-nvidia-cuda:sm_70)" {13}, object +// NON-CUDA-INPUT: 15: linker, {8, 14}, cuda-fatbin, (device-cuda) +// NON-CUDA-INPUT: 16: offload, "host-cuda (powerpc64le-ibm-linux-gnu)" {2}, "device-cuda (nvptx64-nvidia-cuda)" {15}, ir +// NON-CUDA-INPUT: 17: backend, {16}, assembler, (host-cuda) +// NON-CUDA-INPUT: 18: assembler, {17}, object, (host-cuda) +// NON-CUDA-INPUT: 19: input, "[[CPP:.+]]", c++, (host-cuda) +// NON-CUDA-INPUT: 20: preprocessor, {19}, c++-cpp-output, (host-cuda) +// NON-CUDA-INPUT: 21: compiler, {20}, ir, (host-cuda) +// NON-CUDA-INPUT: 22: backend, {21}, assembler, (host-cuda) +// NON-CUDA-INPUT: 23: assembler, {22}, object, (host-cuda) +// NON-CUDA-INPUT: 24: clang-linker-wrapper, {18, 23}, image, (host-cuda) + Index: clang/lib/Driver/Driver.cpp =================================================================== --- clang/lib/Driver/Driver.cpp +++ clang/lib/Driver/Driver.cpp @@ -4432,6 +4432,11 @@ 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 @@ 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)) {
Index: clang/test/Driver/cuda-phases.cu =================================================================== --- clang/test/Driver/cuda-phases.cu +++ clang/test/Driver/cuda-phases.cu @@ -266,3 +266,32 @@ // 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: %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: 1: preprocessor, {0}, cuda-cpp-output, (host-cuda) +// NON-CUDA-INPUT: 2: compiler, {1}, ir, (host-cuda) +// NON-CUDA-INPUT: 3: input, "[[CUDA]]", cuda, (device-cuda, sm_52) +// NON-CUDA-INPUT: 4: preprocessor, {3}, cuda-cpp-output, (device-cuda, sm_52) +// NON-CUDA-INPUT: 5: compiler, {4}, ir, (device-cuda, sm_52) +// NON-CUDA-INPUT: 6: backend, {5}, assembler, (device-cuda, sm_52) +// NON-CUDA-INPUT: 7: assembler, {6}, object, (device-cuda, sm_52) +// NON-CUDA-INPUT: 8: offload, "device-cuda (nvptx64-nvidia-cuda:sm_52)" {7}, object +// NON-CUDA-INPUT: 9: input, "[[CUDA]]", cuda, (device-cuda, sm_70) +// NON-CUDA-INPUT: 10: preprocessor, {9}, cuda-cpp-output, (device-cuda, sm_70) +// NON-CUDA-INPUT: 11: compiler, {10}, ir, (device-cuda, sm_70) +// NON-CUDA-INPUT: 12: backend, {11}, assembler, (device-cuda, sm_70) +// NON-CUDA-INPUT: 13: assembler, {12}, object, (device-cuda, sm_70) +// NON-CUDA-INPUT: 14: offload, "device-cuda (nvptx64-nvidia-cuda:sm_70)" {13}, object +// NON-CUDA-INPUT: 15: linker, {8, 14}, cuda-fatbin, (device-cuda) +// NON-CUDA-INPUT: 16: offload, "host-cuda (powerpc64le-ibm-linux-gnu)" {2}, "device-cuda (nvptx64-nvidia-cuda)" {15}, ir +// NON-CUDA-INPUT: 17: backend, {16}, assembler, (host-cuda) +// NON-CUDA-INPUT: 18: assembler, {17}, object, (host-cuda) +// NON-CUDA-INPUT: 19: input, "[[CPP:.+]]", c++, (host-cuda) +// NON-CUDA-INPUT: 20: preprocessor, {19}, c++-cpp-output, (host-cuda) +// NON-CUDA-INPUT: 21: compiler, {20}, ir, (host-cuda) +// NON-CUDA-INPUT: 22: backend, {21}, assembler, (host-cuda) +// NON-CUDA-INPUT: 23: assembler, {22}, object, (host-cuda) +// NON-CUDA-INPUT: 24: clang-linker-wrapper, {18, 23}, image, (host-cuda) + Index: clang/lib/Driver/Driver.cpp =================================================================== --- clang/lib/Driver/Driver.cpp +++ clang/lib/Driver/Driver.cpp @@ -4432,6 +4432,11 @@ 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 @@ 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)) {
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits