Skip to content

[CUDA][HIP] add option -gpuinc #140106

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
3 changes: 3 additions & 0 deletions clang/include/clang/Driver/Options.td
Original file line number Diff line number Diff line change
Expand Up @@ -5734,6 +5734,9 @@ def nobuiltininc : Flag<["-"], "nobuiltininc">,
def nogpuinc : Flag<["-"], "nogpuinc">, Group<IncludePath_Group>,
HelpText<"Do not add include paths for CUDA/HIP and"
" do not include the default CUDA/HIP wrapper headers">;
def gpuinc : Flag<["-"], "gpuinc">, Group<IncludePath_Group>,
HelpText<"Add include paths for CUDA/HIP and"
" include the default CUDA/HIP wrapper headers">;
Comment on lines 5734 to +5739
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we consolidate them into s single boolean flag?

def nohipwrapperinc : Flag<["-"], "nohipwrapperinc">, Group<IncludePath_Group>,
HelpText<"Do not include the default HIP wrapper headers and include paths">;
def : Flag<["-"], "nocudainc">, Alias<nogpuinc>;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should also have an alias for cudainc, too.

Expand Down
2 changes: 1 addition & 1 deletion clang/lib/Driver/ToolChains/AMDGPU.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -526,7 +526,7 @@ void RocmInstallationDetector::AddHIPIncludeArgs(const ArgList &DriverArgs,
"hipstdpar_lib.hpp"});
};

if (DriverArgs.hasArg(options::OPT_nogpuinc)) {
if (!DriverArgs.hasFlag(options::OPT_gpuinc, options::OPT_nogpuinc, true)) {
if (HasHipStdPar)
HandleHipStdPar();

Expand Down
4 changes: 2 additions & 2 deletions clang/lib/Driver/ToolChains/Clang.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1107,7 +1107,7 @@ void Clang::AddPreprocessingOptions(Compilation &C, const JobAction &JA,
// openmp_wrappers folder which contains alternative system headers.
if (JA.isDeviceOffloading(Action::OFK_OpenMP) &&
!Args.hasArg(options::OPT_nostdinc) &&
!Args.hasArg(options::OPT_nogpuinc) &&
Args.hasFlag(options::OPT_gpuinc, options::OPT_nogpuinc, true) &&
getToolChain().getTriple().isGPU()) {
if (!Args.hasArg(options::OPT_nobuiltininc)) {
// Add openmp_wrappers/* to our system include path. This lets us wrap
Expand Down Expand Up @@ -1290,7 +1290,7 @@ void Clang::AddPreprocessingOptions(Compilation &C, const JobAction &JA,
// TODO: This should be moved to `AddClangSystemIncludeArgs` by passing the
// OffloadKind as an argument.
if (!Args.hasArg(options::OPT_nostdinc) &&
!Args.hasArg(options::OPT_nogpuinc) &&
Args.hasFlag(options::OPT_gpuinc, options::OPT_nogpuinc, true) &&
!Args.hasArg(options::OPT_nobuiltininc)) {
// Without an offloading language we will include these headers directly.
// Offloading languages will instead only use the declarations stored in
Expand Down
7 changes: 4 additions & 3 deletions clang/lib/Driver/ToolChains/Cuda.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ void CudaInstallationDetector::AddCudaIncludeArgs(
CC1Args.push_back(DriverArgs.MakeArgString(P));
}

if (DriverArgs.hasArg(options::OPT_nogpuinc))
if (!DriverArgs.hasFlag(options::OPT_gpuinc, options::OPT_nogpuinc, true))
return;

if (!isValid()) {
Expand Down Expand Up @@ -931,7 +931,7 @@ llvm::DenormalMode CudaToolChain::getDefaultDenormalModeForType(
void CudaToolChain::AddCudaIncludeArgs(const ArgList &DriverArgs,
ArgStringList &CC1Args) const {
// Check our CUDA version if we're going to include the CUDA headers.
if (!DriverArgs.hasArg(options::OPT_nogpuinc) &&
if (DriverArgs.hasFlag(options::OPT_gpuinc, options::OPT_nogpuinc, true) &&
!DriverArgs.hasArg(options::OPT_no_cuda_version_check)) {
StringRef Arch = DriverArgs.getLastArgValue(options::OPT_march_EQ);
assert(!Arch.empty() && "Must have an explicit GPU arch.");
Expand Down Expand Up @@ -1004,7 +1004,8 @@ void CudaToolChain::AddClangSystemIncludeArgs(const ArgList &DriverArgs,
ArgStringList &CC1Args) const {
HostTC.AddClangSystemIncludeArgs(DriverArgs, CC1Args);

if (!DriverArgs.hasArg(options::OPT_nogpuinc) && CudaInstallation.isValid())
if (DriverArgs.hasFlag(options::OPT_gpuinc, options::OPT_nogpuinc, true) &&
CudaInstallation.isValid())
CC1Args.append(
{"-internal-isystem",
DriverArgs.MakeArgString(CudaInstallation.getIncludePath())});
Expand Down
2 changes: 1 addition & 1 deletion clang/lib/Driver/ToolChains/HIPSPV.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ void HIPSPVToolChain::AddIAMCUIncludeArgs(const ArgList &Args,

void HIPSPVToolChain::AddHIPIncludeArgs(const ArgList &DriverArgs,
ArgStringList &CC1Args) const {
if (DriverArgs.hasArg(options::OPT_nogpuinc))
if (!DriverArgs.hasFlag(options::OPT_gpuinc, options::OPT_nogpuinc, true))
return;

StringRef hipPath = DriverArgs.getLastArgValue(options::OPT_hip_path_EQ);
Expand Down
4 changes: 4 additions & 0 deletions clang/test/Driver/hip-include-path.hip
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@
// RUN: -std=c++11 --rocm-path=%S/Inputs/rocm -nogpuinc -nogpulib %s 2>&1 \
// RUN: | FileCheck -check-prefixes=COMMON,CLANG,NOHIP %s

// RUN: %clang -c -### --target=x86_64-unknown-linux-gnu --cuda-gpu-arch=gfx900 \
// RUN: -std=c++11 --rocm-path=%S/Inputs/rocm -nogpuinc -nogpulib -gpuinc %s 2>&1 \
// RUN: | FileCheck -check-prefixes=COMMON,CLANG,HIP %s

// COMMON-LABEL: "{{[^"]*}}clang{{[^"]*}}" "-cc1"
// CLANG-SAME: "-internal-isystem" "{{[^"]*}}/lib{{[^"]*}}/clang/{{[^"]*}}/include/cuda_wrappers"
// NOCLANG-NOT: "{{[^"]*}}/lib{{[^"]*}}/clang/{{[^"]*}}/include/cuda_wrappers"
Expand Down