feat(tulip): implement some more SIMD

This commit is contained in:
2026-11-22 16:41:55 +01:00
parent f98615fea4
commit a8b00b32d2
15 changed files with 333 additions and 18 deletions
+12 -9
View File
@@ -6,6 +6,8 @@
#include "./tensor_shape.hpp"
#include "./tensor_traits.hpp"
#include "./tensor_view.hpp"
#include "tulip/evaluate.hpp"
#include "tulip/simd/traits.hpp"
#include <cstddef>
#include <cstring>
@@ -93,20 +95,14 @@ public:
tensor(E&& exprFwd) { // NOLINT
set_dimensions(exprFwd.shape());
E expr = std::forward<E>(exprFwd);
for (std::size_t i = 0; i < size(); ++i) {
m_items[i] = expr.coeff(i);
}
detail::evaluate_elementwise(m_items, std::forward<E>(exprFwd), size());
}
template <typename E, typename = std::enable_if_t<detail::is_expression_v<E>>>
tensor& operator=(E&& exprFwd) {
set_dimensions(exprFwd.shape());
if (m_shape != exprFwd.shape()) set_dimensions(exprFwd.shape());
E expr = std::forward<E>(exprFwd);
for (std::size_t i = 0; i < view().size(); ++i) {
m_items[i] = expr.coeff(i);
}
detail::evaluate_elementwise(m_items, std::forward<E>(exprFwd), size());
return *this;
}
@@ -225,6 +221,13 @@ public:
const value_type* data() const { return m_items; }
const shape_type& shape() const { return m_shape; }
public:
// WARN: eval_pack does not perform bounds checks!
template <typename Isa>
auto eval_pack(std::size_t idx) noexcept {
using scalar_type = std::remove_cv_t<value_type>;
return simd::detail::load<scalar_type, Isa>(m_items + idx);
}
private:
template <typename... RtDims, std::size_t... Is>
constexpr bool valid_dims(std::index_sequence<Is...>, RtDims... dimensions) const {