Skip to content

Commit 483984a

Browse files
[SYCL] Add missing generic cast builtin for non-const volatile types (#7505)
The headers use builtins for casting from generic pointers to other address spaces. However, of these definitions it is missing variants for non-const volatile. This commit adds these missing definitions. Signed-off-by: Larsen, Steffen <[email protected]>
1 parent 675148c commit 483984a

File tree

2 files changed

+90
-0
lines changed

2 files changed

+90
-0
lines changed

sycl/include/CL/__spirv/spirv_ops.hpp

+24
Original file line numberDiff line numberDiff line change
@@ -415,6 +415,14 @@ __SYCL_GenericCastToPtrExplicit_ToGlobal(const void *Ptr) noexcept {
415415
Ptr, __spv::StorageClass::CrossWorkgroup);
416416
}
417417

418+
template <typename dataT>
419+
extern volatile __attribute__((opencl_global)) dataT *
420+
__SYCL_GenericCastToPtrExplicit_ToGlobal(volatile void *Ptr) noexcept {
421+
return (volatile __attribute__((opencl_global)) dataT *)
422+
__spirv_GenericCastToPtrExplicit_ToGlobal(
423+
Ptr, __spv::StorageClass::CrossWorkgroup);
424+
}
425+
418426
template <typename dataT>
419427
extern const volatile __attribute__((opencl_global)) dataT *
420428
__SYCL_GenericCastToPtrExplicit_ToGlobal(const volatile void *Ptr) noexcept {
@@ -439,6 +447,14 @@ __SYCL_GenericCastToPtrExplicit_ToLocal(const void *Ptr) noexcept {
439447
__spv::StorageClass::Workgroup);
440448
}
441449

450+
template <typename dataT>
451+
extern volatile __attribute__((opencl_local)) dataT *
452+
__SYCL_GenericCastToPtrExplicit_ToLocal(volatile void *Ptr) noexcept {
453+
return (volatile __attribute__((opencl_local)) dataT *)
454+
__spirv_GenericCastToPtrExplicit_ToLocal(Ptr,
455+
__spv::StorageClass::Workgroup);
456+
}
457+
442458
template <typename dataT>
443459
extern const volatile __attribute__((opencl_local)) dataT *
444460
__SYCL_GenericCastToPtrExplicit_ToLocal(const volatile void *Ptr) noexcept {
@@ -463,6 +479,14 @@ __SYCL_GenericCastToPtrExplicit_ToPrivate(const void *Ptr) noexcept {
463479
__spv::StorageClass::Function);
464480
}
465481

482+
template <typename dataT>
483+
extern volatile __attribute__((opencl_private)) dataT *
484+
__SYCL_GenericCastToPtrExplicit_ToPrivate(volatile void *Ptr) noexcept {
485+
return (volatile __attribute__((opencl_private)) dataT *)
486+
__spirv_GenericCastToPtrExplicit_ToPrivate(Ptr,
487+
__spv::StorageClass::Function);
488+
}
489+
466490
template <typename dataT>
467491
extern const volatile __attribute__((opencl_private)) dataT *
468492
__SYCL_GenericCastToPtrExplicit_ToPrivate(const volatile void *Ptr) noexcept {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
// RUN: %clangxx -fsycl %s -o %t.out
2+
//
3+
// Tests that casting multi_ptr to and from generic compiles for various
4+
// combinations of valid qualifiers.
5+
6+
#include <sycl/sycl.hpp>
7+
8+
using namespace sycl;
9+
10+
template <typename T, access::address_space AddrSpace,
11+
sycl::access::decorated IsDecorated>
12+
void test(queue &Q) {
13+
T *GlobPtr = malloc_device<T>(1, Q);
14+
Q.submit([&](handler &CGH) {
15+
local_accessor<T> LocPtr{1, CGH};
16+
CGH.single_task([=]() {
17+
T X = 0;
18+
T *InPtr;
19+
if constexpr (AddrSpace == access::address_space::global_space)
20+
InPtr = GlobPtr;
21+
else if constexpr (AddrSpace == access::address_space::local_space)
22+
InPtr = LocPtr.get_pointer();
23+
else
24+
InPtr = &X;
25+
26+
auto MPtr = address_space_cast<AddrSpace, IsDecorated>(InPtr);
27+
multi_ptr<T, access::address_space::generic_space, IsDecorated> GenPtr;
28+
GenPtr = MPtr;
29+
MPtr = multi_ptr<T, AddrSpace, IsDecorated>{GenPtr};
30+
});
31+
}).wait();
32+
}
33+
34+
template <typename T, access::address_space AddrSpace>
35+
void testAllDecos(queue &Q) {
36+
test<T, AddrSpace, sycl::access::decorated::yes>(Q);
37+
test<T, AddrSpace, sycl::access::decorated::no>(Q);
38+
}
39+
40+
template <typename T> void testAllAddrSpace(queue &Q) {
41+
testAllDecos<T, access::address_space::private_space>(Q);
42+
testAllDecos<T, access::address_space::local_space>(Q);
43+
testAllDecos<T, access::address_space::global_space>(Q);
44+
}
45+
46+
template <typename T> void testAllQuals(queue &Q) {
47+
using UnqualT = std::remove_cv_t<T>;
48+
testAllAddrSpace<UnqualT>(Q);
49+
testAllAddrSpace<std::add_const_t<UnqualT>>(Q);
50+
testAllAddrSpace<std::add_volatile_t<UnqualT>>(Q);
51+
testAllAddrSpace<std::add_cv_t<UnqualT>>(Q);
52+
}
53+
54+
int main() {
55+
queue Q;
56+
testAllQuals<bool>(Q);
57+
testAllQuals<char>(Q);
58+
testAllQuals<short>(Q);
59+
testAllQuals<int>(Q);
60+
testAllQuals<long>(Q);
61+
testAllQuals<long long>(Q);
62+
testAllQuals<sycl::half>(Q);
63+
testAllQuals<float>(Q);
64+
testAllQuals<double>(Q);
65+
return 0;
66+
}

0 commit comments

Comments
 (0)