14#include "arcane/utils/internal/MemoryResourceMng.h"
16#include "arcane/utils/FatalErrorException.h"
17#include "arcane/utils/PlatformUtils.h"
18#include "arcane/utils/Array.h"
19#include "arcane/utils/MemoryView.h"
20#include "arcane/utils/MemoryAllocator.h"
22#include "arcane/utils/internal/MemoryUtilsInternal.h"
38 if (r == eMemoryResource::Unknown)
40 if (r == eMemoryResource::Host || r == eMemoryResource::UnifiedMemory || r == eMemoryResource::HostPinned)
57 [[maybe_unused]]
const RunQueue* queue)
override
62 if (!_isHost(from_mem))
63 ARCANE_FATAL(
"Source buffer is not accessible from host and no copier provided (location={0})",
67 ARCANE_FATAL(
"Destination buffer is not accessible from host and no copier provided (location={0})",
70 MemoryUtils::copyHost(to, from);
80, m_copier(m_default_memory_copier.get())
85 IMemoryAllocator* a = AlignedMemoryAllocator::Simd();
86 setAllocator(eMemoryRessource::Host, a);
92int MemoryResourceMng::
93_checkValidResource(eMemoryResource r)
96 if (x <= 0 || x >= Arccore::ARCCORE_NB_MEMORY_RESOURCE)
97 ARCANE_FATAL(
"Invalid value '{0}'. Valid range is '1' to '{1}'", x, Arccore::ARCCORE_NB_MEMORY_RESOURCE - 1);
104IMemoryAllocator* MemoryResourceMng::
105getAllocator(eMemoryResource r,
bool throw_if_not_found)
107 int x = _checkValidResource(r);
108 IMemoryAllocator* a = m_allocators[x];
112 if (!a && !m_is_accelerator) {
113 if (r == eMemoryResource::UnifiedMemory || r == eMemoryResource::HostPinned) {
114 eMemoryResource mem = MemoryUtils::getDefaultDataMemoryResource();
115 a = m_allocators[
static_cast<int>(mem)];
117 a = m_allocators[
static_cast<int>(eMemoryResource::Host)];
121 if (!a && throw_if_not_found)
122 ARCANE_FATAL(
"Allocator for resource '{0}' is not available", r);
130IMemoryAllocator* MemoryResourceMng::
131getAllocator(eMemoryResource r)
133 return getAllocator(r,
true);
139void MemoryResourceMng::
140setAllocator(eMemoryResource r, IMemoryAllocator* allocator)
142 int x = _checkValidResource(r);
143 m_allocators[x] = allocator;
149void MemoryResourceMng::
153 Int64 from_size = from.bytes().size();
154 Int64 to_size = to.bytes().size();
155 if (from_size > to_size)
156 ARCANE_FATAL(
"Destination copy is too small (to_size={0} from_size={1})", to_size, from_size);
158 m_copier->copy(from, from_mem, to, to_mem, queue);
164void MemoryResourceMng::
167 IMemoryResourceMng* mrm = MemoryUtils::getDataMemoryResourceMng();
168 eMemoryResource mem_type = eMemoryResource::Unknown;
169 mrm->_internal()->copy(from, mem_type, to, mem_type,
nullptr);
#define ARCANE_FATAL(...)
Macro envoyant une exception FatalErrorException.
Fonctions de gestion mémoire et des allocateurs.
File d'exécution pour un accélérateur.
Vue constante sur une zone mémoire contigue contenant des éléments de taille fixe.
Vue modifiable sur une zone mémoire contigue contenant des éléments de taille fixe.
-*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
std::int64_t Int64
Type entier signé sur 64 bits.
Arcane::eMemoryResource eMemoryRessource
Typedef pour la version Arcane historique (avec 2's')