14#include "arcane/impl/internal/Array2Data.h"
16#include "arccore/common/AlignedMemoryAllocator.h"
18#include "arcane/utils/NotSupportedException.h"
19#include "arcane/utils/Real2.h"
20#include "arcane/utils/Real2x2.h"
21#include "arcane/utils/Real3.h"
22#include "arcane/utils/Real3x3.h"
23#include "arcane/utils/IHashAlgorithm.h"
24#include "arcane/utils/NotImplementedException.h"
25#include "arcane/utils/ArgumentException.h"
26#include "arcane/utils/FatalErrorException.h"
27#include "arcane/utils/ITraceMng.h"
28#include "arcane/utils/CheckedConvert.h"
29#include "arcane/utils/MemoryAllocator.h"
32#include "arcane/core/datatype/DataStorageBuildInfo.h"
33#include "arcane/core/datatype/IDataOperation.h"
35#include "arcane/core/ISerializer.h"
37#include "arcane/impl/SerializedData.h"
50 inline constexpr Int64 SERIALIZE2_MAGIC_NUMBER = 0x12ff7789;
60, m_internal(new Impl(this))
67template <
typename DataType> Array2DataT<DataType>::
68Array2DataT(
const Array2DataT<DataType>& rhs)
69: m_value(AlignedMemoryAllocator::Simd())
71, m_internal(new Impl(this))
72, m_allocation_info(rhs.m_allocation_info)
74 m_value = rhs.m_value;
80template <
typename DataType> Array2DataT<DataType>::
81Array2DataT(
const DataStorageBuildInfo& dsbi)
82: m_value(dsbi.memoryAllocator())
83, m_trace(dsbi.traceMng())
84, m_internal(new Impl(this))
91template <
typename DataType> Array2DataT<DataType>::
103template <
typename DataType> DataStorageTypeInfo Array2DataT<DataType>::
104staticStorageTypeInfo()
106 typedef DataTypeTraitsT<DataType> TraitsType;
108 Int32 nb_basic_type = TraitsType::nbBasicType();
111 return DataStorageTypeInfo(bdt, nb_basic_type, dimension, multi_tag);
118storageTypeInfo()
const
120 return staticStorageTypeInfo();
126template <
typename DataType>
void Array2DataT<DataType>::
136createSerializedDataRef(
bool use_basic_type)
const
142 Int64 type_size =
sizeof(DataType);
144 if (use_basic_type) {
147 type_size =
sizeof(BasicType);
151 Int64 nb_base_element = nb_element * nb_count;
152 Int64 full_size = nb_base_element * type_size;
153 const Byte* bt =
reinterpret_cast<const Byte*
>(
m_value.to1DSpan().data());
157 dimensions[0] =
m_value.dim1Size();
158 dimensions[1] =
m_value.dim2Size();
161 nb_base_element,
false, dimensions,
shape());
162 sd->setConstBytes(base_values);
169template <
typename DataType>
void Array2DataT<DataType>::
177 if (data_type !=
dataType() && data_type == base_data_type)
189 m_value.resize(dim1_size, dim2_size);
190 m_shape = sdata->
shape();
200template <
typename DataType>
void Array2DataT<DataType>::
203 ARCANE_UNUSED(sdata);
210template <
typename DataType>
void Array2DataT<DataType>::
218 if (mode == ISerializer::ModeReserve) {
227 sbuf->
reserveSpan(data_type, total_nb_element * nb_count);
236 n[3] = SERIALIZE2_MAGIC_NUMBER;
238 BasicType* bt =
reinterpret_cast<BasicType*
>(
m_value.to1DSpan().data());
244 Int64 n[4] = { 0, 0, 0, 0 };
247 Int64 dim2_size = n[1];
249 if (n[3] != SERIALIZE2_MAGIC_NUMBER)
254 m_value.resize(count, dim2_size);
257 BasicType* bt =
reinterpret_cast<BasicType*
>(
m_value.to1DSpan().data());
267 m_value.resize(current_size + count, dim2_size);
270 BasicType* bt =
reinterpret_cast<BasicType*
>(
m_value.to1DSpan().data() + current_total);
282template <
typename DataType>
void Array2DataT<DataType>::
290 if (mode == ISerializer::ModeReserve) {
299 sbuf->
reserveSpan(data_type, total_nb_value * nb_count);
304 Int64 total_nb_value = count * dim2_size;
305 Int64 total = total_nb_value;
310 n[3] = SERIALIZE2_MAGIC_NUMBER;
321 for (
Int32 i = 0, is = count; i < is; ++i) {
322 const BasicType* sub_a =
reinterpret_cast<const BasicType*
>(
m_value[ids[i]].data());
323 for (
Int64 z = 0, iz = dim2_size * nb_count; z < iz; ++z) {
334 Int64 n[4] = { 0, 0, 0, 0 };
337 Int64 dim2_size = n[1];
338 Int32 count = CheckedConvert::toInt32(n[2]);
339 Int64 total = count * dim2_size;
349 if (n[3] != SERIALIZE2_MAGIC_NUMBER)
352 if (dim2_size != current_dim2_size) {
353 if (current_dim2_size != 0 && dim2_size != 0)
354 ARCANE_FATAL(
"serialized data should have the same dim2Size current={0} found={1}",
355 current_dim2_size, dim2_size);
359 Int64 nb_value = count;
365 Span<DataType> data_value(
reinterpret_cast<DataType*
>(base_value.
data()), nb_value * dim2_size);
371 if (operation && nb_value != 0) {
375 for (
Int32 i = 0, n = count; i < n; ++i) {
377 for (
Int64 z = 0, iz = dim2_size; z < iz; ++z) {
378 current_value[index] = a[z];
383 transformed_value = current_value.
view();
384 operation->applySpan(transformed_value, data_value);
387 transformed_value = data_value;
392 for (
Int32 i = 0, n = count; i < n; ++i) {
394 for (
Int64 z = 0, iz = dim2_size; z < iz; ++z) {
395 a[z] = transformed_value[index];
411template <
typename DataType>
void Array2DataT<DataType>::
420template <
typename DataType>
void Array2DataT<DataType>::
421setName(
const String& name)
429template <
typename DataType>
void Array2DataT<DataType>::
436 Int64 type_size =
sizeof(DataType);
438 const Byte* ptr =
reinterpret_cast<const Byte*
>(values.
data());
444 dimensions[0] =
m_value.dim1Size();
445 dimensions[1] =
m_value.dim2Size();
446 ptr =
reinterpret_cast<const Byte*
>(dimensions.
data());
458 hash_info.setVersion(2);
463 dimensions[0] = m_value.dim1Size();
464 dimensions[1] = m_value.dim2Size();
475template <
typename DataType>
void Array2DataT<DataType>::
476copy(
const IData* data)
478 auto* true_data =
dynamic_cast<const DataInterfaceType*
>(data);
481 m_value.copy(true_data->view());
487template <
typename DataType>
void Array2DataT<DataType>::
488swapValues(
IData* data)
490 auto* true_data =
dynamic_cast<ThatClass*
>(data);
493 swapValuesDirect(true_data);
502 m_value.swap(true_data->m_value);
508template <
typename DataType>
void Array2DataT<DataType>::
511 if (m_allocation_info == v)
513 m_allocation_info = v;
514 m_value.setMemoryLocationHint(v.memoryLocationHint());
523 m_value.changeAllocator(alloc_info);
524 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.