14#include "arcane/accelerator/core/internal/ReduceMemoryImpl.h"
16#include "arcane/utils/CheckedConvert.h"
17#include "arcane/utils/PlatformUtils.h"
20#include "arcane/accelerator/core/Runner.h"
21#include "arcane/accelerator/core/Memory.h"
22#include "arcane/accelerator/core/internal/IRunQueueStream.h"
23#include "arcane/accelerator/core/internal/RunCommandImpl.h"
24#include "arcane/accelerator/core/internal/RunnerImpl.h"
29namespace Arcane::Accelerator::impl
50 _allocateMemoryForReduceData(128);
51 _allocateMemoryForGridDeviceCount();
57void ReduceMemoryImpl::
60 m_command->releaseReduceMemoryImpl(
this);
66void ReduceMemoryImpl::
69 m_grid_memory_info.m_reduce_policy = m_command->runner()->reducePolicy();
75void* ReduceMemoryImpl::
78 auto identity_span = identity_view.
bytes();
79 Int32 data_type_size =
static_cast<Int32>(identity_span.size());
81 if (data_type_size >
m_size)
82 _allocateMemoryForReduceData(data_type_size);
88 m_command->internalStream()->copyMemory(copy_args.addAsync());
96void ReduceMemoryImpl::
97_allocateGridDataMemory()
102 if (total_size <= m_grid_memory_info.m_grid_memory_values.bytes().size())
105 m_grid_buffer.resize(total_size);
108 m_grid_memory_info.m_grid_memory_values = mem_view;
114void ReduceMemoryImpl::
115_allocateMemoryForGridDeviceCount()
119 Int64 size =
sizeof(
unsigned int);
120 const unsigned int zero = 0;
121 m_grid_device_count.resize(1);
122 auto* ptr = m_grid_device_count.data();
124 m_grid_memory_info.m_grid_device_count = ptr;
128 m_command->internalStream()->copyMemory(copy_args);
134void ReduceMemoryImpl::
135copyReduceValueFromDevice()
137 void* destination = m_grid_memory_info.m_host_memory_for_reduced_value;
140 m_command->internalStream()->copyMemory(copy_args);
147internalGetOrCreateReduceMemoryImpl(
RunCommand* command)
149 return command->m_p->getOrCreateReduceMemoryImpl();
Fonctions de gestion mémoire et des allocateurs.
Arguments pour la copie mémoire.
Gestion d'une commande sur accélérateur.
Interface de la gestion mémoire pour les réductions.
std::byte * m_device_memory
Pointeur vers la mémoire unifiée contenant la donnée réduite.
Int64 m_data_type_size
Taille de la donnée actuelle.
UniqueArray< std::byte > m_identity_buffer
Buffer pour conserver la valeur de l'identité
Int64 m_size
Taille allouée pour m_device_memory.
Implémentation d'une commande pour accélérateur.
Vue constante sur une zone mémoire contigue contenant des éléments de taille fixe.
constexpr SpanType bytes() const
Vue sous forme d'octets.
Int32 toInt32(Int64 v)
Converti un Int64 en un Int32.
IMemoryAllocator * getAllocator(eMemoryResource mem_resource)
Allocateur par défaut pour la ressource mem_resource.
MutableMemoryView makeMutableMemoryView(void *ptr, Int32 datatype_size, Int64 nb_element)
Créé une vue mémoire modifiable.
std::int64_t Int64
Type entier signé sur 64 bits.
Arcane::eMemoryResource eMemoryRessource
Typedef pour la version Arcane historique (avec 2's')
@ HostPinned
Alloue sur l'hôte.
std::int32_t Int32
Type entier signé sur 32 bits.