Skip to content

Commit 94ba644

Browse files
Artem-BPankaj Kumar Divedi
authored andcommitted
[CUDA/HIP] propagate -cuid to a host-only compilation. (llvm#107483)
Right now we're bailing out too early, and `-cuid` does not get set for the host-only compilations. Change-Id: I07c5a2b23be66c2ba3bf97a2ebbd6169e05e37cf
1 parent 73bc12c commit 94ba644

File tree

2 files changed

+46
-7
lines changed

2 files changed

+46
-7
lines changed

clang/lib/Driver/Driver.cpp

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3041,13 +3041,6 @@ class OffloadingActionBuilder final {
30413041
// Set the flag to true, so that the builder acts on the current input.
30423042
IsActive = true;
30433043

3044-
if (CompileHostOnly)
3045-
return ABRT_Success;
3046-
3047-
// Replicate inputs for each GPU architecture.
3048-
auto Ty = AssociatedOffloadKind == Action::OFK_HIP
3049-
? types::TY_HIP_DEVICE
3050-
: types::TY_CUDA_DEVICE;
30513044
std::string CUID = FixedCUID.str();
30523045
if (CUID.empty()) {
30533046
if (UseCUID == CUID_Random)
@@ -3071,6 +3064,12 @@ class OffloadingActionBuilder final {
30713064
}
30723065
IA->setId(CUID);
30733066

3067+
if (CompileHostOnly)
3068+
return ABRT_Success;
3069+
3070+
// Replicate inputs for each GPU architecture.
3071+
auto Ty = IA->getType() == types::TY_HIP ? types::TY_HIP_DEVICE
3072+
: types::TY_CUDA_DEVICE;
30743073
for (unsigned I = 0, E = GpuArchList.size(); I != E; ++I) {
30753074
CudaDeviceActions.push_back(
30763075
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)