Skip to content

Commit 9757b4f

Browse files
[SYCL] Fix multi_ptr::prefetch regression (#19013)
The regression was introduced in #18839 and the error looks like: ``` /include/sycl/multi_ptr.hpp:397:5: error: no matching function for call to '__spirv_ocl_prefetch' 397 | __spirv_ocl_prefetch(reinterpret_cast<ptr_t>(get_decorated()), NumBytes); /include/sycl/multi_ptr.hpp:397:5: note: candidate function not viable: no known conversion from 'ptr_t' (aka 'const __global char *') to 'const __global signed char *' for 1st argument 397 | __spirv_ocl_prefetch(reinterpret_cast<ptr_t>(get_decorated()), NumBytes); ``` We previously switched to use `__spirv_ocl_prefetch` that is automatically defined by the compiler instead of having its forward-declaration in our headers. However, compiler-provided declaration does not define an overload for plain `char` for some reason. Changing that may trigger some unknown and unwanted side effects, so for the meantime the problem is worked around by using `unsigned char` overload instead which should be safe (from strict aliasing rules point of view).
1 parent 72829cd commit 9757b4f

File tree

2 files changed

+26
-4
lines changed

2 files changed

+26
-4
lines changed

sycl/include/sycl/multi_ptr.hpp

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -391,10 +391,13 @@ class __SYCL_TYPE(multi_ptr) multi_ptr {
391391
access::address_space _Space = Space,
392392
typename = typename std::enable_if_t<
393393
_Space == Space && Space == access::address_space::global_space>>
394-
void prefetch(size_t NumElements) const {
394+
void prefetch([[maybe_unused]] size_t NumElements) const {
395+
#ifdef __SYCL_DEVICE_ONLY__
395396
size_t NumBytes = NumElements * sizeof(ElementType);
396-
using ptr_t = typename detail::DecoratedType<char, Space>::type const *;
397+
using ptr_t =
398+
typename detail::DecoratedType<unsigned char, Space>::type const *;
397399
__spirv_ocl_prefetch(reinterpret_cast<ptr_t>(get_decorated()), NumBytes);
400+
#endif
398401
}
399402

400403
// Arithmetic operators
@@ -1087,10 +1090,13 @@ class multi_ptr<ElementType, Space, access::decorated::legacy> {
10871090
access::address_space _Space = Space,
10881091
typename = typename std::enable_if_t<
10891092
_Space == Space && Space == access::address_space::global_space>>
1090-
void prefetch(size_t NumElements) const {
1093+
void prefetch([[maybe_unused]] size_t NumElements) const {
1094+
#ifdef __SYCL_DEVICE_ONLY__
10911095
size_t NumBytes = NumElements * sizeof(ElementType);
1092-
using ptr_t = typename detail::DecoratedType<char, Space>::type const *;
1096+
using ptr_t =
1097+
typename detail::DecoratedType<unsigned char, Space>::type const *;
10931098
__spirv_ocl_prefetch(reinterpret_cast<ptr_t>(m_Pointer), NumBytes);
1099+
#endif
10941100
}
10951101

10961102
private:
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// RUN: %clangxx -fsycl -fsycl-device-only -fsyntax-only -Xclang -verify %s
2+
// expected-no-diagnostics
3+
4+
#include <sycl/multi_ptr.hpp>
5+
6+
SYCL_EXTERNAL void
7+
foo(sycl::multi_ptr<int, sycl::access::address_space::global_space> mptr) {
8+
mptr.prefetch(0);
9+
}
10+
11+
SYCL_EXTERNAL void
12+
bar(sycl::multi_ptr<int, sycl::access::address_space::global_space,
13+
sycl::access::decorated::legacy>
14+
mptr) {
15+
mptr.prefetch(0);
16+
}

0 commit comments

Comments
 (0)