14#include "arccore/common/internal/MemoryResourceMng.h"
16#include "arccore/base/FatalErrorException.h"
17#include "arccore/base/PlatformUtils.h"
18#include "arccore/base/MemoryView.h"
19#include "arccore/common/Array.h"
20#include "arccore/common/AlignedMemoryAllocator.h"
22#include "arccore/common/internal/MemoryUtilsInternal.h"
56 [[maybe_unused]]
const RunQueue* queue)
override
61 if (!_isHost(from_mem))
62 ARCCORE_FATAL(
"Source buffer is not accessible from host and no copier provided (location={0})",
66 ARCCORE_FATAL(
"Destination buffer is not accessible from host and no copier provided (location={0})",
78: m_default_memory_copier(new DefaultHostMemoryCopier())
79, m_copier(m_default_memory_copier.get())
90int MemoryResourceMng::
94 if (x <= 0 || x >= ARCCORE_NB_MEMORY_RESOURCE)
95 ARCCORE_FATAL(
"Invalid value '{0}'. Valid range is '1' to '{1}'", x, ARCCORE_NB_MEMORY_RESOURCE - 1);
105 int x = _checkValidResource(r);
110 if (!a && !m_is_accelerator) {
119 if (!a && throw_if_not_found)
120 ARCCORE_FATAL(
"Allocator for resource '{0}' is not available", r);
140 int x = _checkValidResource(r);
150 int x = _checkValidResource(r);
160 int x = _checkValidResource(r);
167void MemoryResourceMng::
173 if (from_size > to_size)
174 ARCCORE_FATAL(
"Destination copy is too small (to_size={0} from_size={1})", to_size, from_size);
176 m_copier->
copy(from, from_mem, to, to_mem, queue);
187 mrm->
_internal()->copy(from, mem_type, to, mem_type,
nullptr);
#define ARCCORE_FATAL(...)
Macro throwing a FatalErrorException.
Memory management utility functions.
Execution queue for an accelerator.
static AlignedMemoryAllocator * Simd()
Allocator guaranteeing alignment to use vectorization on the target platform.
Constant view on a contiguous memory region containing fixed-size elements.
constexpr SpanType bytes() const
View in byte form.
void copy(ConstMemoryView from, eMemoryResource from_mem, MutableMemoryView to, eMemoryResource to_mem, const RunQueue *queue) override
Copies the data from from to to with the queue queue.
Interface for a memory allocator.
Interface for memory copies with accelerator support.
virtual void copy(ConstMemoryView from, eMemoryResource from_mem, MutableMemoryView to, eMemoryResource to_mem, const RunQueue *queue)=0
Copies the data from from to to with the queue queue.
Interface of a memory pool.
Memory resource management for CPUs and accelerators.
virtual IMemoryResourceMngInternal * _internal()=0
Internal interface.
FixedArray< IMemoryPool *, ARCCORE_NB_MEMORY_RESOURCE > m_memory_pools
List of memory pools.
void setAllocator(eMemoryResource r, IMemoryAllocator *allocator) override
Sets the allocator for resource r.
static void genericCopy(ConstMemoryView from, MutableMemoryView to)
Generic copy using platform::getDataMemoryRessourceMng().
FixedArray< IMemoryAllocator *, ARCCORE_NB_MEMORY_RESOURCE > m_allocators
List of allocators.
IMemoryPool * getMemoryPoolOrNull(eMemoryResource r) override
Memory pool for resource r.
IMemoryAllocator * getAllocator(eMemoryResource r) override
Memory allocator for resource r.
void setMemoryPool(eMemoryResource r, IMemoryPool *pool) override
Sets the memory pool for resource r.
Mutable view on a contiguous memory region containing fixed-size elements.
constexpr SpanType bytes() const
View in byte form.
constexpr __host__ __device__ SizeType size() const noexcept
Returns the size of the array.
IMemoryRessourceMng * getDataMemoryResourceMng()
Memory resource manager for data.
void copyHost(MutableMemoryView destination, ConstMemoryView source)
Copies the data from source into destination.
eMemoryResource getDefaultDataMemoryResource()
Memory resource used by the default allocator for data.
-- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature --
std::int64_t Int64
Signed integer type of 64 bits.
eMemoryResource
List of available memory resources.
@ HostPinned
Allocates on the host.
@ Unknown
Unknown or uninitialized value.
@ Host
Allocates on the host.
@ UnifiedMemory
Allocates using unified memory.