12#ifndef ARCANE_ACCELERATOR_MDVARIABLEVIEWS_H
13#define ARCANE_ACCELERATOR_MDVARIABLEVIEWS_H
17#include "arcane/utils/ArrayLayout.h"
32template <
typename ItemType_,
typename Accessor_,
typename Extents_>
33class MeshMDVariableViewBase
35 using Accessor = Accessor_;
36 using AddedFirstExtentsType =
typename Extents_::template AddedFirstExtentsType<DynExtent>;
40 using ItemType = ItemType_;
41 using DataType = Accessor::ValueType;
42 using AccessorReturnType = Accessor::AccessorReturnType;
43 using Extents = Extents_;
44 using ItemLocalIdType = ItemType::LocalIdType;
52 explicit constexpr ARCCORE_HOST_DEVICE MeshMDVariableViewBase(
const MDSpanType& v)
59 constexpr ARCCORE_HOST_DEVICE AccessorReturnType operator()(ItemLocalIdType
id)
const
60 requires(Extents::rank() == 0)
62 return Accessor::build(m_mdspan.ptrAt(
id.localId()));
64 constexpr ARCCORE_HOST_DEVICE AccessorReturnType operator()(ItemLocalIdType
id,
Int32 i1)
const
65 requires(Extents::rank() == 1)
67 return Accessor::build(m_mdspan.ptrAt(
id.localId(), i1));
70 constexpr ARCCORE_HOST_DEVICE AccessorReturnType operator()(ItemLocalIdType
id,
Int32 i1,
Int32 i2)
const
71 requires(Extents::rank() == 2)
73 return Accessor::build(m_mdspan.ptrAt(
id.localId(), i1, i2));
76 constexpr ARCCORE_HOST_DEVICE AccessorReturnType operator()(ItemLocalIdType
id,
Int32 i,
Int32 j,
Int32 k)
const
77 requires(Extents::rank() == 3)
79 return Accessor::build(m_mdspan.ptrAt(
id.localId(), i, j, k));
92template <
typename ItemType_,
typename DataType_,
typename Extents>
93class MeshMDVariableInView
94:
protected MeshMDVariableViewBase<ItemType_, DataViewGetter<DataType_>, Extents>
96 using BaseClass = MeshMDVariableViewBase<ItemType_, DataViewGetter<DataType_>, Extents>;
100 using ItemType = ItemType_;
101 using DataType = DataType_;
102 using ExtentsType = Extents;
103 using ItemLocalIdType = ItemType::LocalIdType;
106 using BaseClass::operator();
110 using MDSpanType = VariableRefType::MDSpanType;
114 MeshMDVariableInView(
const ViewBuildInfo& view_bi,
const VariableRefType& var_ref)
115 : BaseClass(var_ref.m_mdspan)
127template <
typename ItemType_,
typename DataType_,
typename Extents>
128class MeshMDVariableInOutView
129:
protected MeshMDVariableViewBase<ItemType_, DataViewGetterSetter<DataType_>, Extents>
131 using BaseClass = MeshMDVariableViewBase<ItemType_, DataViewGetterSetter<DataType_>, Extents>;
135 using ItemType = ItemType_;
136 using DataType = DataType_;
137 using ExtentsType = Extents;
138 using ItemLocalIdType = ItemType::LocalIdType;
141 using BaseClass::operator();
145 using MDSpanType = VariableRefType::MDSpanType;
149 MeshMDVariableInOutView(
const ViewBuildInfo& view_bi, VariableRefType& var_ref)
150 : BaseClass(var_ref.m_mdspan)
167template <
typename ItemType_,
typename MatrixAccessor_,
typename Extents>
168class MeshMatrixMDVariableViewBase
170 using AddedFirstExtentsType =
typename Extents::template AddedFirstExtentsType<DynExtent>;
174 using ItemType = ItemType_;
175 using MatrixAccessor = MatrixAccessor_;
176 using MatrixElementAccessor = MatrixAccessor_::MatrixElemenAccessor;
177 using NumMatrixType = MatrixAccessor::NumMatrixType;
178 using MatrixAccessorReturnType = MatrixAccessor::AccessorReturnType;
179 using MatrixElementAccessorReturnType = MatrixElementAccessor::AccessorReturnType;
180 using ItemLocalIdType = ItemType::LocalIdType;
188 MeshMatrixMDVariableViewBase(
const MDSpanType& matrix_mdspan)
189 : m_matrix_mdspan(matrix_mdspan)
199 constexpr ARCCORE_HOST_DEVICE MatrixAccessorReturnType
operator()(ItemLocalIdType
id)
const
200 requires(Extents::rank() == 0)
202 return MatrixAccessor::build(m_matrix_mdspan.ptrAt(
id.localId()));
206 constexpr ARCCORE_HOST_DEVICE MatrixElementAccessorReturnType
operator()(ItemLocalIdType
id,
Int32 i,
Int32 j)
const
207 requires(Extents::rank() == 0)
209 return MatrixElementAccessor::build(&m_matrix_mdspan(
id.localId())(i, j));
215 constexpr ARCCORE_HOST_DEVICE MatrixAccessorReturnType
operator()(ItemLocalIdType
id,
Int32 index)
const
216 requires(Extents::rank() == 1)
218 return MatrixAccessor::build(m_matrix_mdspan.
ptrAt(
id.localId(), index));
223 requires(Extents::rank() == 1)
225 return MatrixElementAccessor::build(&m_matrix_mdspan(
id.localId(), index)(i, j));
231 MDSpanType m_matrix_mdspan;
239template <
typename ItemType_,
typename DataType_,
int Row,
int Column,
typename Extents>
240class MeshMatrixMDVariableInView
241:
public MeshMatrixMDVariableViewBase<ItemType_, NumMatrixDataViewGetter<DataType_, Row, Column>, Extents>
243 using BaseClass = MeshMatrixMDVariableViewBase<ItemType_, NumMatrixDataViewGetter<DataType_, Row, Column>, Extents>;
247 using ItemType = ItemType_;
248 using DataType = DataType_;
249 using ItemLocalIdType = ItemType::LocalIdType;
255 using MDSpanType = VariableRefType::MDSpanType;
259 MeshMatrixMDVariableInView(
const ViewBuildInfo& view_bi,
const VariableRefType& var_ref)
260 : BaseClass(var_ref.m_matrix_mdspan)
272template <
typename ItemType_,
typename DataType_,
int Row,
int Column,
typename Extents>
273class MeshMatrixMDVariableInOutView
274:
public MeshMatrixMDVariableViewBase<ItemType_, NumMatrixDataViewGetterSetter<DataType_, Row, Column>, Extents>
276 using BaseClass = MeshMatrixMDVariableViewBase<ItemType_, NumMatrixDataViewGetterSetter<DataType_, Row, Column>, Extents>;
280 using ItemType = ItemType_;
281 using DataType = DataType_;
282 using ItemLocalIdType = ItemType::LocalIdType;
288 using MDSpanType = VariableRefType::MDSpanType;
292 MeshMatrixMDVariableInOutView(
const ViewBuildInfo& view_bi,
const VariableRefType& var_ref)
293 : BaseClass(var_ref.m_matrix_mdspan)
305template <
typename ItemType,
typename DataType,
int Row,
int Column,
typename Extents>
316template <
typename ItemType,
typename DataType,
typename Extents>
327template <
typename ItemType,
typename DataType,
int Row,
int Column,
typename Extents>
338template <
typename ItemType,
typename DataType,
typename Extents>
Read-write view of multi-dimensional variable over a mesh item.
Read-only view of multi-dimensional variable over a mesh item.
Read-write view of multi-dimensional matrix variable over a mesh item.
Read-only view of multi-dimensional matrix variable over a mesh item.
constexpr __host__ __device__ MatrixElementAccessorReturnType operator()(ItemLocalIdType id, Int32 i, Int32 j) const
accessor for the element (i,j) of the matrix for item id
constexpr __host__ __device__ MatrixElementAccessorReturnType operator()(ItemLocalIdType id, Int32 index, Int32 i, Int32 j) const
Accessor for the element (i,j) of the matrix for item id and index index.
constexpr __host__ __device__ MatrixAccessorReturnType operator()(ItemLocalIdType id) const
Accessor of the matrix for item id.
Base class for variable views.
Information to build a view for accelerator data.
Base class for multidimensional views.
constexpr DataType * ptrAt(ExtentIndexType i, ExtentIndexType j, ExtentIndexType k, ExtentIndexType l) const
Pointer to the value for element i,j,k,l.
const UnderlyingVariableType & underlyingVariable() const
Associated underlying variable.
Class managing a multi-dimensional variable on a mesh entity.
Class managing a multi-dimensional NumMatrix type variable on a mesh entity.
Read-only view for a NumMatrix<DataType_,Row,Column>.
IVariable * variable() const
Associated variable.
Namespace for accelerator usage.
auto viewInOut(const ViewBuildInfo &vbi, CellMaterialVariableScalarRef< DataType > &var)
Read/write view for scalar material variables.
auto viewIn(const ViewBuildInfo &vbi, const CellMaterialVariableScalarRef< DataType > &var)
Read view for scalar material variables.
std::int32_t Int32
Signed integer type of 32 bits.