Skip to content

Commit

Permalink
[SYCL] Implement broadcasting vec::operator=
Browse files Browse the repository at this point in the history
Signed-off-by: Mariya Podchishchaeva <mariya.podchishchaeva@intel.com>
  • Loading branch information
Fznamznon authored and vladimirlaz committed Apr 4, 2019
1 parent 3e11f59 commit e8ac887
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
22 changes: 22 additions & 0 deletions sycl/include/CL/sycl/types.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -372,12 +372,34 @@ template <typename Type, int NumElements> class vec {
return *this;
}

#ifdef __SYCL_USE_EXT_VECTOR_TYPE__
explicit vec(const DataT &arg) {
m_Data = (DataType)arg;
}

template <typename Ty = DataT>
typename std::enable_if<std::is_fundamental<Ty>::value, vec &>::type
operator=(const DataT &Rhs) {
m_Data = (DataType)Rhs;
return *this;
}
#else
explicit vec(const DataT &arg) {
for (int i = 0; i < NumElements; ++i) {
setValue(i, arg);
}
}

template <typename Ty = DataT>
typename std::enable_if<std::is_fundamental<Ty>::value, vec &>::type
operator=(const DataT &Rhs) {
for (int i = 0; i < NumElements; ++i) {
setValue(i, Rhs);
}
return *this;
}
#endif

#ifdef __SYCL_USE_EXT_VECTOR_TYPE__
// Optimized naive constructors with NumElements of DataT values.
// We don't expect compilers to optimize vararg recursive functions well.
Expand Down
8 changes: 8 additions & 0 deletions sycl/test/basic_tests/vectors.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,5 +50,13 @@ int main() {
int64_t(vec_2.x());
cl::sycl::int4(vec_2.x());

// Check broadcasting operator=
cl::sycl::vec<float, 4> b_vec(1.0);
b_vec = 0.5;
assert(static_cast<float>(b_vec.x()) == static_cast<float>(0.5));
assert(static_cast<float>(b_vec.y()) == static_cast<float>(0.5));
assert(static_cast<float>(b_vec.z()) == static_cast<float>(0.5));
assert(static_cast<float>(b_vec.w()) == static_cast<float>(0.5));

return 0;
}

0 comments on commit e8ac887

Please sign in to comment.