Skip to content

Commit 70e003a

Browse files
authored
[SYCL] Fix as() function implementation for a swizzle vector (#2966)
Signed-off-by: mdimakov <[email protected]>
1 parent b96e647 commit 70e003a

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

sycl/include/CL/sycl/types.hpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1817,11 +1817,16 @@ class SwizzleOp {
18171817
return Tmp.template convert<convertT, roundingMode>();
18181818
}
18191819

1820-
template <typename asT>
1821-
typename detail::enable_if_t<asT::getNumElements() == getNumElements(), asT>
1822-
as() const {
1820+
template <typename asT> asT as() const {
18231821
// First materialize the swizzle to vec_t and then apply as() to it.
18241822
vec_t Tmp = *this;
1823+
static_assert((sizeof(Tmp) == sizeof(asT)),
1824+
"The new SYCL vec type must have the same storage size in "
1825+
"bytes as this SYCL swizzled vec");
1826+
static_assert(
1827+
detail::is_contained<asT, detail::gtl::vector_basic_list>::value,
1828+
"asT must be SYCL vec of a different element type and "
1829+
"number of elements specified by asT");
18251830
return Tmp.template as<asT>();
18261831
}
18271832

sycl/test/basic_tests/vectors/vectors.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,12 @@ int main() {
6464
unsigned long long ull_val = ull_vec.template swizzle<cl::sycl::elem::s0>();
6565
assert(ull_val == ull_ref);
6666

67+
// Check that the function as() in swizzle vec class is working correctly
68+
cl::sycl::vec<int8_t, 2> inputVec = cl::sycl::vec<int8_t, 2>(0, 1);
69+
auto asVec =
70+
inputVec.template swizzle<cl::sycl::elem::s0, cl::sycl::elem::s1>()
71+
.template as<cl::sycl::vec<int16_t, 1>>();
72+
6773
// Check that [u]long[n] type aliases match vec<[unsigned] long, n> types.
6874
assert((std::is_same<cl::sycl::vec<long, 2>, cl::sycl::long2>::value));
6975
assert((std::is_same<cl::sycl::vec<long, 3>, cl::sycl::long3>::value));

0 commit comments

Comments
 (0)