Arcane  4.1.12.0
User documentation
Loading...
Searching...
No Matches
ArrayMetaData.h
1// -*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
2//-----------------------------------------------------------------------------
3// Copyright 2000-2026 CEA (www.cea.fr) IFPEN (www.ifpenergiesnouvelles.com)
4// See the top-level COPYRIGHT file for details.
5// SPDX-License-Identifier: Apache-2.0
6//-----------------------------------------------------------------------------
7/*---------------------------------------------------------------------------*/
8/* ArrayMetaData.h (C) 2000-2026 */
9/* */
10/* 1D Array. */
11/*---------------------------------------------------------------------------*/
12#ifndef ARCCORE_COMMON_ARRAYMETADATA_H
13#define ARCCORE_COMMON_ARRAYMETADATA_H
14/*---------------------------------------------------------------------------*/
15/*---------------------------------------------------------------------------*/
16
17#include "arccore/common/MemoryAllocationOptions.h"
18#include "arccore/common/MemoryAllocationArgs.h"
19#include "arccore/common/IMemoryAllocator.h"
20#include "arccore/common/AllocatedMemoryInfo.h"
21
22/*---------------------------------------------------------------------------*/
23/*---------------------------------------------------------------------------*/
24
25namespace Arcane
26{
27
28/*---------------------------------------------------------------------------*/
29/*---------------------------------------------------------------------------*/
30
31/*!
32 * \internal
33 *
34 * \brief Array Metadata.
35 *
36 * This class is used to hold common metadata for all
37 * implementations that derive from AbstractArray.
38 *
39 * Only classes that implement a UniqueArray semantics
40 * are allowed to use an allocator other than the default allocator.
41 */
42class ARCCORE_COMMON_EXPORT ArrayMetaData
43{
44 // NOTE: The fields of this class are used for the TTF display of totalview.
45 // If their order is modified, the copy of this class
46 // in Arcane's totalview displayer must be updated.
47
48 template <typename> friend class AbstractArray;
49 template <typename> friend class Array2;
50 template <typename> friend class Array;
51 template <typename> friend class SharedArray;
52 template <typename> friend class SharedArray2;
53 friend class AbstractArrayBase;
54 static IMemoryAllocator* _defaultAllocator();
55
56 public:
57
58 ArrayMetaData()
59 : allocation_options(_defaultAllocator())
60 {}
61
62 protected:
63
64 //! Number of elements in the array (for 1D arrays)
66 //! Size of the first dimension (for 2D arrays)
68 //! Size of the second dimension (for 2D arrays)
70 //! Number of allocated elements
72 //! Memory allocator and associated options
74 //! Number of references on the instance
76 //! Information about the physical location of the memory (if known)
78 //! Indicates if this instance was allocated by the new operator.
79 bool is_allocated_by_new = false;
80 //! Indicates if this instance is not the null instance (shared by all SharedArray)
81 bool is_not_null = false;
82 //! Indicates if calls to the allocator must be performed collectively.
84
85 protected:
86
87 IMemoryAllocator* _allocator() const { return allocation_options.m_allocator; }
88
89 public:
90
91 static void throwInvalidMetaDataForSharedArray ARCCORE_NORETURN();
92 static void throwNullExpected ARCCORE_NORETURN();
93 static void throwNotNullExpected ARCCORE_NORETURN();
94 static void throwUnsupportedSpecificAllocator ARCCORE_NORETURN();
95 static void overlapError ARCCORE_NORETURN(const void* begin1, Int64 size1,
96 const void* begin2, Int64 size2);
97
98 protected:
99
100 using MemoryPointer = void*;
101 using ConstMemoryPointer = const void*;
102
103 protected:
104
105 MemoryPointer _allocate(Int64 nb, Int64 sizeof_true_type, RunQueue* queue);
106 MemoryPointer _reallocate(const AllocatedMemoryInfo& mem_info, Int64 new_capacity, Int64 sizeof_true_type, RunQueue* queue);
107 void _deallocate(const AllocatedMemoryInfo& mem_info, RunQueue* queue) noexcept
108 {
109 if (_allocator()) {
110 MemoryAllocationArgs alloc_args = _getAllocationArgs(queue);
111 _allocator()->deallocate(alloc_args, mem_info);
112 }
113 }
114 MemoryPointer _changeAllocator(const MemoryAllocationOptions& new_allocator_opt, const AllocatedMemoryInfo& current_info, Int64 sizeof_true_type, RunQueue* queue);
115 void _setMemoryLocationHint(eMemoryLocationHint new_hint, void* ptr, Int64 sizeof_true_type);
116 void _setHostDeviceMemoryLocation(eHostDeviceMemoryLocation location);
117 void _copyFromMemory(MemoryPointer destination, ConstMemoryPointer source, Int64 sizeof_true_type, RunQueue* queue);
118
119 private:
120
121 void _checkAllocator() const;
122 MemoryAllocationArgs _getAllocationArgs() const { return allocation_options.allocationArgs(); }
123 MemoryAllocationArgs _getAllocationArgs(RunQueue* queue) const
124 {
125 return allocation_options.allocationArgs(queue);
126 }
127};
128
129/*---------------------------------------------------------------------------*/
130/*---------------------------------------------------------------------------*/
131
132/*!
133 * \internal
134 *
135 * \brief This type is no longer used.
136 */
138{
139};
140
141/*---------------------------------------------------------------------------*/
142/*---------------------------------------------------------------------------*/
143
144/*!
145 * \internal
146 *
147 * \brief This class is no longer used.
148 */
149template <typename T>
151: public ArrayImplBase
152{
153};
154
155/*---------------------------------------------------------------------------*/
156/*---------------------------------------------------------------------------*/
157
158} // namespace Arcane
159
160/*---------------------------------------------------------------------------*/
161/*---------------------------------------------------------------------------*/
162
163#endif
Information about an allocated memory region.
bool is_not_null
Indicates if this instance is not the null instance (shared by all SharedArray).
Int64 size
Number of elements in the array (for 1D arrays).
Int64 capacity
Number of allocated elements.
MemoryAllocationOptions allocation_options
Memory allocator and associated options.
Int32 nb_ref
Number of references on the instance.
eHostDeviceMemoryLocation m_host_device_memory_location
Information about the physical location of the memory (if known).
bool is_collective_allocator
Indicates if calls to the allocator must be performed collectively.
Int64 dim2_size
Size of the second dimension (for 2D arrays).
bool is_allocated_by_new
Indicates if this instance was allocated by the new operator.
Int64 dim1_size
Size of the first dimension (for 2D arrays).
Class containing information to specialize allocations.
MemoryAllocationArgs allocationArgs(RunQueue *queue=nullptr) const
Arguments for 'IMemoryAllocator' associated with these options and the queue.
-- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature --
std::int64_t Int64
Signed integer type of 64 bits.
eHostDeviceMemoryLocation
Physical location of a memory address.
std::int32_t Int32
Signed integer type of 32 bits.