Skip to content

Commit 4a501a4

Browse files
authored
[CUDA/HIP] propagate -cuid to a host-only compilation. (#107483)
Right now we're bailing out too early, and `-cuid` does not get set for the host-only compilations.
1 parent 6850410 commit 4a501a4

File tree

2 files changed

+46
-6
lines changed

2 files changed

+46
-6
lines changed

clang/lib/Driver/Driver.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3026,12 +3026,6 @@ class OffloadingActionBuilder final {
30263026
// Set the flag to true, so that the builder acts on the current input.
30273027
IsActive = true;
30283028

3029-
if (CompileHostOnly)
3030-
return ABRT_Success;
3031-
3032-
// Replicate inputs for each GPU architecture.
3033-
auto Ty = IA->getType() == types::TY_HIP ? types::TY_HIP_DEVICE
3034-
: types::TY_CUDA_DEVICE;
30353029
std::string CUID = FixedCUID.str();
30363030
if (CUID.empty()) {
30373031
if (UseCUID == CUID_Random)
@@ -3055,6 +3049,12 @@ class OffloadingActionBuilder final {
30553049
}
30563050
IA->setId(CUID);
30573051

3052+
if (CompileHostOnly)
3053+
return ABRT_Success;
3054+
3055+
// Replicate inputs for each GPU architecture.
3056+
auto Ty = IA->getType() == types::TY_HIP ? types::TY_HIP_DEVICE
3057+
: types::TY_CUDA_DEVICE;
30583058
for (unsigned I = 0, E = GpuArchList.size(); I != E; ++I) {
30593059
CudaDeviceActions.push_back(
30603060
C.MakeAction<InputAction>(IA->getInputArg(), Ty, IA->getId()));

clang/test/Driver/hip-cuid.hip

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,28 @@
5858
// RUN: %S/Inputs/hip_multiple_inputs/b.hip \
5959
// RUN: 2>&1 | FileCheck -check-prefixes=COMMON,HEX %s
6060

61+
// Check that cuid is propagated to the host-only compilation.
62+
// RUN: %clang -### -x hip \
63+
// RUN: --target=x86_64-unknown-linux-gnu \
64+
// RUN: --no-offload-new-driver \
65+
// RUN: --offload-arch=gfx900 \
66+
// RUN: --offload-host-only \
67+
// RUN: -c -nogpuinc -nogpulib -cuid=xyz_123 \
68+
// RUN: %S/Inputs/hip_multiple_inputs/a.cu \
69+
// RUN: %S/Inputs/hip_multiple_inputs/b.hip \
70+
// RUN: 2>&1 | FileCheck -check-prefixes=HOST %s
71+
72+
// Check that cuid is propagated to the device-only compilation.
73+
// RUN: %clang -### -x hip \
74+
// RUN: --target=x86_64-unknown-linux-gnu \
75+
// RUN: --no-offload-new-driver \
76+
// RUN: --offload-arch=gfx900 \
77+
// RUN: --offload-device-only \
78+
// RUN: -c -nogpuinc -nogpulib -cuid=xyz_123 \
79+
// RUN: %S/Inputs/hip_multiple_inputs/a.cu \
80+
// RUN: %S/Inputs/hip_multiple_inputs/b.hip \
81+
// RUN: 2>&1 | FileCheck -check-prefixes=DEVICE %s
82+
6183
// INVALID: invalid value 'invalid' in '-fuse-cuid=invalid'
6284

6385
// COMMON: "-cc1"{{.*}} "-triple" "amdgcn-amd-amdhsa"
@@ -92,3 +114,21 @@
92114
// HEX-NOT: "-cuid=[[CUID]]"
93115
// COMMON-SAME: "-cuid=[[CUID2]]"
94116
// COMMON-SAME: "{{.*}}b.hip"
117+
118+
// HOST: "-cc1"{{.*}} "-triple" "x86_64-unknown-linux-gnu"
119+
// HOST-SAME: "-cuid=[[CUID:xyz_123]]"
120+
// HOST-SAME: "{{.*}}a.cu"
121+
122+
// HOST: "-cc1"{{.*}} "-triple" "x86_64-unknown-linux-gnu"
123+
// HOST-SAME: "-cuid=[[CUID]]"
124+
// HOST-SAME: "{{.*}}b.hip"
125+
126+
// DEVICE: "-cc1"{{.*}} "-triple" "amdgcn-amd-amdhsa"
127+
// DEVICE-SAME: "-target-cpu" "gfx900"
128+
// DEVICE-SAME: "-cuid=[[CUID:xyz_123]]"
129+
// DEVICE-SAME: "{{.*}}a.cu"
130+
131+
// DEVICE: "-cc1"{{.*}} "-triple" "amdgcn-amd-amdhsa"
132+
// DEVICE-SAME: "-target-cpu" "gfx900"
133+
// DEVICE-SAME: "-cuid=[[CUID]]"
134+
// DEVICE-SAME: "{{.*}}b.hip"

0 commit comments

Comments
 (0)