From 3fbfeafdd79949ad97f0cacc6250c4df7db44858 Mon Sep 17 00:00:00 2001 From: Andrei Elovikov Date: Tue, 24 Dec 2024 14:25:50 -0800 Subject: [PATCH] [NFCI][SYCL] Remove `vec`/`swizzle`'s `getNumElements` `public` `size()` can be used instead. --- sycl/include/sycl/vector.hpp | 82 ++++++++++++++++++------------------ 1 file changed, 41 insertions(+), 41 deletions(-) diff --git a/sycl/include/sycl/vector.hpp b/sycl/include/sycl/vector.hpp index 3c5e7c3a305b..0e3d5d07f922 100644 --- a/sycl/include/sycl/vector.hpp +++ b/sycl/include/sycl/vector.hpp @@ -180,8 +180,6 @@ class __SYCL_EBO vec private: #endif // __SYCL_DEVICE_ONLY__ - static constexpr int getNumElements() { return NumElements; } - // SizeChecker is needed for vec(const argTN &... args) ctor to validate args. template struct SizeChecker : std::conditional_t, sizeof...(Indexes)> { using DataT = typename VecT::element_type; + +public: + using element_type = DataT; + using value_type = DataT; + + __SYCL2020_DEPRECATED("get_count() is deprecated, please use size() instead") + size_t get_count() const { return size(); } + static constexpr size_t size() noexcept { return sizeof...(Indexes); } + + template + __SYCL2020_DEPRECATED( + "get_size() is deprecated, please use byte_size() instead") + size_t get_size() const { + return byte_size(); + } + + template size_t byte_size() const noexcept { + return sizeof(DataT) * (Num == 3 ? 4 : Num); + } + +private: // Certain operators return a vector with a different element type. Also, the // left and right operand types may differ. CommonDataT selects a result type // based on these types to ensure that the result value can be represented. @@ -579,7 +598,6 @@ class SwizzleOp : public detail::NamedSwizzlesMixinBoth< using CommonDataT = std::conditional_t< sizeof(DataT) >= sizeof(std::common_type_t), DataT, std::common_type_t>; - static constexpr int getNumElements() { return sizeof...(Indexes); } using rel_t = detail::rel_t; using vec_t = vec; @@ -594,7 +612,7 @@ class SwizzleOp : public detail::NamedSwizzlesMixinBoth< template class OperationCurrentT_, int... Idx_> - using NewRelOp = SwizzleOp, + using NewRelOp = SwizzleOp, SwizzleOp, OperationRightT_, OperationCurrentT_, Idx_...>; @@ -608,11 +626,11 @@ class SwizzleOp : public detail::NamedSwizzlesMixinBoth< template using EnableIfOneIndex = typename std::enable_if_t< - 1 == IdxNum && SwizzleOp::getNumElements() == IdxNum, T>; + 1 == IdxNum && SwizzleOp::size() == IdxNum, T>; template using EnableIfMultipleIndexes = typename std::enable_if_t< - 1 != IdxNum && SwizzleOp::getNumElements() == IdxNum, T>; + 1 != IdxNum && SwizzleOp::size() == IdxNum, T>; template using EnableIfScalarType = @@ -633,40 +651,22 @@ class SwizzleOp : public detail::NamedSwizzlesMixinBoth< SwizzleOp, GetOp, GetOp, Indices...>; public: - using element_type = DataT; - using value_type = DataT; - #ifdef __SYCL_DEVICE_ONLY__ using vector_t = typename vec_t::vector_t; #endif // __SYCL_DEVICE_ONLY__ const DataT &operator[](int i) const { - std::array Idxs{Indexes...}; + std::array Idxs{Indexes...}; return (*m_Vector)[Idxs[i]]; } template std::enable_if_t, DataT> &operator[](int i) { - std::array Idxs{Indexes...}; + std::array Idxs{Indexes...}; return (*m_Vector)[Idxs[i]]; } - __SYCL2020_DEPRECATED("get_count() is deprecated, please use size() instead") - size_t get_count() const { return size(); } - static constexpr size_t size() noexcept { return getNumElements(); } - - template - __SYCL2020_DEPRECATED( - "get_size() is deprecated, please use byte_size() instead") - size_t get_size() const { - return byte_size(); - } - - template size_t byte_size() const noexcept { - return sizeof(DataT) * (Num == 3 ? 4 : Num); - } - - template , typename = EnableIfScalarType> operator T() const { @@ -870,7 +870,7 @@ class SwizzleOp : public detail::NamedSwizzlesMixinBoth< __SYCL_RELLOGOP(||, (!detail::is_byte_v && !detail::is_vgenfloat_v)) #undef __SYCL_RELLOGOP - template > SwizzleOp &operator=(const vec &Rhs) { std::array Idxs{Indexes...}; @@ -880,14 +880,14 @@ class SwizzleOp : public detail::NamedSwizzlesMixinBoth< return *this; } - template > + template > SwizzleOp &operator=(const DataT &Rhs) { std::array Idxs{Indexes...}; (*m_Vector)[Idxs[0]] = Rhs; return *this; } - template = true> SwizzleOp &operator=(const DataT &Rhs) { std::array Idxs{Indexes...}; @@ -897,7 +897,7 @@ class SwizzleOp : public detail::NamedSwizzlesMixinBoth< return *this; } - template > + template > SwizzleOp &operator=(DataT &&Rhs) { std::array Idxs{Indexes...}; (*m_Vector)[Idxs[0]] = Rhs; @@ -1049,9 +1049,9 @@ class SwizzleOp : public detail::NamedSwizzlesMixinBoth< template < typename T1, typename T2, typename T3, template class T4, int... T5, - typename = typename std::enable_if_t> + typename = typename std::enable_if_t> SwizzleOp &operator=(const SwizzleOp &Rhs) { - std::array Idxs{Indexes...}; + std::array Idxs{Indexes...}; for (size_t I = 0; I < Idxs.size(); ++I) { (*m_Vector)[Idxs[I]] = Rhs.getValue(I); } @@ -1061,9 +1061,9 @@ class SwizzleOp : public detail::NamedSwizzlesMixinBoth< template < typename T1, typename T2, typename T3, template class T4, int... T5, - typename = typename std::enable_if_t> + typename = typename std::enable_if_t> SwizzleOp &operator=(SwizzleOp &&Rhs) { - std::array Idxs{Indexes...}; + std::array Idxs{Indexes...}; for (size_t I = 0; I < Idxs.size(); ++I) { (*m_Vector)[Idxs[I]] = Rhs.getValue(I); } @@ -1212,7 +1212,7 @@ class SwizzleOp : public detail::NamedSwizzlesMixinBoth< vec convert() const { // First materialize the swizzle to vec_t and then apply convert() to it. vec_t Tmp; - std::array Idxs{Indexes...}; + std::array Idxs{Indexes...}; for (size_t I = 0; I < Idxs.size(); ++I) { Tmp[I] = (*m_Vector)[Idxs[I]]; } @@ -1251,10 +1251,10 @@ class SwizzleOp : public detail::NamedSwizzlesMixinBoth< // or reading values from actual vector. Perform implicit type conversion when // the number of elements == 1 - template + template CommonDataT getValue(EnableIfOneIndex Index) const { if (std::is_same_v, GetOp>) { - std::array Idxs{Indexes...}; + std::array Idxs{Indexes...}; return (*m_Vector)[Idxs[Index]]; } auto Op = OperationCurrentT(); @@ -1262,10 +1262,10 @@ class SwizzleOp : public detail::NamedSwizzlesMixinBoth< m_RightOperation.getValue(Index)); } - template + template DataT getValue(EnableIfMultipleIndexes Index) const { if (std::is_same_v, GetOp>) { - std::array Idxs{Indexes...}; + std::array Idxs{Indexes...}; return (*m_Vector)[Idxs[Index]]; } auto Op = OperationCurrentT(); @@ -1276,7 +1276,7 @@ class SwizzleOp : public detail::NamedSwizzlesMixinBoth< template