14#include "arcane/impl/internal/Array2Data.h"
16#include "arcane/utils/NotSupportedException.h"
17#include "arcane/utils/Real2.h"
18#include "arcane/utils/Real2x2.h"
19#include "arcane/utils/Real3.h"
20#include "arcane/utils/Real3x3.h"
21#include "arcane/utils/IHashAlgorithm.h"
22#include "arcane/utils/NotImplementedException.h"
23#include "arcane/utils/ArgumentException.h"
24#include "arcane/utils/FatalErrorException.h"
25#include "arcane/utils/ITraceMng.h"
26#include "arcane/utils/CheckedConvert.h"
27#include "arcane/utils/MemoryAllocator.h"
30#include "arcane/core/datatype/DataStorageBuildInfo.h"
31#include "arcane/core/datatype/IDataOperation.h"
33#include "arcane/core/ISerializer.h"
35#include "arcane/impl/SerializedData.h"
48 inline constexpr Int64 SERIALIZE2_MAGIC_NUMBER = 0x12ff7789;
58, m_internal(new Impl(this))
65template <
typename DataType> Array2DataT<DataType>::
66Array2DataT(
const Array2DataT<DataType>& rhs)
67: m_value(AlignedMemoryAllocator::Simd())
69, m_internal(new Impl(this))
70, m_allocation_info(rhs.m_allocation_info)
72 m_value = rhs.m_value;
78template <
typename DataType> Array2DataT<DataType>::
79Array2DataT(
const DataStorageBuildInfo& dsbi)
80: m_value(dsbi.memoryAllocator())
81, m_trace(dsbi.traceMng())
82, m_internal(new Impl(this))
89template <
typename DataType> Array2DataT<DataType>::
101template <
typename DataType> DataStorageTypeInfo Array2DataT<DataType>::
102staticStorageTypeInfo()
104 typedef DataTypeTraitsT<DataType> TraitsType;
106 Int32 nb_basic_type = TraitsType::nbBasicType();
109 return DataStorageTypeInfo(bdt, nb_basic_type, dimension, multi_tag);
116storageTypeInfo()
const
118 return staticStorageTypeInfo();
124template <
typename DataType>
void Array2DataT<DataType>::
134createSerializedDataRef(
bool use_basic_type)
const
140 Int64 type_size =
sizeof(DataType);
142 if (use_basic_type) {
145 type_size =
sizeof(BasicType);
149 Int64 nb_base_element = nb_element * nb_count;
150 Int64 full_size = nb_base_element * type_size;
151 const Byte* bt =
reinterpret_cast<const Byte*
>(
m_value.to1DSpan().data());
155 dimensions[0] =
m_value.dim1Size();
156 dimensions[1] =
m_value.dim2Size();
159 nb_base_element,
false, dimensions,
shape());
160 sd->setConstBytes(base_values);
167template <
typename DataType>
void Array2DataT<DataType>::
175 if (data_type !=
dataType() && data_type == base_data_type)
187 m_value.resize(dim1_size, dim2_size);
188 m_shape = sdata->
shape();
198template <
typename DataType>
void Array2DataT<DataType>::
201 ARCANE_UNUSED(sdata);
208template <
typename DataType>
void Array2DataT<DataType>::
216 if (mode == ISerializer::ModeReserve) {
225 sbuf->
reserveSpan(data_type, total_nb_element * nb_count);
234 n[3] = SERIALIZE2_MAGIC_NUMBER;
236 BasicType* bt =
reinterpret_cast<BasicType*
>(
m_value.to1DSpan().data());
242 Int64 n[4] = { 0, 0, 0, 0 };
245 Int64 dim2_size = n[1];
247 if (n[3] != SERIALIZE2_MAGIC_NUMBER)
252 m_value.resize(count, dim2_size);
255 BasicType* bt =
reinterpret_cast<BasicType*
>(
m_value.to1DSpan().data());
265 m_value.resize(current_size + count, dim2_size);
268 BasicType* bt =
reinterpret_cast<BasicType*
>(
m_value.to1DSpan().data() + current_total);
280template <
typename DataType>
void Array2DataT<DataType>::
288 if (mode == ISerializer::ModeReserve) {
297 sbuf->
reserveSpan(data_type, total_nb_value * nb_count);
302 Int64 total_nb_value = count * dim2_size;
303 Int64 total = total_nb_value;
308 n[3] = SERIALIZE2_MAGIC_NUMBER;
319 for (
Int32 i = 0, is = count; i < is; ++i) {
320 const BasicType* sub_a =
reinterpret_cast<const BasicType*
>(
m_value[ids[i]].data());
321 for (
Int64 z = 0, iz = dim2_size * nb_count; z < iz; ++z) {
332 Int64 n[4] = { 0, 0, 0, 0 };
335 Int64 dim2_size = n[1];
336 Int32 count = CheckedConvert::toInt32(n[2]);
337 Int64 total = count * dim2_size;
347 if (n[3] != SERIALIZE2_MAGIC_NUMBER)
350 if (dim2_size != current_dim2_size) {
351 if (current_dim2_size != 0 && dim2_size != 0)
352 ARCANE_FATAL(
"serialized data should have the same dim2Size current={0} found={1}",
353 current_dim2_size, dim2_size);
357 Int64 nb_value = count;
363 Span<DataType> data_value(
reinterpret_cast<DataType*
>(base_value.
data()), nb_value * dim2_size);
369 if (operation && nb_value != 0) {
373 for (
Int32 i = 0, n = count; i < n; ++i) {
375 for (
Int64 z = 0, iz = dim2_size; z < iz; ++z) {
376 current_value[index] = a[z];
381 transformed_value = current_value.
view();
382 operation->applySpan(transformed_value, data_value);
385 transformed_value = data_value;
390 for (
Int32 i = 0, n = count; i < n; ++i) {
392 for (
Int64 z = 0, iz = dim2_size; z < iz; ++z) {
393 a[z] = transformed_value[index];
409template <
typename DataType>
void Array2DataT<DataType>::
418template <
typename DataType>
void Array2DataT<DataType>::
419setName(
const String& name)
427template <
typename DataType>
void Array2DataT<DataType>::
434 Int64 type_size =
sizeof(DataType);
436 const Byte* ptr =
reinterpret_cast<const Byte*
>(values.
data());
442 dimensions[0] =
m_value.dim1Size();
443 dimensions[1] =
m_value.dim2Size();
444 ptr =
reinterpret_cast<const Byte*
>(dimensions.
data());
456 hash_info.setVersion(2);
461 dimensions[0] = m_value.dim1Size();
462 dimensions[1] = m_value.dim2Size();
473template <
typename DataType>
void Array2DataT<DataType>::
474copy(
const IData* data)
476 auto* true_data =
dynamic_cast<const DataInterfaceType*
>(data);
479 m_value.copy(true_data->view());
485template <
typename DataType>
void Array2DataT<DataType>::
486swapValues(
IData* data)
488 auto* true_data =
dynamic_cast<ThatClass*
>(data);
491 swapValuesDirect(true_data);
500 m_value.swap(true_data->m_value);
506template <
typename DataType>
void Array2DataT<DataType>::
509 if (m_allocation_info == v)
511 m_allocation_info = v;
512 m_value.setMemoryLocationHint(v.memoryLocationHint());
521 m_value.changeAllocator(alloc_info);
522 m_allocation_info.setMemoryLocationHint(alloc_info.memoryLocationHint());
#define ARCANE_FATAL(...)
Macro throwing a FatalErrorException.
Memory and allocator management functions.
Integer size() const
Number of elements in the vector.
Memory allocator with specific memory alignment.
Exception when an argument is invalid.
Two-dimensional array data of type DataType.
UniqueArray2< DataType > m_value
Data.
eDataType dataType() const override
Data type.
ArrayShape shape() const override
Array shape for a 1D or 2D data item.
void resize(Int64 s)
Changes the number of elements in the array to s.
const T * data() const
Access to the root of the array without any protection.
ArrayView< T > view() const
Mutable view of this array.
constexpr Integer size() const noexcept
Number of elements in the array.
Information on data allocation.
Information for calculating data hash.
Type information for a data container.
Interface of an operation on a data.
Interface of a data item.
Context for calculating a hash incrementally.
virtual void updateHash(Span< const std::byte > input)=0
Adds the array input to the calculated hash.
Interface of a hashing algorithm.
virtual void computeHash64(Span< const Byte > input, ByteArray &output)
Calculates the hash value for the array input.
Interface of a serialized data.
virtual eDataType baseDataType() const =0
Data type.
virtual ArrayShape shape() const =0
Shape of the array associated with the data.
virtual Int64 memorySize() const =0
Indicates the number of bytes that must be allocated to store or read the data.
virtual void setWritableBytes(Span< Byte > bytes)=0
Positions the serialized values.
virtual Int64ConstArrayView extents() const =0
Array containing the number of elements for each dimension.
virtual bool isMultiSize() const =0
Indicates if it is a multi-size array. (only relevant if nbDimension()>1).
eMode
Serializer operating mode.
@ ModePut
The serializer expects reserve().
@ ModeGet
The serializer expects get().
virtual eReadMode readMode() const =0
Read mode.
virtual void putSpan(Span< const Real > values)
Add the array values.
virtual eMode mode() const =0
Current operating mode.
@ ReadReplace
Replace current elements with those read.
@ ReadAdd
Add those read to the current elements.
virtual void getSpan(Span< Real > values)
Retrieve the array values.
virtual void reserveSpan(eBasicDataType dt, Int64 n)=0
Reserves memory for n values of dt.
Options to configure allocations.
Exception when a function is not implemented.
Reference to an instance.
constexpr __host__ __device__ pointer data() const noexcept
Pointer to the start of the view.
constexpr __host__ __device__ SizeType size() const noexcept
Returns the size of the array.
View of an array of elements of type T.
Unicode character string.
1D data vector with value semantics (STL style).
-- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature --
Ref< ISerializedData > arcaneCreateSerializedDataRef(eDataType data_type, Int64 memory_size, Integer nb_dim, Int64 nb_element, Int64 nb_base_element, bool is_multi_size, Int64ConstArrayView dimensions)
Creates serialized data.
std::int64_t Int64
Signed integer type of 64 bits.
Int32 Integer
Type representing an integer.
Array< Byte > ByteArray
Dynamic one-dimensional array of characters.
ConstArrayView< Int32 > Int32ConstArrayView
C equivalent of a 1D array of 32-bit integers.
eBasicDataType
Type of a basic data item.
@ Int64
64-bit integer data type
Impl::SpanTypeFromSize< conststd::byte, SizeType >::SpanType asBytes(const SpanImpl< DataType, SizeType, Extent > &s)
Converts the view into an array of non-modifiable bytes.
unsigned char Byte
Type of a byte.
std::int32_t Int32
Signed integer type of 32 bits.