Skip to content

[CUDA] pass -fno-threadsafe-statics to GPU sub-compilations. #117074

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions clang/lib/Driver/ToolChains/Cuda.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -856,8 +856,9 @@ void CudaToolChain::addClangTargetOptions(
DeviceOffloadingKind == Action::OFK_Cuda) &&
"Only OpenMP or CUDA offloading kinds are supported for NVIDIA GPUs.");

CC1Args.append(
{"-fcuda-is-device", "-mllvm", "-enable-memcpyopt-without-libcalls"});
CC1Args.append({"-fcuda-is-device", "-mllvm",
"-enable-memcpyopt-without-libcalls",
"-fno-threadsafe-statics"});

// Unsized function arguments used for variadics were introduced in CUDA-9.0
// We still do not support generating code that actually uses variadic
Expand Down
2 changes: 1 addition & 1 deletion clang/lib/Driver/ToolChains/HIPAMD.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ void HIPAMDToolChain::addClangTargetOptions(
assert(DeviceOffloadingKind == Action::OFK_HIP &&
"Only HIP offloading kinds are supported for GPUs.");

CC1Args.push_back("-fcuda-is-device");
CC1Args.append({"-fcuda-is-device", "-fno-threadsafe-statics"});

if (!DriverArgs.hasFlag(options::OPT_fgpu_rdc, options::OPT_fno_gpu_rdc,
false))
Expand Down
13 changes: 13 additions & 0 deletions clang/test/Driver/cuda-no-threadsafe-statics.cu
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// Check that -fno-thread-safe-statics get passed down to device-side
// compilation only.
//
// RUN: %clang -### -x cuda --target=x86_64-linux-gnu -c --cuda-gpu-arch=sm_20 %s \
// RUN: -nocudainc -nocudalib 2>&1 | FileCheck %s

// RUN: %clang -### -x hip --target=x86_64-linux-gnu -c --cuda-gpu-arch=gfx1010 %s \
// RUN: -nocudainc -nocudalib 2>&1 | FileCheck %s
//
// CHECK: "-fcuda-is-device"
// CHECK-SAME: "-fno-threadsafe-statics"
// CHECK: "-triple" "x86_64-unknown-linux-gnu"
// CHECK-NOT: "-fno-threadsafe-statics"
Loading