Namespace for memory and allocator management functions. More...
Functions | |
| template<typename DataType> | |
| Int32 | checkResizeArrayWithCapacity (Array< DataType > &array, Int64 new_size, bool force_resize) |
| Resizes an array by adding a memory reserve. | |
| template<typename DataType> | |
| Int32 | checkResizeArrayWithCapacity (Array< DataType > &array, Int64 new_size) |
| Resizes an array by adding a memory reserve. | |
| IMemoryAllocator * | getAcceleratorHostMemoryAllocator () |
| Specific allocator for accelerators. | |
| eMemoryResource | getDefaultDataMemoryResource () |
| Memory resource used by the default allocator for data. | |
| eMemoryResource | getMemoryResourceFromName (const String &name) |
| Returns the memory resource by its name. | |
| IMemoryAllocator * | getDefaultDataAllocator () |
| Default allocator for data. | |
| MemoryAllocationOptions | getDefaultDataAllocator (eMemoryLocationHint hint) |
| Default allocator for data with expected location information. | |
| IMemoryAllocator * | getDeviceOrHostAllocator () |
| Returns the host or device allocator. | |
| MemoryAllocationOptions | getAllocatorForMostlyReadOnlyData () |
| Default allocator for mostly read-only data. | |
| MemoryAllocationOptions | getAllocationOptions (eMemoryResource mem_resource) |
| Default allocation for the resource mem_resource. | |
| IMemoryAllocator * | getAllocator (eMemoryResource mem_resource) |
| Default allocator for the resource mem_resource. | |
| IMemoryPool * | getMemoryPoolOrNull (eMemoryResource mem_resource) |
| Memory pool for the resource mem_resource. | |
| void | copy (MutableMemoryView destination, eMemoryResource destination_mem, ConstMemoryView source, eMemoryResource source_mem, const RunQueue *queue=nullptr) |
| Copies source to destination using the queue queue. | |
| void | copy (MutableMemoryView destination, ConstMemoryView source, const RunQueue *queue=nullptr) |
| Copies source to destination using the queue queue. | |
| template<typename DataType> | |
| void | copy (Span< DataType > destination, Span< const DataType > source, const RunQueue *queue=nullptr) |
| Copies source to destination using the queue queue. | |
| template<typename DataType> | |
| void | copy (SmallSpan< DataType > destination, SmallSpan< const DataType > source, const RunQueue *queue=nullptr) |
| Copies source to destination using the queue queue. | |
| void | copyHostWithIndexedSource (MutableMemoryView destination, ConstMemoryView source, Span< const Int32 > indexes) |
| Copies data on the host with indirection. | |
| void | copyWithIndexedSource (MutableMemoryView destination, ConstMemoryView source, SmallSpan< const Int32 > indexes, RunQueue *run_queue=nullptr) |
| Copies data on the host with indirection. | |
| void | copyHost (MutableMemoryView destination, ConstMemoryView source) |
| Copies the data from source into destination. | |
| void | copyHostWithIndexedDestination (MutableMemoryView destination, ConstMemoryView source, Span< const Int32 > indexes) |
| Copies indexed data from v into the instance. | |
| void | copyWithIndexedDestination (MutableMemoryView destination, ConstMemoryView source, SmallSpan< const Int32 > indexes, RunQueue *run_queue=nullptr) |
| Memory copy with indirection. | |
| void | fillIndexed (MutableMemoryView destination, ConstMemoryView source, SmallSpan< const Int32 > indexes, const RunQueue *run_queue=nullptr) |
| Fills an indexed memory region with a value. | |
| void | fill (MutableMemoryView destination, ConstMemoryView source, const RunQueue *run_queue=nullptr) |
| Fills a memory region with a value. | |
| void | copyWithIndexedSource (MutableMemoryView destination, ConstMultiMemoryView source, SmallSpan< const Int32 > indexes, RunQueue *run_queue=nullptr) |
| Copies indexed data from source into destination. | |
| void | copyWithIndexedDestination (MutableMultiMemoryView destination, ConstMemoryView source, SmallSpan< const Int32 > indexes, RunQueue *run_queue=nullptr) |
| Copies indexed elements of destination with data from source. | |
| void | fillIndexed (MutableMultiMemoryView destination, ConstMemoryView source, SmallSpan< const Int32 > indexes, RunQueue *run_queue=nullptr) |
| Fills indexed elements of destination with data source. | |
| void | fill (MutableMultiMemoryView destination, ConstMemoryView source, RunQueue *run_queue=nullptr) |
| Fills elements of destination with the value source. | |
Namespace for memory and allocator management functions.
|
inline |
Resizes an array by adding a memory reserve.
This call is equivalent to checkResizeArrayWithCapacity(array, new_size, false).
Definition at line 75 of file arcane/src/arcane/utils/MemoryUtils.h.
References checkResizeArrayWithCapacity().
|
inline |
Resizes an array by adding a memory reserve.
The array array is resized only if new_size is greater than the current size of the array or if force_resize is true.
If the array is resized, an additional capacity is reserved to prevent reallocating every time.
| 2 | if reallocation occurred via reserve() |
| 1 | if resizing occurred without reallocation. |
| 0 | if no operation took place. |
Definition at line 52 of file arcane/src/arcane/utils/MemoryUtils.h.
References Arcane::AbstractArray< T >::capacity(), Arcane::AbstractArray< T >::largeSize(), Arcane::Array< T >::reserve(), and Arcane::Array< T >::resize().
Referenced by Arcane::ItemGroupImpl::addItems(), Arcane::MeshUtils::checkResizeArray(), and checkResizeArrayWithCapacity().
|
inline |
Copies source to destination using the queue queue.
Definition at line 188 of file arccore/src/common/arccore/common/MemoryUtils.h.
References copy(), and Arcane::Unknown.
| void Arcane::MemoryUtils::copy | ( | MutableMemoryView | destination, |
| eMemoryResource | destination_mem, | ||
| ConstMemoryView | source, | ||
| eMemoryResource | source_mem, | ||
| const RunQueue * | queue = nullptr ) |
Copies source to destination using the queue queue.
It is possible to specify the memory resource where the source and destination are located. If they are unknown, it is preferable to use the overload copy(MutableMemoryView destination, ConstMemoryView source, const RunQueue* queue).
Definition at line 229 of file arccore/src/common/arccore/common/MemoryUtils.cc.
References Arcane::IMemoryResourceMng::_internal().
Referenced by Arcane::ItemGroupImpl::addItems(), copy(), copy(), copy(), and Arcane::ItemVector::ItemVector().
|
inline |
Copies source to destination using the queue queue.
Definition at line 212 of file arccore/src/common/arccore/common/MemoryUtils.h.
References copy().
|
inline |
Copies source to destination using the queue queue.
Definition at line 199 of file arccore/src/common/arccore/common/MemoryUtils.h.
References Arcane::asBytes(), Arcane::asWritableBytes(), and copy().
| void Arcane::MemoryUtils::copyHost | ( | MutableMemoryView | destination, |
| ConstMemoryView | source ) |
Copies the data from source into destination.
Uses std::memmove for the copy.
Definition at line 240 of file arccore/src/common/arccore/common/MemoryUtils.cc.
References ARCCORE_CHECK_POINTER, ARCCORE_FATAL, Arcane::ConstMemoryView::bytes(), and Arcane::MutableMemoryView::bytes().
| void Arcane::MemoryUtils::copyHostWithIndexedDestination | ( | MutableMemoryView | destination, |
| ConstMemoryView | source, | ||
| Span< const Int32 > | indexes ) |
Copies indexed data from v into the instance.
The operation is equivalent to the following pseudo-code:
Definition at line 262 of file arccore/src/common/arccore/common/MemoryUtils.cc.
References copyWithIndexedDestination(), and Arcane::SpanImpl< T, SizeType, Extent >::smallView().
| void Arcane::MemoryUtils::copyHostWithIndexedSource | ( | MutableMemoryView | destination, |
| ConstMemoryView | source, | ||
| Span< const Int32 > | indexes ) |
Copies data on the host with indirection.
Copies the data from source into destination indexed by indexes
The operation is equivalent to the following pseudo-code:
Definition at line 325 of file arccore/src/common/arccore/common/MemoryUtils.cc.
References copyWithIndexedSource(), and Arcane::SpanImpl< T, SizeType, Extent >::smallView().
| void Arcane::MemoryUtils::copyWithIndexedDestination | ( | MutableMemoryView | destination, |
| ConstMemoryView | source, | ||
| SmallSpan< const Int32 > | indexes, | ||
| RunQueue * | run_queue = nullptr ) |
Memory copy with indirection.
Copies the data from source into destination for the indices specified by indexes.
The operation is equivalent to the following pseudo-code:
If run_queue is not null, it will be used for the copy.
Definition at line 272 of file arccore/src/common/arccore/common/MemoryUtils.cc.
References Arcane::ConstMemoryView::bytes(), Arcane::MutableMemoryView::bytes(), Arcane::ConstMemoryView::datatypeSize(), Arcane::MutableMemoryView::datatypeSize(), and Arcane::SpanImpl< T, SizeType, Extent >::size().
Referenced by copyHostWithIndexedDestination().
| void Arcane::MemoryUtils::copyWithIndexedDestination | ( | MutableMultiMemoryView | destination, |
| ConstMemoryView | source, | ||
| SmallSpan< const Int32 > | indexes, | ||
| RunQueue * | run_queue = nullptr ) |
Copies indexed elements of destination with data from source.
The operation is equivalent to the following pseudo-code:
The array indexes must have a size that is a multiple of 2. Even values are used to index the first array and odd values the second.
If run_queue is not null, it will be used for the copy.
Definition at line 358 of file arccore/src/common/arccore/common/MemoryUtils.cc.
References Arcane::ConstMemoryView::bytes(), Arcane::ConstMemoryView::datatypeSize(), Arcane::MutableMultiMemoryView::datatypeSize(), Arcane::SpanImpl< T, SizeType, Extent >::size(), and Arcane::MutableMultiMemoryView::views().
| void Arcane::MemoryUtils::copyWithIndexedSource | ( | MutableMemoryView | destination, |
| ConstMemoryView | source, | ||
| SmallSpan< const Int32 > | indexes, | ||
| RunQueue * | run_queue = nullptr ) |
Copies data on the host with indirection.
Copies the data from source into destination indexed by indexes
If run_queue is not null, it will be used for the copy.
Definition at line 335 of file arccore/src/common/arccore/common/MemoryUtils.cc.
References Arcane::ConstMemoryView::bytes(), Arcane::MutableMemoryView::bytes(), Arcane::ConstMemoryView::datatypeSize(), Arcane::MutableMemoryView::datatypeSize(), and Arcane::SpanImpl< T, SizeType, Extent >::size().
Referenced by copyHostWithIndexedSource().
| void Arcane::MemoryUtils::copyWithIndexedSource | ( | MutableMemoryView | destination, |
| ConstMultiMemoryView | source, | ||
| SmallSpan< const Int32 > | indexes, | ||
| RunQueue * | run_queue = nullptr ) |
Copies indexed data from source into destination.
The operation is equivalent to the following pseudo-code:
The array indexes must have a size that is a multiple of 2. Even values are used to index the first array and odd values the second.
If run_queue is not null, it will be used for the copy.
Definition at line 401 of file arccore/src/common/arccore/common/MemoryUtils.cc.
References Arcane::MutableMemoryView::bytes(), Arcane::ConstMultiMemoryView::datatypeSize(), Arcane::MutableMemoryView::datatypeSize(), Arcane::SpanImpl< T, SizeType, Extent >::size(), and Arcane::ConstMultiMemoryView::views().
| void Arcane::MemoryUtils::fill | ( | MutableMemoryView | destination, |
| ConstMemoryView | source, | ||
| const RunQueue * | run_queue = nullptr ) |
Fills a memory region with a value.
Fills the values of the memory region destination with the value of the memory region source. source must have a single value. The memory region source must be accessible from the host.
The operation is equivalent to the following pseudo-code:
If run_queue is not null, it will be used for the copy.
Definition at line 311 of file arccore/src/common/arccore/common/MemoryUtils.cc.
References Arcane::ConstMemoryView::bytes(), Arcane::MutableMemoryView::bytes(), Arcane::ConstMemoryView::datatypeSize(), Arcane::MutableMemoryView::datatypeSize(), and Arcane::SpanImpl< T, SizeType, Extent >::fill().
| void Arcane::MemoryUtils::fill | ( | MutableMultiMemoryView | destination, |
| ConstMemoryView | source, | ||
| RunQueue * | run_queue = nullptr ) |
Fills elements of destination with the value source.
source must have a single value. It must be accessible from the host.
The operation is equivalent to the following pseudo-code:
If run_queue is not null, it will be used for the copy.
Definition at line 390 of file arccore/src/common/arccore/common/MemoryUtils.cc.
References Arcane::ConstMemoryView::bytes(), Arcane::ConstMemoryView::datatypeSize(), Arcane::MutableMultiMemoryView::datatypeSize(), and Arcane::MutableMultiMemoryView::views().
| void Arcane::MemoryUtils::fillIndexed | ( | MutableMemoryView | destination, |
| ConstMemoryView | source, | ||
| SmallSpan< const Int32 > | indexes, | ||
| const RunQueue * | run_queue = nullptr ) |
Fills an indexed memory region with a value.
Fills the indices indexes of the memory region destination with the value of the memory region source. source must have a single value. The memory region source must be accessible from the host.
The operation is equivalent to the following pseudo-code:
If run_queue is not null, it will be used for the copy.
Definition at line 292 of file arccore/src/common/arccore/common/MemoryUtils.cc.
References Arcane::ConstMemoryView::bytes(), Arcane::MutableMemoryView::bytes(), Arcane::ConstMemoryView::datatypeSize(), Arcane::MutableMemoryView::datatypeSize(), Arcane::SpanImpl< T, SizeType, Extent >::fill(), and Arcane::SpanImpl< T, SizeType, Extent >::size().
| void Arcane::MemoryUtils::fillIndexed | ( | MutableMultiMemoryView | destination, |
| ConstMemoryView | source, | ||
| SmallSpan< const Int32 > | indexes, | ||
| RunQueue * | run_queue = nullptr ) |
Fills indexed elements of destination with data source.
source must have a single value. This value will be used to fill the values of the instance at the indices specified by indexes. It must be accessible from the host.
The operation is equivalent to the following pseudo-code:
If run_queue is not null, it will be used for the copy.
Definition at line 374 of file arccore/src/common/arccore/common/MemoryUtils.cc.
References Arcane::ConstMemoryView::bytes(), Arcane::ConstMemoryView::datatypeSize(), Arcane::MutableMultiMemoryView::datatypeSize(), Arcane::SpanImpl< T, SizeType, Extent >::size(), and Arcane::MutableMultiMemoryView::views().
| IMemoryAllocator * Arcane::MemoryUtils::getAcceleratorHostMemoryAllocator | ( | ) |
Specific allocator for accelerators.
Definition at line 142 of file arccore/src/common/arccore/common/MemoryUtils.cc.
Referenced by Arcane::platform::getAcceleratorHostMemoryAllocator().
| MemoryAllocationOptions Arcane::MemoryUtils::getAllocationOptions | ( | eMemoryResource | mem_resource | ) |
Default allocation for the resource mem_resource.
Throws an exception if no allocator is available for the resource (for example, if eMemoryResource::Device is requested and there is no support for accelerators.
The eMemoryResource::UnifiedMemory resource is always available. If no accelerator runtime is loaded, then it is equivalent to eMemoryResource::Host.
Definition at line 211 of file arccore/src/common/arccore/common/MemoryUtils.cc.
References getAllocator().
| IMemoryAllocator * Arcane::MemoryUtils::getAllocator | ( | eMemoryResource | mem_resource | ) |
Default allocator for the resource mem_resource.
Throws an exception if no allocator is available for the resource mem_resource.
Definition at line 202 of file arccore/src/common/arccore/common/MemoryUtils.cc.
Referenced by getAllocationOptions().
| MemoryAllocationOptions Arcane::MemoryUtils::getAllocatorForMostlyReadOnlyData | ( | ) |
Default allocator for mostly read-only data.
This call is equivalent to getDefaultDataAllocator(eMemoryLocationHint::HostAndDeviceMostlyRead).
Definition at line 193 of file arccore/src/common/arccore/common/MemoryUtils.cc.
References getDefaultDataAllocator(), and Arcane::HostAndDeviceMostlyRead.
| IMemoryAllocator * Arcane::MemoryUtils::getDefaultDataAllocator | ( | ) |
Default allocator for data.
The default allocator for data is an allocator that allows access to the memory region both by the host and the accelerator.
It is possible to retrieve the associated memory resource via getDefaultDataMemoryResource();
This call is equivalent to getAllocator(getDefaultDataMemoryResource()).
It is guaranteed that the alignment is at least that returned by AlignedMemoryAllocator::Simd().
Definition at line 162 of file arccore/src/common/arccore/common/MemoryUtils.cc.
References getDefaultDataMemoryResource().
Referenced by getAllocatorForMostlyReadOnlyData(), getDefaultDataAllocator(), and Arcane::platform::getDefaultDataAllocator().
| MemoryAllocationOptions Arcane::MemoryUtils::getDefaultDataAllocator | ( | eMemoryLocationHint | hint | ) |
Default allocator for data with expected location information.
This function returns the allocator of getDefaulDataAllocator() but adds the memory management information specified by hint.
Definition at line 184 of file arccore/src/common/arccore/common/MemoryUtils.cc.
References getDefaultDataAllocator().
| eMemoryResource Arcane::MemoryUtils::getDefaultDataMemoryResource | ( | ) |
Memory resource used by the default allocator for data.
By default, if an accelerator runtime is initialized, the associated resource is eMemoryResource::UnifiedMemory. Otherwise, it is eMemoryResource::Host.
Definition at line 76 of file arccore/src/common/arccore/common/MemoryUtils.cc.
Referenced by getDefaultDataAllocator().
| IMemoryAllocator * Arcane::MemoryUtils::getDeviceOrHostAllocator | ( | ) |
Returns the host or device allocator.
If an accelerator runtime is initialized, the returned allocator allows allocation using the default accelerator memory (eMemoryResource::Device). Otherwise, it uses the host allocator (eMemoryResource::Host).
Definition at line 171 of file arccore/src/common/arccore/common/MemoryUtils.cc.
References Arcane::Device, Arcane::IMemoryResourceMng::getAllocator(), and Arcane::Host.
| IMemoryPool * Arcane::MemoryUtils::getMemoryPoolOrNull | ( | eMemoryResource | mem_resource | ) |
Memory pool for the resource mem_resource.
Returns nullptr if no memory pool is available for the resource mem_resource.
Definition at line 220 of file arccore/src/common/arccore/common/MemoryUtils.cc.
| eMemoryResource Arcane::MemoryUtils::getMemoryResourceFromName | ( | const String & | name | ) |
Returns the memory resource by its name.
The name corresponds to the name of the enumeration value (e.g., 'Device' for eMemoryResource::Device.
If name is null, returns eMemoryResource::Unknown. If name does not correspond to a valid value, throws an exception.
Definition at line 85 of file arccore/src/common/arccore/common/MemoryUtils.cc.
References ARCCORE_FATAL, Arcane::Device, Arcane::Host, Arcane::HostPinned, Arcane::String::null(), Arcane::UnifiedMemory, and Arcane::Unknown.