Skip to content
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

[SYCL][PTX][CUDA] Implicit global offset implementation #1773

Merged
merged 3 commits into from
Jul 3, 2020
Merged
Show file tree
Hide file tree
Changes from 2 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/Basic/BuiltinsNVPTX.def
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,9 @@ BUILTIN(__nvvm_read_ptx_sreg_pm1, "i", "n")
BUILTIN(__nvvm_read_ptx_sreg_pm2, "i", "n")
BUILTIN(__nvvm_read_ptx_sreg_pm3, "i", "n")

// SYCL
BUILTIN(__builtin_ptx_implicit_offset, "Ui*", "nc")

// MISC

BUILTIN(__nvvm_prmt, "UiUiUiUi", "")
Expand Down
9 changes: 6 additions & 3 deletions libclc/ptx-nvidiacl/libspirv/workitem/get_global_id.cl
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,16 @@
#include <spirv/spirv.h>

_CLC_DEF _CLC_OVERLOAD size_t __spirv_GlobalInvocationId_x() {
return __spirv_WorkgroupId_x() * __spirv_WorkgroupSize_x() + __spirv_LocalInvocationId_x();
return __spirv_WorkgroupId_x() * __spirv_WorkgroupSize_x() +
__spirv_LocalInvocationId_x() + __spirv_GlobalOffset_x();
}

_CLC_DEF _CLC_OVERLOAD size_t __spirv_GlobalInvocationId_y() {
return __spirv_WorkgroupId_y() * __spirv_WorkgroupSize_y() + __spirv_LocalInvocationId_y();
return __spirv_WorkgroupId_y() * __spirv_WorkgroupSize_y() +
__spirv_LocalInvocationId_y() + __spirv_GlobalOffset_y();
}

_CLC_DEF _CLC_OVERLOAD size_t __spirv_GlobalInvocationId_z() {
return __spirv_WorkgroupId_z() * __spirv_WorkgroupSize_z() + __spirv_LocalInvocationId_z();
return __spirv_WorkgroupId_z() * __spirv_WorkgroupSize_z() +
__spirv_LocalInvocationId_z() + __spirv_GlobalOffset_z();
}
6 changes: 3 additions & 3 deletions libclc/ptx-nvidiacl/libspirv/workitem/get_global_offset.cl
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@
// Compiler support is required to provide global offset on NVPTX.

_CLC_DEF _CLC_OVERLOAD size_t __spirv_GlobalOffset_x() {
return 0;
return __builtin_ptx_implicit_offset()[0];
}

_CLC_DEF _CLC_OVERLOAD size_t __spirv_GlobalOffset_y() {
return 0;
return __builtin_ptx_implicit_offset()[1];
}

_CLC_DEF _CLC_OVERLOAD size_t __spirv_GlobalOffset_z() {
return 0;
return __builtin_ptx_implicit_offset()[2];
}
6 changes: 6 additions & 0 deletions llvm/include/llvm/IR/IntrinsicsNVVM.td
Original file line number Diff line number Diff line change
Expand Up @@ -4161,4 +4161,10 @@ foreach layout_a = ["row", "col"] in {
} // layout_b
} // layout_a

// SYCL
def int_nvvm_implicit_offset :
GCCBuiltin<"__builtin_ptx_implicit_offset">,
Intrinsic<[LLVMPointerType<llvm_i32_ty>], [],
[IntrNoMem, IntrSpeculatable]>;

} // let TargetPrefix = "nvvm"
1 change: 1 addition & 0 deletions llvm/lib/Target/NVPTX/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ set(NVPTXCodeGen_sources
NVVMIntrRange.cpp
NVVMReflect.cpp
NVPTXProxyRegErasure.cpp
SYCL/GlobalOffset.cpp
SYCL/LocalAccessorToSharedMemory.cpp
)

Expand Down
6 changes: 5 additions & 1 deletion llvm/lib/Target/NVPTX/NVPTXTargetMachine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@
#include "NVPTXLowerAggrCopies.h"
#include "NVPTXTargetObjectFile.h"
#include "NVPTXTargetTransformInfo.h"
#include "TargetInfo/NVPTXTargetInfo.h"
#include "SYCL/GlobalOffset.h"
#include "SYCL/LocalAccessorToSharedMemory.h"
#include "TargetInfo/NVPTXTargetInfo.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/Triple.h"
#include "llvm/Analysis/TargetTransformInfo.h"
Expand Down Expand Up @@ -71,6 +72,7 @@ void initializeNVPTXLowerArgsPass(PassRegistry &);
void initializeNVPTXLowerAllocaPass(PassRegistry &);
void initializeNVPTXProxyRegErasurePass(PassRegistry &);

void initializeGlobalOffsetPass(PassRegistry &);
void initializeLocalAccessorToSharedMemoryPass(PassRegistry &);

} // end namespace llvm
Expand All @@ -94,6 +96,7 @@ extern "C" LLVM_EXTERNAL_VISIBILITY void LLVMInitializeNVPTXTarget() {
initializeNVPTXProxyRegErasurePass(PR);

// SYCL-specific passes, needed here to be available to `opt`.
initializeGlobalOffsetPass(PR);
initializeLocalAccessorToSharedMemoryPass(PR);
}

Expand Down Expand Up @@ -274,6 +277,7 @@ void NVPTXPassConfig::addIRPasses() {

if (getTM<NVPTXTargetMachine>().getTargetTriple().getOS() == Triple::CUDA &&
getTM<NVPTXTargetMachine>().getTargetTriple().getEnvironment() == Triple::SYCLDevice) {
addPass(createGlobalOffsetPass());
addPass(createLocalAccessorToSharedMemoryPass());
}

Expand Down
Loading