10#include "../DeviceView.hpp"
13#include "Eigen/src/Core/Matrix.h"
14#include "Eigen/src/Core/util/Constants.h"
34 template <
class real_T = real>
46 static_assert(
sizeof(UInt32PairIn64) == 8);
61 static_assert(
sizeof(UInt32PairIn64) == 8 &&
sizeof(UInt16QuadIn64) == 8);
63 using t_matrix = Eigen::Matrix<std::remove_cv_t<real_T>, Eigen::Dynamic, Eigen::Dynamic>;
64 using t_map_const = Eigen::Map<const t_matrix, Eigen::Unaligned>;
66 std::conditional_t<std::is_const_v<real_T>,
68 Eigen::Map<t_matrix, Eigen::Unaligned>>;
70 template <
class t_matrices_elem>
74 rowsize bufSiz = matrices.size() + 1;
75 for (
const auto &i : matrices)
77 Eigen::Index mSiz = i.rows() * i.cols();
78 static_assert(std::numeric_limits<Eigen::Index>::digits > std::numeric_limits<uint32_t>::digits);
88 static_assert(
sizeof(real_T) == 8 ||
sizeof(real_T) == 4);
89 static const ptrdiff_t n_real_in_64 = 8 /
sizeof(
real);
94 return (
const_cast<MatrixBatch *
>(
this))->get_kth_64_meta_block(k);
105 return *(uint64_t *)(_buf);
144 template <
class t_matrices_elem>
145 void CompressIn(
const std::vector<t_matrices_elem> &matrices)
148 this->
Size() = uint64_t(matrices.size());
150 uint32_t curOffset = uint32_t(this->
Size()) + 1;
151 for (
size_t i = 0; i < matrices.size(); i++)
153 DNDS_assert(matrices[i].rows() <= Eigen::Index(UINT16_MAX));
154 DNDS_assert(matrices[i].cols() <= Eigen::Index(UINT16_MAX));
160 static_assert(std::numeric_limits<Eigen::Index>::digits > std::numeric_limits<uint32_t>::digits);
161 DNDS_assert(matrices[i].size() <= Eigen::Index(UINT32_MAX - curOffset));
162 curOffset += matrices[i].size();
172 return {_buf + offset, n_row, n_col};
182 return {_buf + offset, n_row, n_col};
186 template <DeviceBackend B,
class real_T>
191 using t_base::t_base;
Core type aliases, constants, and metaprogramming utilities for the DNDS framework.
#define DNDS_DEVICE_TRIVIAL_COPY_DEFINE(T, T_Self)
#define DNDS_DEVICE_CALLABLE
Device memory abstraction layer with backend-specific storage and factory creation.
#define DNDS_assert(expr)
Debug-only assertion (compiled out when DNDS_NDEBUG is defined). Prints the expression + file/line + ...
Non-owning device-callable view of an Array, specialised per DeviceBackend.
DNDS_DEVICE_CALLABLE MatrixBatch< real_T > operator[](index i)
typename MatrixBatch< real_T >::t_matrix t_matrix
DNDS_DEVICE_CALLABLE MatrixBatch< const real_T > operator[](index i) const
typename MatrixBatch< real_T >::t_map_const t_map_const
DNDS_DEVICE_CALLABLE t_map_const operator()(index i, rowsize j) const
typename MatrixBatch< real_T >::t_map t_map
DNDS_DEVICE_CALLABLE index BatchSize(index i)
DNDS_DEVICE_CALLABLE t_map operator()(index i, rowsize j)
T * operator[](index iRow)
Raw row pointer. iRow == Size() is allowed for past-the-end queries (useful for computing buffer end ...
DNDS_DEVICE_CALLABLE rowsize RowSize() const
Uniform row width for fixed layouts (asserts otherwise).
Packed variable-shape matrix-batch layout inside a flat buffer.
void CompressIn(const std::vector< t_matrices_elem > &matrices)
DNDS_DEVICE_CALLABLE uint32_t getOffset(rowsize k) const
DNDS_DEVICE_CALLABLE uint16_t getNCol(rowsize k) const
Eigen::Matrix< std::remove_cv_t< real_T >, Eigen::Dynamic, Eigen::Dynamic > t_matrix
static rowsize getBufSize(const std::vector< t_matrices_elem > &matrices)
DNDS_DEVICE_CALLABLE uint64_t & Size() const
Eigen::Map< const t_matrix, Eigen::Unaligned > t_map_const
DNDS_DEVICE_CALLABLE void setOffset(rowsize k, uint32_t v)
DNDS_DEVICE_CALLABLE MatrixBatch(real_T *n_buf, rowsize new_size)
DNDS_DEVICE_CALLABLE uint16_t getNRow(rowsize k) const
DNDS_DEVICE_CALLABLE t_map_const operator[](rowsize k) const
std::conditional_t< std::is_const_v< real_T >, t_map_const, Eigen::Map< t_matrix, Eigen::Unaligned > > t_map
DNDS_DEVICE_CALLABLE void setNCol(rowsize k, uint16_t v)
DNDS_DEVICE_CALLABLE void setNRow(rowsize k, uint16_t v)
DNDS_DEVICE_CALLABLE t_map operator[](rowsize k)
the host side operators are provided as implemented
int32_t rowsize
Row-width / per-row element-count type (signed 32-bit).
int64_t index
Global row / DOF index type (signed 64-bit; handles multi-billion-cell meshes).
double real
Canonical floating-point scalar used throughout DNDSR (double precision).
DNDS_DEVICE_CALLABLE void setA(uint16_t v)
DNDS_DEVICE_CALLABLE void setD(uint16_t v)
DNDS_DEVICE_CALLABLE void setC(uint16_t v)
DNDS_DEVICE_CALLABLE uint16_t getC() const
DNDS_DEVICE_CALLABLE uint16_t getB() const
DNDS_DEVICE_CALLABLE uint16_t getA() const
DNDS_DEVICE_CALLABLE void setB(uint16_t v)
DNDS_DEVICE_CALLABLE uint16_t getD() const
DNDS_DEVICE_CALLABLE uint32_t getM() const
DNDS_DEVICE_CALLABLE void setN(uint32_t v)
DNDS_DEVICE_CALLABLE uint32_t getN() const
DNDS_DEVICE_CALLABLE void setM(uint32_t v)
Eigen::Matrix< real, 5, 1 > v