Skip to content

Commit

Permalink
[SYCL] Implement SYCL 2020 multi_ptr (#6893)
Browse files Browse the repository at this point in the history
This commit adds implementations of [SYCL 2020
`multi_ptr`](https://registry.khronos.org/SYCL/specs/sycl-2020/html/sycl-2020.html#sec:multiptr)
and `address_space_cast`. Likewise it adds the `legacy` decoration for
SYCL 1.2.1 style `multi_ptr` as deprecated.
To prevent breaking user code the legacy decoration is made the default.

Test-suite changes: intel/llvm-test-suite#1293

Signed-off-by: Larsen, Steffen <steffen.larsen@intel.com>
  • Loading branch information
steffenlarsen committed Oct 13, 2022
1 parent c657d06 commit 8700b76
Show file tree
Hide file tree
Showing 35 changed files with 1,685 additions and 507 deletions.
6 changes: 6 additions & 0 deletions clang/lib/Sema/SPIRVBuiltins.td
Expand Up @@ -840,6 +840,12 @@ foreach AS = [GlobalAS, LocalAS, PrivateAS] in {
def : SPVBuiltin<"GenericCastToPtrExplicit", [PointerType<Char, AS>, PointerType<Char, GenericAS>], Attr.Const>;
}

foreach Ty = [Void, ConstType<Void>, VolatileType<Void>, VolatileType<ConstType<Void>>] in {
def : SPVBuiltin<"GenericCastToPtrExplicit_ToGlobal", [PointerType<Ty, GlobalAS>, PointerType<Ty, DefaultAS>, Int], Attr.Const>;
def : SPVBuiltin<"GenericCastToPtrExplicit_ToLocal", [PointerType<Ty, LocalAS>, PointerType<Ty, DefaultAS>, Int], Attr.Const>;
def : SPVBuiltin<"GenericCastToPtrExplicit_ToPrivate", [PointerType<Ty, PrivateAS>, PointerType<Ty, DefaultAS>, Int], Attr.Const>;
}

foreach Type = TLFloat.List in {
foreach v = [2, 3, 4, 8, 16] in {
def : SPVBuiltin<"VectorTimesScalar", [VectorType<Type, v>, VectorType<Type, v>, Type], Attr.Const>;
Expand Down
Expand Up @@ -78,8 +78,8 @@ location at `src` + `get_local_id()`.

[source,c++]
----
template <typename T, access::address_space Space>
T load(const multi_ptr<T, Space>* src)
template <typename T, access::address_space Space, access::decorated IsDecorated>
T load(const multi_ptr<T, Space, IsDecorated>* src)
----
_Constraints_: `T` must be a _NumericType_. `Space` must be
`access::address_space::global_space` or `access::address_space::local_space`.
Expand All @@ -92,8 +92,8 @@ location at `src` + `get_local_id()`.

[source,c++]
----
template <int N, typename T, access::address_space Space>
vec<T, N> load(const multi_ptr<T, Space> src)
template <int N, typename T, access::address_space Space, access::decorated IsDecorated>
vec<T, N> load(const multi_ptr<T, Space, IsDecorated> src)
----
_Constraints_: `T` must be a _NumericType_. `Space` must be
`access::address_space::global_space` or `access::address_space::local_space`.
Expand Down Expand Up @@ -122,8 +122,8 @@ _Effects_: Writes the value of `x` from each work-item to the memory location at

[source,c++]
----
template <typename T, access::address_space Space>
void store(multi_ptr<T, Space> dst, const T& x)
template <typename T, access::address_space Space, access::decorated IsDecorated>
void store(multi_ptr<T, Space, IsDecorated> dst, const T& x)
----
_Constraints_: `T` must be a _NumericType_. `Space` must be
`access::address_space::global_space` or `access::address_space::local_space`.
Expand All @@ -136,8 +136,8 @@ _Effects_: Writes the value of `x` from each work-item to the memory location at

[source,c++]
----
template <typename T, access::address_space Space>
void store(multi_ptr<T, Space> dst, const vec<T, N>& x)
template <typename T, access::address_space Space, access::decorated IsDecorated>
void store(multi_ptr<T, Space, IsDecorated> dst, const vec<T, N>& x)
----
_Constraints_: `T` must be a _NumericType_. `Space` must be
`access::address_space::global_space` or `access::address_space::local_space`.
Expand Down
10 changes: 6 additions & 4 deletions sycl/doc/extensions/experimental/sycl_ext_oneapi_matrix.asciidoc
Expand Up @@ -130,9 +130,10 @@ IMPORTANT: In the current implementation, only the subgroup scope is supported.
namespace sycl::ext::oneapi::experimental::matrix {
template <typename Group, typename T, size_t NumRows, size_t NumCols,
matrix_layout Layout,
access::address_space Space>
access::address_space Space,
access::decorated IsDecorated>
void joint_matrix_load(Group sg, joint_matrix<T, NumRows, NumCols, Layout, Group> &res,
multi_ptr<T, Space> src, size_t stride, matrix_layout MemLayout);
multi_ptr<T, Space, IsDecorated> src, size_t stride, matrix_layout MemLayout);
}
```
This function loads data from memory to the 2d tiles/registers of Intel AMX/DPAS.
Expand All @@ -143,9 +144,10 @@ This function loads data from memory to the 2d tiles/registers of Intel AMX/DPAS
namespace sycl::ext::oneapi::experimental::matrix {
template <typename Group, typename T, size_t NumRows, size_t NumCols,
matrix_layout L,
access::address_space Space>
access::address_space Space,
access::decorated IsDecorated>
void joint_matrix_store(Group sg, joint_matrix<T, NumRows, NumCols, L, Group> &res,
multi_ptr<T, Space> src, size_t stride, matrix_layout memL);
multi_ptr<T, Space, IsDecorated> src, size_t stride, matrix_layout memL);
}
```
This function stores the data from the 2d tiles back to memory.
Expand Down
68 changes: 58 additions & 10 deletions sycl/include/CL/__spirv/spirv_ops.hpp
Expand Up @@ -328,30 +328,78 @@ __SPIRV_ATOMICS(__SPIRV_ATOMIC_MINMAX, Max)
#undef __SPIRV_ATOMIC_UNSIGNED
#undef __SPIRV_ATOMIC_XOR

extern SYCL_EXTERNAL __attribute__((opencl_global)) void *
__spirv_GenericCastToPtrExplicit_ToGlobal(const void *Ptr,
__spv::StorageClass::Flag S) noexcept;

extern SYCL_EXTERNAL __attribute__((opencl_local)) void *
__spirv_GenericCastToPtrExplicit_ToLocal(const void *Ptr,
__spv::StorageClass::Flag S) noexcept;

template <typename dataT>
extern __attribute__((opencl_global)) dataT *
__SYCL_GenericCastToPtrExplicit_ToGlobal(const void *Ptr) noexcept {
__SYCL_GenericCastToPtrExplicit_ToGlobal(void *Ptr) noexcept {
return (__attribute__((opencl_global)) dataT *)
__spirv_GenericCastToPtrExplicit_ToGlobal(
Ptr, __spv::StorageClass::CrossWorkgroup);
}

template <typename dataT>
extern const __attribute__((opencl_global)) dataT *
__SYCL_GenericCastToPtrExplicit_ToGlobal(const void *Ptr) noexcept {
return (const __attribute__((opencl_global)) dataT *)
__spirv_GenericCastToPtrExplicit_ToGlobal(
Ptr, __spv::StorageClass::CrossWorkgroup);
}

template <typename dataT>
extern const volatile __attribute__((opencl_global)) dataT *
__SYCL_GenericCastToPtrExplicit_ToGlobal(const volatile void *Ptr) noexcept {
return (const volatile __attribute__((opencl_global)) dataT *)
__spirv_GenericCastToPtrExplicit_ToGlobal(
Ptr, __spv::StorageClass::CrossWorkgroup);
}

template <typename dataT>
extern __attribute__((opencl_local)) dataT *
__SYCL_GenericCastToPtrExplicit_ToLocal(const void *Ptr) noexcept {
__SYCL_GenericCastToPtrExplicit_ToLocal(void *Ptr) noexcept {
return (__attribute__((opencl_local)) dataT *)
__spirv_GenericCastToPtrExplicit_ToLocal(Ptr,
__spv::StorageClass::Workgroup);
}

template <typename dataT>
extern const __attribute__((opencl_local)) dataT *
__SYCL_GenericCastToPtrExplicit_ToLocal(const void *Ptr) noexcept {
return (const __attribute__((opencl_local)) dataT *)
__spirv_GenericCastToPtrExplicit_ToLocal(Ptr,
__spv::StorageClass::Workgroup);
}

template <typename dataT>
extern const volatile __attribute__((opencl_local)) dataT *
__SYCL_GenericCastToPtrExplicit_ToLocal(const volatile void *Ptr) noexcept {
return (const volatile __attribute__((opencl_local)) dataT *)
__spirv_GenericCastToPtrExplicit_ToLocal(Ptr,
__spv::StorageClass::Workgroup);
}

template <typename dataT>
extern __attribute__((opencl_private)) dataT *
__SYCL_GenericCastToPtrExplicit_ToPrivate(void *Ptr) noexcept {
return (__attribute__((opencl_private)) dataT *)
__spirv_GenericCastToPtrExplicit_ToPrivate(Ptr,
__spv::StorageClass::Function);
}

template <typename dataT>
extern const __attribute__((opencl_private)) dataT *
__SYCL_GenericCastToPtrExplicit_ToPrivate(const void *Ptr) noexcept {
return (const __attribute__((opencl_private)) dataT *)
__spirv_GenericCastToPtrExplicit_ToPrivate(Ptr,
__spv::StorageClass::Function);
}

template <typename dataT>
extern const volatile __attribute__((opencl_private)) dataT *
__SYCL_GenericCastToPtrExplicit_ToPrivate(const volatile void *Ptr) noexcept {
return (const volatile __attribute__((opencl_private)) dataT *)
__spirv_GenericCastToPtrExplicit_ToPrivate(Ptr,
__spv::StorageClass::Function);
}

template <typename dataT>
__SYCL_CONVERGENT__ extern SYCL_EXTERNAL dataT
__spirv_SubgroupShuffleINTEL(dataT Data, uint32_t InvocationId) noexcept;
Expand Down

0 comments on commit 8700b76

Please sign in to comment.