12#ifndef ARCANE_ACCELERATOR_MDVARIABLEVIEWS_H
13#define ARCANE_ACCELERATOR_MDVARIABLEVIEWS_H
17#include "arcane/utils/ArrayLayout.h"
21#include "arccore/common/NumMatrixDataView.h"
22#include "arccore/common/NumVectorDataView.h"
35template <
typename ItemType_,
typename Accessor_,
typename Extents_>
36class MeshMDVariableViewBase
38 using Accessor = Accessor_;
39 using AddedFirstExtentsType =
typename Extents_::template AddedFirstExtentsType<DynExtent>;
43 using ItemType = ItemType_;
44 using DataType = Accessor::ValueType;
45 using AccessorReturnType = Accessor::AccessorReturnType;
46 using Extents = Extents_;
47 using ItemLocalIdType = ItemType::LocalIdType;
55 explicit constexpr ARCCORE_HOST_DEVICE MeshMDVariableViewBase(
const MDSpanType& v)
62 constexpr ARCCORE_HOST_DEVICE AccessorReturnType operator()(ItemLocalIdType
id)
const
63 requires(Extents::rank() == 0)
65 return Accessor::build(m_mdspan.ptrAt(
id.localId()));
67 constexpr ARCCORE_HOST_DEVICE AccessorReturnType operator()(ItemLocalIdType
id,
Int32 i1)
const
68 requires(Extents::rank() == 1)
70 return Accessor::build(m_mdspan.ptrAt(
id.localId(), i1));
73 constexpr ARCCORE_HOST_DEVICE AccessorReturnType operator()(ItemLocalIdType
id,
Int32 i1,
Int32 i2)
const
74 requires(Extents::rank() == 2)
76 return Accessor::build(m_mdspan.ptrAt(
id.localId(), i1, i2));
79 constexpr ARCCORE_HOST_DEVICE AccessorReturnType operator()(ItemLocalIdType
id,
Int32 i,
Int32 j,
Int32 k)
const
80 requires(Extents::rank() == 3)
82 return Accessor::build(m_mdspan.ptrAt(
id.localId(), i, j, k));
95template <
typename ItemType_,
typename DataType_,
typename Extents>
96class MeshMDVariableInView
97:
protected MeshMDVariableViewBase<ItemType_, DataViewGetter<DataType_>, Extents>
99 using BaseClass = MeshMDVariableViewBase<ItemType_, DataViewGetter<DataType_>, Extents>;
103 using ItemType = ItemType_;
104 using DataType = DataType_;
105 using ExtentsType = Extents;
106 using ItemLocalIdType = ItemType::LocalIdType;
109 using BaseClass::operator();
113 using MDSpanType = VariableRefType::MDSpanType;
117 MeshMDVariableInView(
const ViewBuildInfo& view_bi,
const VariableRefType& var_ref)
118 : BaseClass(var_ref.m_mdspan)
130template <
typename ItemType_,
typename DataType_,
typename Extents>
131class MeshMDVariableInOutView
132:
protected MeshMDVariableViewBase<ItemType_, DataViewGetterSetter<DataType_>, Extents>
134 using BaseClass = MeshMDVariableViewBase<ItemType_, DataViewGetterSetter<DataType_>, Extents>;
138 using ItemType = ItemType_;
139 using DataType = DataType_;
140 using ExtentsType = Extents;
141 using ItemLocalIdType = ItemType::LocalIdType;
144 using BaseClass::operator();
148 using MDSpanType = VariableRefType::MDSpanType;
152 MeshMDVariableInOutView(
const ViewBuildInfo& view_bi, VariableRefType& var_ref)
153 : BaseClass(var_ref.m_mdspan)
170template <
typename ItemType_,
typename VectorAccessor_,
typename Extents>
171class MeshVectorMDVariableViewBase
173 using AddedFirstExtentsType =
typename Extents::template AddedFirstExtentsType<DynExtent>;
177 using ItemType = ItemType_;
178 using VectorAccessor = VectorAccessor_;
179 using VectorElementAccessor = VectorAccessor_::VectorElemenAccessor;
180 using NumVectorType = VectorAccessor::NumVectorType;
181 using VectorAccessorReturnType = VectorAccessor::AccessorReturnType;
182 using VectorElementAccessorReturnType = VectorElementAccessor::AccessorReturnType;
183 using ItemLocalIdType = ItemType::LocalIdType;
191 MeshVectorMDVariableViewBase(
const MDSpanType& vector_mdspan)
192 : m_vector_mdspan(vector_mdspan)
202 constexpr ARCCORE_HOST_DEVICE VectorAccessorReturnType
operator()(ItemLocalIdType
id)
const
203 requires(Extents::rank() == 0)
205 return VectorAccessor::build(m_vector_mdspan.ptrAt(
id.localId()));
209 constexpr ARCCORE_HOST_DEVICE VectorElementAccessorReturnType
operator()(ItemLocalIdType
id,
Int32 i)
const
210 requires(Extents::rank() == 0)
212 return VectorElementAccessor::build(&m_vector_mdspan(
id.localId())(i));
218 constexpr ARCCORE_HOST_DEVICE VectorAccessorReturnType
operator()(ItemLocalIdType
id,
Int32 index)
const
219 requires(Extents::rank() == 1)
221 return VectorAccessor::build(m_vector_mdspan.
ptrAt(
id.localId(), index));
225 constexpr ARCCORE_HOST_DEVICE VectorElementAccessorReturnType
operator()(ItemLocalIdType
id,
Int32 index,
Int32 i)
const
226 requires(Extents::rank() == 1)
228 return VectorElementAccessor::build(&m_vector_mdspan(
id.localId(), index)(i));
234 MDSpanType m_vector_mdspan;
242template <
typename ItemType_,
typename DataType_,
int Size_,
typename Extents>
243class MeshVectorMDVariableInView
244:
public MeshVectorMDVariableViewBase<ItemType_, NumVectorDataViewGetter<DataType_, Size_>, Extents>
246 using BaseClass = MeshVectorMDVariableViewBase<ItemType_, NumVectorDataViewGetter<DataType_, Size_>, Extents>;
250 static const int Size = Size_;
251 using ItemType = ItemType_;
252 using DataType = DataType_;
253 using ItemLocalIdType = ItemType::LocalIdType;
259 using MDSpanType = VariableRefType::MDSpanType;
263 MeshVectorMDVariableInView(
const ViewBuildInfo& view_bi,
const VariableRefType& var_ref)
264 : BaseClass(var_ref.m_vector_mdspan)
276template <
typename ItemType_,
typename DataType_,
int Size_,
typename Extents>
277class MeshVectorMDVariableInOutView
278:
public MeshVectorMDVariableViewBase<ItemType_, NumVectorDataViewGetterSetter<DataType_, Size_>, Extents>
280 using BaseClass = MeshVectorMDVariableViewBase<ItemType_, NumVectorDataViewGetterSetter<DataType_, Size_>, Extents>;
284 static const int Size = Size_;
285 using ItemType = ItemType_;
286 using DataType = DataType_;
287 using ItemLocalIdType = ItemType::LocalIdType;
293 using MDSpanType = VariableRefType::MDSpanType;
297 MeshVectorMDVariableInOutView(
const ViewBuildInfo& view_bi,
const VariableRefType& var_ref)
298 : BaseClass(var_ref.m_vector_mdspan)
315template <
typename ItemType_,
typename MatrixAccessor_,
typename Extents>
316class MeshMatrixMDVariableViewBase
318 using AddedFirstExtentsType =
typename Extents::template AddedFirstExtentsType<DynExtent>;
322 using ItemType = ItemType_;
323 using MatrixAccessor = MatrixAccessor_;
324 using MatrixElementAccessor = MatrixAccessor_::MatrixElemenAccessor;
325 using NumMatrixType = MatrixAccessor::NumMatrixType;
326 using MatrixAccessorReturnType = MatrixAccessor::AccessorReturnType;
327 using MatrixElementAccessorReturnType = MatrixElementAccessor::AccessorReturnType;
328 using ItemLocalIdType = ItemType::LocalIdType;
336 MeshMatrixMDVariableViewBase(
const MDSpanType& matrix_mdspan)
337 : m_matrix_mdspan(matrix_mdspan)
347 constexpr ARCCORE_HOST_DEVICE MatrixAccessorReturnType
operator()(ItemLocalIdType
id)
const
348 requires(Extents::rank() == 0)
350 return MatrixAccessor::build(m_matrix_mdspan.ptrAt(
id.localId()));
354 constexpr ARCCORE_HOST_DEVICE MatrixElementAccessorReturnType
operator()(ItemLocalIdType
id,
Int32 i,
Int32 j)
const
355 requires(Extents::rank() == 0)
357 return MatrixElementAccessor::build(&m_matrix_mdspan(
id.localId())(i, j));
363 constexpr ARCCORE_HOST_DEVICE MatrixAccessorReturnType
operator()(ItemLocalIdType
id,
Int32 index)
const
364 requires(Extents::rank() == 1)
366 return MatrixAccessor::build(m_matrix_mdspan.
ptrAt(
id.localId(), index));
371 requires(Extents::rank() == 1)
373 return MatrixElementAccessor::build(&m_matrix_mdspan(
id.localId(), index)(i, j));
379 MDSpanType m_matrix_mdspan;
387template <
typename ItemType_,
typename DataType_,
int Row,
int Column,
typename Extents>
388class MeshMatrixMDVariableInView
389:
public MeshMatrixMDVariableViewBase<ItemType_, NumMatrixDataViewGetter<DataType_, Row, Column>, Extents>
391 using BaseClass = MeshMatrixMDVariableViewBase<ItemType_, NumMatrixDataViewGetter<DataType_, Row, Column>, Extents>;
395 using ItemType = ItemType_;
396 using DataType = DataType_;
397 using ItemLocalIdType = ItemType::LocalIdType;
403 using MDSpanType = VariableRefType::MDSpanType;
407 MeshMatrixMDVariableInView(
const ViewBuildInfo& view_bi,
const VariableRefType& var_ref)
408 : BaseClass(var_ref.m_matrix_mdspan)
420template <
typename ItemType_,
typename DataType_,
int Row,
int Column,
typename Extents>
421class MeshMatrixMDVariableInOutView
422:
public MeshMatrixMDVariableViewBase<ItemType_, NumMatrixDataViewGetterSetter<DataType_, Row, Column>, Extents>
424 using BaseClass = MeshMatrixMDVariableViewBase<ItemType_, NumMatrixDataViewGetterSetter<DataType_, Row, Column>, Extents>;
428 using ItemType = ItemType_;
429 using DataType = DataType_;
430 using ItemLocalIdType = ItemType::LocalIdType;
436 using MDSpanType = VariableRefType::MDSpanType;
440 MeshMatrixMDVariableInOutView(
const ViewBuildInfo& view_bi,
const VariableRefType& var_ref)
441 : BaseClass(var_ref.m_matrix_mdspan)
453template <
typename ItemType,
typename DataType,
int Size,
typename Extents>
464template <
typename ItemType,
typename DataType,
int Row,
int Column,
typename Extents>
475template <
typename ItemType,
typename DataType,
typename Extents>
486template <
typename ItemType,
typename DataType,
int Size,
typename Extents>
497template <
typename ItemType,
typename DataType,
int Row,
int Column,
typename Extents>
508template <
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.
Read-write view of multi-dimensional vector variable over a mesh item.
Read-only view of multi-dimensional vector variable over a mesh item.
constexpr __host__ __device__ VectorAccessorReturnType operator()(ItemLocalIdType id) const
Accessor of the vector for item id.
constexpr __host__ __device__ VectorElementAccessorReturnType operator()(ItemLocalIdType id, Int32 i) const
accessor for the element (i) of the vector for item id
constexpr __host__ __device__ VectorElementAccessorReturnType operator()(ItemLocalIdType id, Int32 index, Int32 i) const
Accessor for the element (i) of the vector for item id and index index.
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.
Class managing a multi-dimensional NumVector type variable on a mesh entity.
Read-only view for a NumMatrix<DataType_,Row,Column>.
Read-only view for a NumVector<DataType_, Size_>.
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.