-
Notifications
You must be signed in to change notification settings - Fork 790
[SYCL] Add device_ptr and host_ptr #1864
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
Changes from all commits
27e7b6a
23a8ada
5aa55f3
2c832ee
2ef86a0
fc5aa11
1a1237c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -45,7 +45,9 @@ enum class address_space : int { | |
private_space = 0, | ||
global_space, | ||
constant_space, | ||
local_space | ||
local_space, | ||
global_device_space, | ||
global_host_space | ||
}; | ||
|
||
} // namespace access | ||
|
@@ -103,11 +105,15 @@ constexpr bool modeWritesNewData(access::mode m) { | |
|
||
#ifdef __SYCL_DEVICE_ONLY__ | ||
#define __OPENCL_GLOBAL_AS__ __attribute__((opencl_global)) | ||
#define __OPENCL_GLOBAL_DEVICE_AS__ __attribute__((opencl_global_device)) | ||
#define __OPENCL_GLOBAL_HOST_AS__ __attribute__((opencl_global_host)) | ||
#define __OPENCL_LOCAL_AS__ __attribute__((opencl_local)) | ||
#define __OPENCL_CONSTANT_AS__ __attribute__((opencl_constant)) | ||
#define __OPENCL_PRIVATE_AS__ __attribute__((opencl_private)) | ||
#else | ||
#define __OPENCL_GLOBAL_AS__ | ||
#define __OPENCL_GLOBAL_DEVICE_AS__ | ||
#define __OPENCL_GLOBAL_HOST_AS__ | ||
#define __OPENCL_LOCAL_AS__ | ||
#define __OPENCL_CONSTANT_AS__ | ||
#define __OPENCL_PRIVATE_AS__ | ||
|
@@ -141,6 +147,16 @@ struct PtrValueType<ElementType, access::address_space::global_space> { | |
using type = __OPENCL_GLOBAL_AS__ ElementType; | ||
}; | ||
|
||
template <typename ElementType> | ||
struct PtrValueType<ElementType, access::address_space::global_device_space> { | ||
using type = __OPENCL_GLOBAL_DEVICE_AS__ ElementType; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is likely to not be portable and cause ICE rather than a clear error. As this overlaps with There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As DPCPP compiler generated SPIR-V code - this mechanism is currently moved to the SPIR-V translator (basically during reversed translation from SPIR-V to LLVM IR there is an option added - without this option passed, the translator will generate global address space instead of global_device / global_host address space. So if someone would like to support these address spaces in their backend - it's needed to add this option in the backend's driver. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
or PTX via the NVPTX backend without going through SPIR-V There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Got it, thanks! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actually, not, I don't really get it. What target is used for NVPTX? I mean, that in clang part of the feature we have added definitions for these new address spaces like this:
If for NVPTX we compile with spir-unknown-unknown triple, than the code above is indeed a problem. But if not - I don't see any issues. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
The issue is in the mangler, given the current definition of the address space mapping void foo(global_ptr<int>::pointer_t p) { [...] }
void foo(device_ptr<int>::pointer_t p) { [...] } This will cause the compiler to mangle the 2 There is 2 solutions to it:
Note: this is kind of a corner case for now, I pointing this out so you are aware of it. I'm more concerned about the naming here. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thank you very much for your feedback. I'll think about these options. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would like to leave this corner case unresolved for now. One of the possible solutions is to expand authority of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @MrSidims, could you open a GitHub issue to track/discuss solution this problem, please? |
||
}; | ||
|
||
template <typename ElementType> | ||
struct PtrValueType<ElementType, access::address_space::global_host_space> { | ||
using type = __OPENCL_GLOBAL_HOST_AS__ ElementType; | ||
}; | ||
|
||
template <typename ElementType> | ||
struct PtrValueType<ElementType, access::address_space::constant_space> { | ||
// Current implementation of address spaces handling leads to possibility | ||
|
@@ -171,6 +187,14 @@ struct remove_AS<__OPENCL_GLOBAL_AS__ T> { | |
typedef T type; | ||
}; | ||
|
||
template <class T> struct remove_AS<__OPENCL_GLOBAL_DEVICE_AS__ T> { | ||
typedef T type; | ||
}; | ||
|
||
template <class T> struct remove_AS<__OPENCL_GLOBAL_HOST_AS__ T> { | ||
typedef T type; | ||
}; | ||
|
||
template <class T> | ||
struct remove_AS<__OPENCL_PRIVATE_AS__ T> { | ||
typedef T type; | ||
|
@@ -188,6 +212,8 @@ struct remove_AS<__OPENCL_CONSTANT_AS__ T> { | |
#endif | ||
|
||
#undef __OPENCL_GLOBAL_AS__ | ||
#undef __OPENCL_GLOBAL_DEVICE_AS__ | ||
#undef __OPENCL_GLOBAL_HOST_AS__ | ||
#undef __OPENCL_LOCAL_AS__ | ||
#undef __OPENCL_CONSTANT_AS__ | ||
#undef __OPENCL_PRIVATE_AS__ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// RUN: %clangxx -fsycl-device-only -Xclang -fsycl-is-device -emit-llvm %s -S -o %t.ll -I %sycl_include -Wno-sycl-strict -Xclang -verify-ignore-unexpected=note,warning | ||
// RUN: FileCheck %s --input-file %t.ll | ||
// | ||
// Check the address space of the pointer in multi_ptr class | ||
// | ||
// CHECK: %[[DEVPTR_T:.*]] = type { i8 addrspace(5)* } | ||
// CHECK: %[[HOSTPTR_T:.*]] = type { i8 addrspace(6)* } | ||
// | ||
// CHECK-LABEL: define {{.*}} spir_func i8 addrspace(4)* @{{.*}}multi_ptr{{.*}} | ||
// CHECK: %m_Pointer = getelementptr inbounds %[[DEVPTR_T]] | ||
// CHECK-NEXT: %[[DEVLOAD:[0-9]+]] = load i8 addrspace(5)*, i8 addrspace(5)* addrspace(4)* %m_Pointer | ||
// CHECK-NEXT: %[[DEVCAST:[0-9]+]] = addrspacecast i8 addrspace(5)* %[[DEVLOAD]] to i8 addrspace(4)* | ||
// ret i8 addrspace(4)* %[[DEVCAST]] | ||
// | ||
// CHECK-LABEL: define {{.*}} spir_func i8 addrspace(4)* @{{.*}}multi_ptr{{.*}} | ||
// CHECK: %m_Pointer = getelementptr inbounds %[[HOSTPTR_T]] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This test fails on the builds with disabled assertions. I suppose we should not check variable names - those are stripped. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok |
||
// CHECK-NEXT: %[[HOSTLOAD:[0-9]+]] = load i8 addrspace(6)*, i8 addrspace(6)* addrspace(4)* %m_Pointer | ||
// CHECK-NEXT: %[[HOSTCAST:[0-9]+]] = addrspacecast i8 addrspace(6)* %[[HOSTLOAD]] to i8 addrspace(4)* | ||
// ret i8 addrspace(4)* %[[HOSTCAST]] | ||
|
||
#include <CL/sycl.hpp> | ||
|
||
using namespace cl::sycl; | ||
|
||
int main() { | ||
cl::sycl::queue queue; | ||
{ | ||
queue.submit([&](cl::sycl::handler &cgh) { | ||
cgh.single_task<class check_adress_space>([=]() { | ||
void *Ptr = nullptr; | ||
device_ptr<void> DevPtr(Ptr); | ||
host_ptr<void> HostPtr(Ptr); | ||
global_ptr<void> GlobPtr = global_ptr<void>(DevPtr); | ||
GlobPtr = global_ptr<void>(HostPtr); | ||
}); | ||
}); | ||
queue.wait(); | ||
} | ||
|
||
return 0; | ||
} |
Uh oh!
There was an error while loading. Please reload this page.