Skip to content

Commit a287f9d

Browse files
committed
[SYCL] Fix conversions in multi_ptr class.
Clang doesn't allow casting address spaces using reinterpret_cast. Replaced with C-style cast. Signed-off-by: Vlad Romanov <[email protected]>
1 parent a91d722 commit a287f9d

File tree

2 files changed

+17
-9
lines changed

2 files changed

+17
-9
lines changed

sycl/include/CL/sycl/multi_ptr.hpp

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,7 @@ template <typename ElementType, access::address_space Space> class multi_ptr {
4242
multi_ptr(multi_ptr &&) = default;
4343
multi_ptr(pointer_t pointer) : m_Pointer(pointer) {}
4444
#ifdef __SYCL_DEVICE_ONLY__
45-
multi_ptr(ElementType *pointer)
46-
: m_Pointer((pointer_t)(pointer)) {
45+
multi_ptr(ElementType *pointer) : m_Pointer((pointer_t)(pointer)) {
4746
// TODO An implementation should reject an argument if the deduced
4847
// address space is not compatible with Space.
4948
}
@@ -62,7 +61,7 @@ template <typename ElementType, access::address_space Space> class multi_ptr {
6261
multi_ptr &operator=(ElementType *pointer) {
6362
// TODO An implementation should reject an argument if the deduced
6463
// address space is not compatible with Space.
65-
m_Pointer = reinterpret_cast<pointer_t>(pointer);
64+
m_Pointer = (pointer_t)pointer;
6665
return *this;
6766
}
6867
#endif
@@ -93,7 +92,7 @@ template <typename ElementType, access::address_space Space> class multi_ptr {
9392
multi_ptr(accessor<ElementType, dimensions, Mode,
9493
access::target::global_buffer, isPlaceholder>
9594
Accessor) {
96-
m_Pointer = reinterpret_cast<pointer_t>(Accessor.get_pointer().m_Pointer);
95+
m_Pointer = (pointer_t)(Accessor.get_pointer().m_Pointer);
9796
}
9897

9998
// Only if Space == local_space
@@ -287,7 +286,7 @@ template <access::address_space Space> class multi_ptr<void, Space> {
287286
multi_ptr(multi_ptr &&) = default;
288287
multi_ptr(pointer_t pointer) : m_Pointer(pointer) {}
289288
#ifdef __SYCL_DEVICE_ONLY__
290-
multi_ptr(void *pointer) : m_Pointer(reinterpret_cast<pointer_t>(pointer)) {
289+
multi_ptr(void *pointer) : m_Pointer((pointer_t)pointer) {
291290
// TODO An implementation should reject an argument if the deduced
292291
// address space is not compatible with Space.
293292
}
@@ -313,7 +312,7 @@ template <access::address_space Space> class multi_ptr<void, Space> {
313312
multi_ptr &operator=(void *pointer) {
314313
// TODO An implementation should reject an argument if the deduced
315314
// address space is not compatible with Space.
316-
m_Pointer = reinterpret_cast<pointer_t>(pointer);
315+
m_Pointer = (pointer_t)pointer;
317316
return *this;
318317
}
319318
#endif
@@ -403,8 +402,7 @@ class multi_ptr<const void, Space> {
403402
multi_ptr(multi_ptr &&) = default;
404403
multi_ptr(pointer_t pointer) : m_Pointer(pointer) {}
405404
#ifdef __SYCL_DEVICE_ONLY__
406-
multi_ptr(const void *pointer)
407-
: m_Pointer(reinterpret_cast<pointer_t>(pointer)) {
405+
multi_ptr(const void *pointer) : m_Pointer((pointer_t)pointer) {
408406
// TODO An implementation should reject an argument if the deduced
409407
// address space is not compatible with Space.
410408
}
@@ -430,7 +428,7 @@ class multi_ptr<const void, Space> {
430428
multi_ptr &operator=(const void *pointer) {
431429
// TODO An implementation should reject an argument if the deduced
432430
// address space is not compatible with Space.
433-
m_Pointer = reinterpret_cast<pointer_t>(pointer);
431+
m_Pointer = (pointer_t)pointer;
434432
return *this;
435433
}
436434
#endif

sycl/test/multi_ptr/multi_ptr.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,16 @@ template <typename T> void testMultPtr() {
7777
auto local_ptr = make_ptr<T, access::address_space::local_space>(
7878
localAccessor.get_pointer());
7979

80+
T *RawPtr = nullptr;
81+
global_ptr<T> ptr_4(RawPtr);
82+
ptr_4 = RawPtr;
83+
84+
global_ptr<T> ptr_5(accessorData_1);
85+
86+
global_ptr<void> ptr_6((void *)RawPtr);
87+
88+
ptr_6 = (void *)RawPtr;
89+
8090
innerFunc<T>(wiID.get(0), ptr_1, ptr_2, local_ptr);
8191
});
8292
});

0 commit comments

Comments
 (0)