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)
55 void copy(ConstMemoryView from, eMemoryResource from_mem,
56 MutableMemoryView to, eMemoryResource to_mem,
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})",
80, m_copier(m_default_memory_copier.get())
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) {
116 a = m_allocators[(int)eMemoryResource::Host];
120 if (!a && throw_if_not_found)
121 ARCANE_FATAL(
"Allocator for resource '{0}' is not available", r);
129IMemoryAllocator* MemoryResourceMng::
130getAllocator(eMemoryResource r)
138void MemoryResourceMng::
139setAllocator(eMemoryResource r, IMemoryAllocator* allocator)
141 int x = _checkValidResource(r);
142 m_allocators[x] = allocator;
148void MemoryResourceMng::
149copy(ConstMemoryView from, eMemoryResource from_mem,
150 MutableMemoryView to, eMemoryResource to_mem,
const RunQueue* queue)
152 Int64 from_size = from.bytes().size();
153 Int64 to_size = to.bytes().size();
154 if (from_size > to_size)
155 ARCANE_FATAL(
"Destination copy is too small (to_size={0} from_size={1})", to_size, from_size);
157 m_copier->copy(from, from_mem, to, to_mem, queue);
163void MemoryResourceMng::
164genericCopy(ConstMemoryView from, MutableMemoryView to)
166 IMemoryResourceMng* mrm = MemoryUtils::getDataMemoryResourceMng();
168 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.
static AlignedMemoryAllocator * Simd()
Allocateur garantissant l'alignement pour utiliser la vectorisation sur la plateforme cible.
Interface d'un allocateur pour la mémoire.
IMemoryAllocator * getDefaultDataAllocator()
Allocateur par défaut pour les données.
IMemoryAllocator * getAllocator(eMemoryResource mem_resource)
Allocateur par défaut pour la ressource mem_resource.
-*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
Arccore::eMemoryResource eMemoryRessource
Typedef pour la version Arcane historique (avec 2's')
eMemoryResource
Liste des ressources mémoire disponibles.