Skip to content

Commit e372c1d

Browse files
committed
[HIP] Fix -fgpu-allow-device-init option
The option needs to be passed to both host and device compilation. Differential Revision: https://reviews.llvm.org/D88550
1 parent 5b551b7 commit e372c1d

File tree

3 files changed

+13
-7
lines changed

3 files changed

+13
-7
lines changed

clang/lib/Driver/ToolChains/Clang.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5476,9 +5476,14 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
54765476
// Forward -cl options to -cc1
54775477
RenderOpenCLOptions(Args, CmdArgs);
54785478

5479-
if (IsHIP && Args.hasFlag(options::OPT_fhip_new_launch_api,
5480-
options::OPT_fno_hip_new_launch_api, true))
5481-
CmdArgs.push_back("-fhip-new-launch-api");
5479+
if (IsHIP) {
5480+
if (Args.hasFlag(options::OPT_fhip_new_launch_api,
5481+
options::OPT_fno_hip_new_launch_api, true))
5482+
CmdArgs.push_back("-fhip-new-launch-api");
5483+
if (Args.hasFlag(options::OPT_fgpu_allow_device_init,
5484+
options::OPT_fno_gpu_allow_device_init, false))
5485+
CmdArgs.push_back("-fgpu-allow-device-init");
5486+
}
54825487

54835488
if (Arg *A = Args.getLastArg(options::OPT_fcf_protection_EQ)) {
54845489
CmdArgs.push_back(

clang/lib/Driver/ToolChains/HIP.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -268,10 +268,6 @@ void HIPToolChain::addClangTargetOptions(
268268
CC1Args.push_back(DriverArgs.MakeArgStringRef(ArgStr));
269269
}
270270

271-
if (DriverArgs.hasFlag(options::OPT_fgpu_allow_device_init,
272-
options::OPT_fno_gpu_allow_device_init, false))
273-
CC1Args.push_back("-fgpu-allow-device-init");
274-
275271
CC1Args.push_back("-fcuda-allow-variadic-functions");
276272

277273
// Default to "hidden" visibility, as object level linking will not be

clang/test/Driver/hip-options.hip

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@
99
// CHECK: clang{{.*}}" "-cc1" {{.*}} "-fcuda-is-device"
1010
// CHECK-SAME: "--gpu-max-threads-per-block=1024"
1111

12+
// RUN: %clang -### -nogpuinc -nogpulib -fgpu-allow-device-init \
13+
// RUN: %s 2>&1 | FileCheck -check-prefix=DEVINIT %s
14+
// DEVINIT: clang{{.*}}" "-cc1" {{.*}}"-fgpu-allow-device-init"
15+
// DEVINIT: clang{{.*}}" "-cc1" {{.*}}"-fgpu-allow-device-init"
16+
1217
// RUN: %clang -### -x hip -target x86_64-pc-windows-msvc -fms-extensions \
1318
// RUN: -mllvm -amdgpu-early-inline-all=true %s 2>&1 | \
1419
// RUN: FileCheck -check-prefix=MLLVM %s

0 commit comments

Comments
 (0)