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})",
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) {
113 a = m_allocators[
static_cast<int>(mem)];
119 if (!a && throw_if_not_found)
120 ARCCORE_FATAL(
"Allocator for resource '{0}' is not available", r);
140 int x = _checkValidResource(r);
141 return m_memory_pools[x];
147void MemoryResourceMng::
150 int x = _checkValidResource(r);
151 m_allocators[x] = allocator;
157void MemoryResourceMng::
160 int x = _checkValidResource(r);
161 m_memory_pools[x] = pool;
167void MemoryResourceMng::
171 Int64 from_size = from.bytes().size();
172 Int64 to_size = to.bytes().size();
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);
182void MemoryResourceMng::
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.
Interface for a memory allocator.
Interface of a memory pool.
Mutable view on a contiguous memory region containing fixed-size elements.
void copyHost(MutableMemoryView destination, ConstMemoryView source)
Copies the data from source into destination.
IMemoryAllocator * getAllocator(eMemoryResource mem_resource)
Default allocator for the resource mem_resource.
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.