Author: Joseph Huber Date: 2022-08-24T08:47:55-05:00 New Revision: ba57828e11c52f45420f2027dae0843cf83a57bf
URL: https://github.com/llvm/llvm-project/commit/ba57828e11c52f45420f2027dae0843cf83a57bf DIFF: https://github.com/llvm/llvm-project/commit/ba57828e11c52f45420f2027dae0843cf83a57bf.diff LOG: [CUDA][OpenMP] Fix the new driver crashing on multiple device-only outputs The new driver supports device-only compilation for the offloading device. The way this is handlded is a little different from the old offloading driver. The old driver would put all the outputs in the final action list akin to a linker job. The new driver however generated these in the middle of the host's job so we instead put them all in a single offloading action. However, we only handled these kinds of offloading actions correctly when there was only a single input. When we had multiple inputs we would instead attempt to get the host job, which didn't exist, and crash. This patch simply adds some extra logic to generate the jobs for all dependencies if there is not host action. Reviewed By: yaxunl Differential Revision: https://reviews.llvm.org/D132248 Added: Modified: clang/lib/Driver/Driver.cpp clang/test/Driver/cuda-bindings.cu clang/test/Driver/hip-binding.hip Removed: ################################################################################ diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp index d00f08d15ae5..f5b0cb85788b 100644 --- a/clang/lib/Driver/Driver.cpp +++ b/clang/lib/Driver/Driver.cpp @@ -4716,10 +4716,13 @@ void Driver::BuildJobs(Compilation &C) const { // we are also generating .o files. So we allow more than one output file in // this case as well. // + // OffloadClass of type TY_Nothing: device-only output will place many outputs + // into a single offloading action. We should count all inputs to the action + // as outputs. if (FinalOutput) { unsigned NumOutputs = 0; unsigned NumIfsOutputs = 0; - for (const Action *A : C.getActions()) + for (const Action *A : C.getActions()) { if (A->getType() != types::TY_Nothing && !(A->getKind() == Action::IfsMergeJobClass || (A->getType() == clang::driver::types::TY_IFS_CPP && @@ -4728,6 +4731,10 @@ void Driver::BuildJobs(Compilation &C) const { (A->getKind() == Action::BindArchClass && A->getInputs().size() && A->getInputs().front()->getKind() == Action::IfsMergeJobClass))) ++NumOutputs; + else if (A->getKind() == Action::OffloadClass && + A->getType() == types::TY_Nothing) + NumOutputs += A->size(); + } if (NumOutputs > 1) { Diag(clang::diag::err_drv_output_argument_with_multiple_files); @@ -5265,20 +5272,21 @@ InputInfoList Driver::BuildJobsForActionNoCache( // \ // Device Action 1 ---> OffloadAction -> Device Action 2 // - // For a) and b), we just return the job generated for the dependence. For + // For a) and b), we just return the job generated for the dependences. For // c) and d) we override the current action with the host/device dependence // if the current toolchain is host/device and set the offload dependences // info with the jobs obtained from the device/host dependence(s). - // If there is a single device option, just generate the job for it. - if (OA->hasSingleDeviceDependence()) { + // If there is a single device option or has no host action, just generate + // the job for it. + if (OA->hasSingleDeviceDependence() || !OA->hasHostDependence()) { InputInfoList DevA; OA->doOnEachDeviceDependence([&](Action *DepA, const ToolChain *DepTC, const char *DepBoundArch) { - DevA = - BuildJobsForAction(C, DepA, DepTC, DepBoundArch, AtTopLevel, - /*MultipleArchs*/ !!DepBoundArch, LinkingOutput, - CachedResults, DepA->getOffloadingDeviceKind()); + DevA.append(BuildJobsForAction(C, DepA, DepTC, DepBoundArch, AtTopLevel, + /*MultipleArchs*/ !!DepBoundArch, + LinkingOutput, CachedResults, + DepA->getOffloadingDeviceKind())); }); return DevA; } diff --git a/clang/test/Driver/cuda-bindings.cu b/clang/test/Driver/cuda-bindings.cu index 7115117e79ce..a7aa4c797885 100644 --- a/clang/test/Driver/cuda-bindings.cu +++ b/clang/test/Driver/cuda-bindings.cu @@ -146,3 +146,20 @@ // RUN: --cuda-gpu-arch=sm_52 --cuda-device-only -c -o foo.o %s 2>&1 \ // RUN: | FileCheck -check-prefix=D_ONLY %s // D_ONLY: "foo.o" + +// +// Check to make sure we can generate multiple outputs for device-only +// compilation and fail with '-o'. +// +// RUN: %clang -### -target powerpc64le-ibm-linux-gnu --offload-new-driver -ccc-print-bindings \ +// RUN: --offload-arch=sm_70 --offload-arch=sm_52 --offload-device-only -c %s 2>&1 \ +// RUN: | FileCheck -check-prefix=MULTI-D-ONLY %s +// MULTI-D-ONLY: # "nvptx64-nvidia-cuda" - "clang", inputs: ["[[INPUT:.+]]"], output: "[[PTX_70:.+]]" +// MULTI-D-ONLY-NEXT: # "nvptx64-nvidia-cuda" - "NVPTX::Assembler", inputs: ["[[PTX_70]]"], output: "[[CUBIN_70:.+]]" +// MULTI-D-ONLY-NEXT: # "nvptx64-nvidia-cuda" - "clang", inputs: ["[[INPUT]]"], output: "[[PTX_52:.+]]" +// MULTI-D-ONLY-NEXT: # "nvptx64-nvidia-cuda" - "NVPTX::Assembler", inputs: ["[[PTX_52]]"], output: "[[CUBIN_52:.+]]" +// +// RUN: %clang -### -target powerpc64le-ibm-linux-gnu --offload-new-driver -ccc-print-bindings \ +// RUN: --offload-arch=sm_70 --offload-arch=sm_52 --offload-device-only -c -o %t %s 2>&1 \ +// RUN: | FileCheck -check-prefix=MULTI-D-ONLY-O %s +// MULTI-D-ONLY-O: error: cannot specify -o when generating multiple output files diff --git a/clang/test/Driver/hip-binding.hip b/clang/test/Driver/hip-binding.hip index 6a27558dbf03..e9ced3004237 100644 --- a/clang/test/Driver/hip-binding.hip +++ b/clang/test/Driver/hip-binding.hip @@ -51,3 +51,20 @@ // NORDC-NOT: offload bundler // NORDC: # "x86_64-unknown-linux-gnu" - "GNU::Linker", inputs: ["{{.*o}}"], output: "a.out" + +// +// Check to make sure we can generate multiple outputs for device-only +// compilation and fail with '-o'. +// +// RUN: %clang -### -target x86_64-linux-gnu --offload-new-driver -ccc-print-bindings \ +// RUN: --offload-arch=gfx90a --offload-arch=gfx908 --offload-device-only -c %s 2>&1 \ +// RUN: | FileCheck -check-prefix=MULTI-D-ONLY %s +// MULTI-D-ONLY: # "amdgcn-amd-amdhsa" - "clang", inputs: ["[[INPUT:.+]]"], output: "[[GFX908:.+]]" +// MULTI-D-ONLY-NEXT: # "amdgcn-amd-amdhsa" - "AMDGCN::Linker", inputs: ["[[GFX908]]"], output: "[[GFX908_OUT:.+]]" +// MULTI-D-ONLY-NEXT: # "amdgcn-amd-amdhsa" - "clang", inputs: ["[[INPUT]]"], output: "[[GFX90a:.+]]" +// MULTI-D-ONLY-NEXT: # "amdgcn-amd-amdhsa" - "AMDGCN::Linker", inputs: ["[[GFX90a]]"], output: "[[GFX90a_OUT:.+]]" +// +// RUN: %clang -### -target x86_64-linux-gnu --offload-new-driver -ccc-print-bindings \ +// RUN: --offload-arch=gfx90a --offload-arch=gfx908 --offload-device-only -c -o %t %s 2>&1 \ +// RUN: | FileCheck -check-prefix=MULTI-D-ONLY-O %s +// MULTI-D-ONLY-O: error: cannot specify -o when generating multiple output files _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits