Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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/Clang.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8537,9 +8537,10 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
}
}

if (IsCuda) {
if (IsCuda || (IsSYCLDevice && Triple.isNVPTX())) {
bool UseShortPtr = IsSYCLDevice && Triple.isNVPTX();
if (Args.hasFlag(options::OPT_fcuda_short_ptr,
options::OPT_fno_cuda_short_ptr, false))
options::OPT_fno_cuda_short_ptr, UseShortPtr))
CmdArgs.push_back("-fcuda-short-ptr");
}

Expand Down
9 changes: 5 additions & 4 deletions clang/lib/Driver/ToolChains/Cuda.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1010,6 +1010,11 @@ void CudaToolChain::addClangTargetOptions(
CC1Args.push_back(DriverArgs.MakeArgString(LibSpirvFile));
}

bool UseShortPtr = DeviceOffloadingKind == Action::OFK_SYCL;
if (DriverArgs.hasFlag(options::OPT_fcuda_short_ptr,
options::OPT_fno_cuda_short_ptr, UseShortPtr))
CC1Args.append({"-mllvm", "--nvptx-short-ptr"});

if (DriverArgs.hasArg(options::OPT_nogpulib))
return;

Expand All @@ -1035,10 +1040,6 @@ void CudaToolChain::addClangTargetOptions(

clang::CudaVersion CudaInstallationVersion = CudaInstallation.version();

if (DriverArgs.hasFlag(options::OPT_fcuda_short_ptr,
options::OPT_fno_cuda_short_ptr, false))
CC1Args.append({"-mllvm", "--nvptx-short-ptr"});

if (CudaInstallationVersion >= CudaVersion::UNKNOWN)
CC1Args.push_back(
DriverArgs.MakeArgString(Twine("-target-sdk-version=") +
Expand Down
7 changes: 6 additions & 1 deletion libclc/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -450,10 +450,15 @@ foreach( t ${LIBCLC_TARGETS_TO_BUILD} )
list(APPEND flags -D__unix__)
endif()

set(spirv_flags ${flags})
if( ARCH STREQUAL nvptx OR ARCH STREQUAL nvptx64 )
list(APPEND spirv_flags -Xclang -fcuda-short-ptr -mllvm -nvptx-short-ptr)

Choose a reason for hiding this comment

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

I think this is ok, but you could end up linking the libspirv (with short ptr) to a program compiled without. As builtins don't write pointers, I don't think this is an issue but would be good to test prior to merging and document this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Note I've now reduced the scope of this PR and the option is no longer enabled by default. Thus libclc/libspirv is no longer compiled with this option. If a user passes -fcuda-short-ptr they'll see a warning while linking libclc/libspirv which I think is correct to do.

But yes in general we need to consider whether this is okay. I also think it's okay, and I've run several benchmarks with it and not seen a problem. Ideally we'd compile two versions of libspirv for NVPTX, but I don't know if it's going to be worth it for this relatively obscure option.

endif()

add_libclc_builtin_set(libspirv-${arch_suffix}
TRIPLE ${clang_triple}
TARGET_ENV libspirv
COMPILE_OPT ${flags}
COMPILE_OPT ${spirv_flags}
OPT_FLAGS ${opt_flags}
FILES ${libspirv_files}
GEN_FILES ${libspirv_gen_files}
Expand Down
Loading