-
Notifications
You must be signed in to change notification settings - Fork 792
[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; | ||
|
||
}; | ||
|
||
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.