Skip to content

Commit 01351f1

Browse files
authored
[ESIMD] Replace mask_type_t with simd_mask to represent Gen predicates. (#4230)
* [SYCL][ESIMD] Replace mask_type_t with simd_mask to represent Gen predicates. Addresses the following review comment from simd.hpp: // TODO @rolandschulz, @mattkretz // Introduce simd_mask type and let user use this type instead of specific // type representation (simd<uint16_t, N>) to make it more portable // TODO @iburyl should be mask_type_t, which might become more abstracted in // the future revisions. // Gen predicates (masks) used to be represented with simd<unsigned short, N> types which made them indistinguishable from simd objects forcing the same same sets of available APIs, even though it did not always make sense. This patch introduces a new class simd_mask, which provides its own set of APIs, some of which are unique, other - repeat those from the simd class. A new class 'simd_obj_impl' is added, which encompasses functionality common between simd and simd_mask objects. Particularly, view creation APIs (select, bit_cast_view), object construction APIs - replicate, memory I/O (copy from/to) and others. simd and simd_mask both extend the simd_obj_impl class. They use the 'curiously recurring template' design pattern, when simd_obj_impl is templated by its derivative class (simd or simd_mask), to allow simd_obj_impl APIs return subclass objects rather than simd_obj_impl instances, those avoiding API duplication in subclasses. For example, 'select' functions defined in simd_obj_impl, will return a view of the derived class (subclass) rather than a view of simd_obj_impl: simd_view<Derived,...>, where Derived is the derived class. APIs unique to simd_mask: - unary logical negation '!' operator - implicit conversion to bool for single-element masks - logical binary operators '||' and '&&' APIs unique to simd: - binary arithmetic operators ('+', '-', '*', '/') and corresponding compound assignments - unary arithmetic operators ('+', '-', '++', '--') - relational operators ('<', '<=', '>', '>=') The same division of the APIs to unique sets applies to simd_view<simd<...>,...> and simd_view<simd_mask<...>,...> simd_view class specializations. Signed-off-by: kbobrovs <[email protected]>
1 parent 0d3cc99 commit 01351f1

29 files changed

+2815
-1210
lines changed

llvm/lib/SYCLLowerIR/LowerESIMD.cpp

+9-2
Original file line numberDiff line numberDiff line change
@@ -1350,11 +1350,18 @@ SmallPtrSet<Type *, 4> collectGenXVolatileTypes(Module &M) {
13501350
continue;
13511351
auto GTy = dyn_cast<StructType>(PTy->getPointerElementType());
13521352
// TODO FIXME relying on type name in LLVM IR is fragile, needs rework
1353-
if (!GTy || !GTy->getName().endswith(
1354-
"cl::sycl::ext::intel::experimental::esimd::simd"))
1353+
if (!GTy ||
1354+
!GTy->getName().endswith("sycl::ext::intel::experimental::esimd::simd"))
13551355
continue;
13561356
assert(GTy->getNumContainedTypes() == 1);
13571357
auto VTy = GTy->getContainedType(0);
1358+
if (GTy = dyn_cast<StructType>(VTy)) {
1359+
assert(
1360+
GTy &&
1361+
GTy->getName().endswith(
1362+
"sycl::ext::intel::experimental::esimd::detail::simd_obj_impl"));
1363+
VTy = GTy->getContainedType(0);
1364+
}
13581365
assert(VTy->isVectorTy());
13591366
GenXVolatileTypeSet.insert(VTy);
13601367
}

llvm/lib/SYCLLowerIR/LowerESIMDVecArg.cpp

+10-6
Original file line numberDiff line numberDiff line change
@@ -110,14 +110,18 @@ ModulePass *llvm::createESIMDLowerVecArgPass() {
110110
// nullptr.
111111
Type *ESIMDLowerVecArgPass::getSimdArgPtrTyOrNull(Value *arg) {
112112
auto ArgType = dyn_cast<PointerType>(arg->getType());
113-
if (!ArgType || !ArgType->getElementType()->isStructTy())
113+
if (!ArgType)
114114
return nullptr;
115-
auto ContainedType = ArgType->getElementType();
116-
if ((ContainedType->getStructNumElements() != 1) ||
117-
!ContainedType->getStructElementType(0)->isVectorTy())
115+
Type *Res = nullptr;
116+
StructType *ST = dyn_cast_or_null<StructType>(ArgType->getElementType());
117+
118+
while (ST && (ST->getStructNumElements() == 1)) {
119+
Res = ST->getStructElementType(0);
120+
ST = dyn_cast<StructType>(Res);
121+
}
122+
if (!Res || !Res->isVectorTy())
118123
return nullptr;
119-
return PointerType::get(ContainedType->getStructElementType(0),
120-
ArgType->getPointerAddressSpace());
124+
return PointerType::get(Res, ArgType->getPointerAddressSpace());
121125
}
122126

123127
// F may have multiple arguments of type simd*. This

sycl/include/sycl/ext/intel/experimental/esimd/detail/intrin.hpp

+4-10
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,6 @@
1818
#include <assert.h>
1919
#include <cstdint>
2020

21-
#define __SEIEED sycl::ext::intel::experimental::esimd::detail
22-
#define __SEIEE sycl::ext::intel::experimental::esimd
23-
2421
// \brief __esimd_rdregion: region access intrinsic.
2522
//
2623
// @param T the element data type, one of i8, i16, i32, i64, half, float,
@@ -125,14 +122,14 @@ template <typename T, int N, int M, int VStride, int Width, int Stride,
125122
SYCL_EXTERNAL SYCL_ESIMD_FUNCTION __SEIEED::vector_type_t<T, N>
126123
__esimd_wrregion(__SEIEED::vector_type_t<T, N> OldVal,
127124
__SEIEED::vector_type_t<T, M> NewVal, uint16_t Offset,
128-
__SEIEE::mask_type_t<M> Mask = 1);
125+
__SEIEED::simd_mask_storage_t<M> Mask = 1);
129126

130127
template <typename T, int N, int M, int ParentWidth = 0>
131128
SYCL_EXTERNAL SYCL_ESIMD_FUNCTION __SEIEED::vector_type_t<T, N>
132129
__esimd_wrindirect(__SEIEED::vector_type_t<T, N> OldVal,
133130
__SEIEED::vector_type_t<T, M> NewVal,
134131
__SEIEED::vector_type_t<uint16_t, M> Offset,
135-
__SEIEE::mask_type_t<M> Mask = 1);
132+
__SEIEED::simd_mask_storage_t<M> Mask = 1);
136133

137134
__SYCL_INLINE_NAMESPACE(cl) {
138135
namespace sycl {
@@ -286,7 +283,7 @@ template <typename T, int N, int M, int VStride, int Width, int Stride,
286283
SYCL_EXTERNAL SYCL_ESIMD_FUNCTION __SEIEED::vector_type_t<T, N>
287284
__esimd_wrregion(__SEIEED::vector_type_t<T, N> OldVal,
288285
__SEIEED::vector_type_t<T, M> NewVal, uint16_t Offset,
289-
__SEIEE::mask_type_t<M> Mask) {
286+
__SEIEED::simd_mask_storage_t<M> Mask) {
290287
uint16_t EltOffset = Offset / sizeof(T);
291288
assert(Offset % sizeof(T) == 0);
292289

@@ -310,7 +307,7 @@ SYCL_EXTERNAL SYCL_ESIMD_FUNCTION __SEIEED::vector_type_t<T, N>
310307
__esimd_wrindirect(__SEIEED::vector_type_t<T, N> OldVal,
311308
__SEIEED::vector_type_t<T, M> NewVal,
312309
__SEIEED::vector_type_t<uint16_t, M> Offset,
313-
__SEIEE::mask_type_t<M> Mask) {
310+
__SEIEED::simd_mask_storage_t<M> Mask) {
314311
__SEIEED::vector_type_t<T, N> Result = OldVal;
315312
for (int i = 0; i < M; ++i) {
316313
if (Mask[i]) {
@@ -324,6 +321,3 @@ __esimd_wrindirect(__SEIEED::vector_type_t<T, N> OldVal,
324321
}
325322

326323
#endif // __SYCL_DEVICE_ONLY__
327-
328-
#undef __SEIEE
329-
#undef __SEIEED

sycl/include/sycl/ext/intel/experimental/esimd/detail/math_intrin.hpp

+1-8
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,10 @@
1515
#include <sycl/ext/intel/experimental/esimd/common.hpp>
1616
#include <sycl/ext/intel/experimental/esimd/detail/host_util.hpp>
1717
#include <sycl/ext/intel/experimental/esimd/detail/types.hpp>
18+
#include <sycl/ext/intel/experimental/esimd/detail/util.hpp>
1819

1920
#include <cstdint>
2021

21-
#define __SEIEED sycl::ext::intel::experimental::esimd::detail
22-
2322
// saturation intrinsics
2423
template <typename T0, typename T1, int SZ>
2524
SYCL_EXTERNAL SYCL_ESIMD_FUNCTION __SEIEED::vector_type_t<T0, SZ>
@@ -385,8 +384,6 @@ inline T extract(const uint32_t &width, const uint32_t &offset, uint32_t src,
385384
return ret;
386385
}
387386

388-
#define __SEIEEED sycl::ext::intel::experimental::esimd::emu::detail
389-
390387
template <typename T0, typename T1, int SZ>
391388
inline __SEIEED::vector_type_t<T0, SZ>
392389
__esimd_satf(__SEIEED::vector_type_t<T1, SZ> src) {
@@ -1327,8 +1324,4 @@ __esimd_reduced_smin(__SEIEED::vector_type_t<Ty, N> src1,
13271324
return __esimd_reduced_min<Ty, N>(src1, src2);
13281325
}
13291326

1330-
#undef __SEIEEED
1331-
13321327
#endif // #ifdef __SYCL_DEVICE_ONLY__
1333-
1334-
#undef __SEIEED

0 commit comments

Comments
 (0)