Arcane  4.1.12.0
User documentation
Loading...
Searching...
No Matches
Arcane::AlignedMemoryAllocator Class Reference

Memory allocator with specific memory alignment. More...

#include <arccore/common/AlignedMemoryAllocator.h>

Public Member Functions

bool hasRealloc (MemoryAllocationArgs) const override
 Indicates whether the allocator supports realloc semantics.
AllocatedMemoryInfo allocate (MemoryAllocationArgs args, Int64 new_size) override
AllocatedMemoryInfo reallocate (MemoryAllocationArgs args, AllocatedMemoryInfo current_ptr, Int64 new_size) override
 Reallocates memory for new_size bytes and returns the pointer.
void deallocate (MemoryAllocationArgs args, AllocatedMemoryInfo ptr) override
 Frees the memory whose base address is ptr.
Int64 adjustedCapacity (MemoryAllocationArgs args, Int64 wanted_capacity, Int64 element_size) const override
 Adjusts the capacity based on the element size.
size_t guaranteedAlignment (MemoryAllocationArgs) const override
 Value of the alignment guaranteed by the allocator.
eMemoryResource memoryResource () const override
 Memory resource provided by the allocator.
Public Member Functions inherited from Arcane::IMemoryAllocator
virtual ~IMemoryAllocator ()=default
 Destroys 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 bool isCollective () const
 Indicates whether calls to the allocator must be performed collectively.

Static Public Member Functions

static constexpr Integer simdAlignment ()
 Alignment for structures using vectorization.
static constexpr Integer cacheLineAlignment ()
 Alignment for a cache line.
static AlignedMemoryAllocator * Simd ()
 Allocator guaranteeing alignment to use vectorization on the target platform.
static AlignedMemoryAllocator * CacheLine ()
 Allocator guaranteeing alignment to a cache line.

Protected Member Functions

 AlignedMemoryAllocator (Int32 alignment)

Detailed Description

Memory allocator with specific memory alignment.

This class is used via the two public methods Simd() and CacheLine(), which return an allocator with adequate alignment to allow vectorization, and an allocator aligned to a cache line, respectively.

Definition at line 44 of file AlignedMemoryAllocator.h.

Constructor & Destructor Documentation

◆ AlignedMemoryAllocator()

Arcane::AlignedMemoryAllocator::AlignedMemoryAllocator ( Int32 alignment)
inlineexplicitprotected

Definition at line 92 of file AlignedMemoryAllocator.h.

Member Function Documentation

◆ adjustedCapacity()

Int64 Arcane::AlignedMemoryAllocator::adjustedCapacity ( MemoryAllocationArgs args,
Int64 wanted_capacity,
Int64 element_size ) const
overridevirtual

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.

Implements Arcane::IMemoryAllocator.

Definition at line 244 of file MemoryAllocator.cc.

◆ allocate()

AllocatedMemoryInfo Arcane::AlignedMemoryAllocator::allocate ( MemoryAllocationArgs args,
Int64 new_size )
overridevirtual

NOTE: Normally the _mm_alloc() and _mm_free() functions allow allocating aligned memory. It should be checked if they are available everywhere.

Implements Arcane::IMemoryAllocator.

Definition at line 147 of file MemoryAllocator.cc.

◆ CacheLine()

AlignedMemoryAllocator * Arcane::AlignedMemoryAllocator::CacheLine ( )
inlinestatic

Allocator guaranteeing alignment to a cache line.

Definition at line 85 of file AlignedMemoryAllocator.h.

◆ cacheLineAlignment()

constexpr Integer Arcane::AlignedMemoryAllocator::cacheLineAlignment ( )
inlinestaticconstexpr

Alignment for a cache line.

Definition at line 68 of file AlignedMemoryAllocator.h.

◆ deallocate()

void Arcane::AlignedMemoryAllocator::deallocate ( MemoryAllocationArgs args,
AllocatedMemoryInfo ptr )
overridevirtual

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.

Implements Arcane::IMemoryAllocator.

Definition at line 185 of file MemoryAllocator.cc.

References Arcane::AllocatedMemoryInfo::baseAddress().

◆ guaranteedAlignment()

size_t Arcane::AlignedMemoryAllocator::guaranteedAlignment ( MemoryAllocationArgs args) const
inlineoverridevirtual

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.

Implements Arcane::IMemoryAllocator.

Definition at line 103 of file AlignedMemoryAllocator.h.

◆ hasRealloc()

bool Arcane::AlignedMemoryAllocator::hasRealloc ( MemoryAllocationArgs ) const
inlineoverridevirtual

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 from Arcane::IMemoryAllocator.

Definition at line 98 of file AlignedMemoryAllocator.h.

◆ memoryResource()

eMemoryResource Arcane::AlignedMemoryAllocator::memoryResource ( ) const
inlineoverridevirtual

Memory resource provided by the allocator.

Reimplemented from Arcane::IMemoryAllocator.

Definition at line 104 of file AlignedMemoryAllocator.h.

References Arcane::Host.

◆ reallocate()

AllocatedMemoryInfo Arcane::AlignedMemoryAllocator::reallocate ( MemoryAllocationArgs args,
AllocatedMemoryInfo current_ptr,
Int64 new_size )
overridevirtual

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():

  • current_ptr may be null, in which case this call is equivalent to allocate().
  • the returned pointer may be null if the memory could not be allocated.

Implements Arcane::IMemoryAllocator.

Definition at line 168 of file MemoryAllocator.cc.

References Arcane::AllocatedMemoryInfo::baseAddress().

◆ Simd()

AlignedMemoryAllocator * Arcane::AlignedMemoryAllocator::Simd ( )
inlinestatic

Allocator guaranteeing alignment to use vectorization on the target platform.

This is the alignment for the more restrictive type, and therefore this allocator can be used for all vector structures.

Definition at line 77 of file AlignedMemoryAllocator.h.

◆ simdAlignment()

constexpr Integer Arcane::AlignedMemoryAllocator::simdAlignment ( )
inlinestaticconstexpr

Alignment for structures using vectorization.

Definition at line 66 of file AlignedMemoryAllocator.h.


The documentation for this class was generated from the following files: