67 template <
typename Expr>
70 return reduce<ReduceOp::Min>(expr);
73 template <
typename Expr>
76 return reduce<ReduceOp::Max>(expr);
79 template <
typename Expr>
82 return reduce<ReduceOp::Sum>(expr);
92 template <ReduceOp Op>
103 template <ReduceOp Op>
115 template <ReduceOp Op>
116 FORCE_INLINE static T reduce_scalar_combine(T a, T b)
noexcept
120 return ScalarK::min(a, b);
122 return ScalarK::max(a, b);
124 return ScalarK::add(a, b);
129 template <ReduceOp Op,
typename Expr>
135 return reduce_contiguous<Op>(expr);
140 return reduce_logical<Op>(expr);
146 template <ReduceOp Op,
typename Expr>
147 FORCE_INLINE static T reduce_contiguous(
const Expr &expr)
noexcept
149 using ExprPadPolicy =
typename Expr::Layout::PadPolicyType;
151 static constexpr my_size_t lastDim = ExprPadPolicy::LastDim;
152 static constexpr my_size_t paddedLastDim = ExprPadPolicy::PaddedLastDim;
153 static constexpr my_size_t numSlices = ExprPadPolicy::PhysicalSize / paddedLastDim;
157 T result = reduce_identity<Op>();
159 if constexpr (simdSteps > 0)
163 for (
my_size_t slice = 0; slice < numSlices; ++slice)
165 const my_size_t base = slice * paddedLastDim;
166 for (
my_size_t i = 0; i < simdSteps; ++i)
167 acc = reduce_simd_combine<Op>(
168 acc, expr.template evalu<T, Bits, Arch>(base + i *
simdWidth));
175 result = reduce_scalar_combine<Op>(result, tmp[i]);
178 if constexpr (scalarStart < lastDim)
180 for (
my_size_t slice = 0; slice < numSlices; ++slice)
182 const my_size_t base = slice * paddedLastDim;
183 for (
my_size_t i = scalarStart; i < lastDim; ++i)
184 result = reduce_scalar_combine<Op>(
185 result, expr.template evalu<T, 1, GENERICARCH>(base + i));
198 template <ReduceOp Op,
typename Expr>
199 FORCE_INLINE static T reduce_logical(
const Expr &expr)
noexcept
201 static constexpr my_size_t totalSize = Expr::TotalSize;
203 T result = reduce_identity<Op>();
205 for (
my_size_t i = 0; i < totalSize; ++i)
206 result = reduce_scalar_combine<Op>(
207 result, expr.template logical_evalu<T, 1, GENERICARCH>(i));