Interface for a memory allocator. More...
Public Member Functions | |
| virtual | ~IMemoryAllocator ()=default |
| Destroys the allocator. | |
| virtual bool | hasRealloc (MemoryAllocationArgs) const |
| Indicates whether the allocator supports realloc semantics. | |
| virtual AllocatedMemoryInfo | allocate (MemoryAllocationArgs args, Int64 new_size)=0 |
| Allocates memory for new_size bytes and returns the pointer. | |
| virtual AllocatedMemoryInfo | reallocate (MemoryAllocationArgs args, AllocatedMemoryInfo current_ptr, Int64 new_size)=0 |
| Reallocates memory for new_size bytes and returns the pointer. | |
| virtual void | deallocate (MemoryAllocationArgs args, AllocatedMemoryInfo ptr)=0 |
| Frees the memory whose base address is ptr. | |
| virtual Int64 | adjustedCapacity (MemoryAllocationArgs args, Int64 wanted_capacity, Int64 element_size) const =0 |
| Adjusts the capacity based on the element size. | |
| virtual size_t | guaranteedAlignment (MemoryAllocationArgs args) const =0 |
| Value of the alignment guaranteed by the allocator. | |
| virtual size_t | guarantedAlignment (MemoryAllocationArgs args) const |
| Value of the alignment guaranteed by the allocator. | |
| virtual void | notifyMemoryArgsChanged (MemoryAllocationArgs old_args, MemoryAllocationArgs new_args, AllocatedMemoryInfo ptr) |
| Notifies of a change in instance-specific arguments. | |
| virtual void | copyMemory (MemoryAllocationArgs args, AllocatedMemoryInfo destination, AllocatedMemoryInfo source) |
| Copies memory between two regions. | |
| virtual eMemoryResource | memoryResource () const |
| Memory resource provided by the allocator. | |
| virtual bool | isCollective () const |
| Indicates whether calls to the allocator must be performed collectively. | |
Interface for a memory allocator.
This class defines an interface for the memory allocation used by Arccore array classes (Array, UniqueArray).
An instance of this class must remain valid as long as there are arrays using it. Since the allocator is transferred during copies, it is preferable that allocators be static objects whose lifetime is that of the program.
Allocators do not have specific mutable state and must function in multi-threading.
Definition at line 42 of file arccore/src/common/arccore/common/IMemoryAllocator.h.
|
virtualdefault |
Destroys the allocator.
All objects allocated by the allocator must have been deallocated.
|
pure virtual |
Adjusts the capacity based on the element size.
This method is used to optionally modify the number of allocated elements based on their size. This allows, for example, aligned allocators to ensure that the number of elements allocated is a multiple of this alignment.
Implemented in Arcane::Accelerator::AcceleratorMemoryAllocatorBase, Arcane::AlignedMemoryAllocator, Arcane::DefaultMemoryAllocator, Arcane::Impl::StackMemoryAllocator, Arcane::MachineShMemWinMemoryAllocator, Arccore::AlignedMemoryAllocator, and Arccore::DefaultMemoryAllocator.
|
pure virtual |
Allocates memory for new_size bytes and returns the pointer.
The semantics are equivalent to malloc():
Implemented in Arcane::Accelerator::AcceleratorMemoryAllocatorBase, Arcane::Accelerator::Sycl::SyclMemoryAllocatorBase, Arcane::AlignedMemoryAllocator, Arcane::DefaultMemoryAllocator, Arcane::Impl::StackMemoryAllocator, Arcane::MachineShMemWinMemoryAllocator, Arcane::PrintableMemoryAllocator, Arccore::AlignedMemoryAllocator, Arccore::DefaultMemoryAllocator, and Arccore::PrintableMemoryAllocator.
|
virtual |
Copies memory between two regions.
The default implementation uses std::memcpy().
| args | memory region arguments |
| destination | destination of the copy |
| source | source of the copy |
Reimplemented in Arcane::Accelerator::AcceleratorMemoryAllocatorBase.
Definition at line 68 of file MemoryAllocator.cc.
References Arcane::AllocatedMemoryInfo::baseAddress().
Referenced by guaranteedAlignment().
|
pure virtual |
Frees the memory whose base address is ptr.
The pointer ptr must have been allocated via a call to allocate() or reallocate() on this instance.
The semantics of this method are equivalent to free(), and thus ptr may be null, in which case no operation is performed.
Implemented in Arcane::Accelerator::AcceleratorMemoryAllocatorBase, Arcane::Accelerator::Sycl::SyclMemoryAllocatorBase, Arcane::AlignedMemoryAllocator, Arcane::DefaultMemoryAllocator, Arcane::Impl::StackMemoryAllocator, Arcane::MachineShMemWinMemoryAllocator, Arcane::PrintableMemoryAllocator, Arccore::AlignedMemoryAllocator, Arccore::DefaultMemoryAllocator, and Arccore::PrintableMemoryAllocator.
|
virtual |
Value of the alignment guaranteed by the allocator.
Definition at line 51 of file MemoryAllocator.cc.
References guaranteedAlignment().
Referenced by guaranteedAlignment().
|
pure virtual |
Value of the alignment guaranteed by the allocator.
This method ensures that an allocator has sufficient alignment for certain operations such as vectorization, for example.
If there is no guarantee, it returns 0.
Implemented in Arcane::AlignedMemoryAllocator, Arcane::DefaultMemoryAllocator, Arcane::Impl::StackMemoryAllocator, Arcane::MachineShMemWinMemoryAllocator, Arccore::AlignedMemoryAllocator, and Arccore::DefaultMemoryAllocator.
References copyMemory(), guarantedAlignment(), and notifyMemoryArgsChanged().
Referenced by guarantedAlignment().
|
inlinevirtual |
Indicates whether the allocator supports realloc semantics.
Default C allocators (malloc/realloc/free) obviously support realloc, but this is not necessarily the case for specific allocators with memory alignment (such as posix_memalign).
Reimplemented in Arcane::Accelerator::AcceleratorMemoryAllocatorBase, Arcane::Accelerator::Sycl::SyclMemoryAllocatorBase, Arcane::AlignedMemoryAllocator, Arcane::DefaultMemoryAllocator, Arcane::Impl::StackMemoryAllocator, Arcane::MachineShMemWinMemoryAllocator, Arccore::AlignedMemoryAllocator, and Arccore::DefaultMemoryAllocator.
Definition at line 63 of file arccore/src/common/arccore/common/IMemoryAllocator.h.
|
inlinevirtual |
Indicates whether calls to the allocator must be performed collectively.
Reimplemented in Arcane::MachineShMemWinMemoryAllocator.
Definition at line 154 of file arccore/src/common/arccore/common/IMemoryAllocator.h.
|
inlinevirtual |
Memory resource provided by the allocator.
Reimplemented in Arcane::Accelerator::AcceleratorMemoryAllocatorBase, Arcane::Accelerator::Sycl::DeviceSyclMemoryAllocator, Arcane::Accelerator::Sycl::HostPinnedSyclMemoryAllocator, Arcane::Accelerator::Sycl::UnifiedMemorySyclMemoryAllocator, Arcane::AlignedMemoryAllocator, Arcane::DefaultMemoryAllocator, Arccore::AlignedMemoryAllocator, and Arccore::DefaultMemoryAllocator.
Definition at line 148 of file arccore/src/common/arccore/common/IMemoryAllocator.h.
References memoryResource(), and Arcane::Unknown.
Referenced by memoryResource(), and Arcane::VariableUtils::prefetchVariableAsync().
|
virtual |
Notifies of a change in instance-specific arguments.
| ptr | allocated memory region |
| old_args | old value of the arguments |
| new_args | new value of the arguments |
Reimplemented in Arcane::Accelerator::Cuda::UnifiedMemoryCudaMemoryAllocator.
Definition at line 60 of file MemoryAllocator.cc.
Referenced by guaranteedAlignment(), and Arcane::Array2< T >::setDebugName().
|
pure virtual |
Reallocates memory for new_size bytes and returns the pointer.
The pointer current_ptr must have been allocated via a call to allocate() or reallocate() on this instance.
The semantics of this method are equivalent to realloc():
Implemented in Arcane::Accelerator::AcceleratorMemoryAllocatorBase, Arcane::Accelerator::Sycl::SyclMemoryAllocatorBase, Arcane::AlignedMemoryAllocator, Arcane::DefaultMemoryAllocator, Arcane::Impl::StackMemoryAllocator, Arcane::MachineShMemWinMemoryAllocator, Arcane::PrintableMemoryAllocator, Arccore::AlignedMemoryAllocator, Arccore::DefaultMemoryAllocator, and Arccore::PrintableMemoryAllocator.