14#include "arccore/common/accelerator/internal/ReduceMemoryImpl.h"
16#include "arccore/base/CheckedConvert.h"
17#include "arccore/base/PlatformUtils.h"
20#include "arccore/common/accelerator/Runner.h"
21#include "arccore/common/accelerator/Memory.h"
22#include "arccore/common/accelerator/internal/IRunQueueStream.h"
23#include "arccore/common/accelerator/internal/RunCommandImpl.h"
24#include "arccore/common/accelerator/internal/RunnerImpl.h"
29namespace Arcane::Accelerator::Impl
43ReduceMemoryImpl(RunCommandImpl* p)
49 _allocateMemoryForReduceData(128);
50 _allocateMemoryForGridDeviceCount();
56void ReduceMemoryImpl::
59 m_command->releaseReduceMemoryImpl(
this);
65void ReduceMemoryImpl::
66allocateReduceDataMemory(Int32 data_type_size)
68 m_data_type_size = data_type_size;
69 if (data_type_size > m_size)
70 _allocateMemoryForReduceData(data_type_size);
76void ReduceMemoryImpl::
77_allocateMemoryForReduceData(Int32 new_size)
79 m_host_memory_bytes.resize(new_size);
80 m_grid_memory_info.m_host_memory_for_reduced_value = m_host_memory_bytes.data();
88void ReduceMemoryImpl::
89_allocateGridDataMemory()
93 Int32 total_size = CheckedConvert::toInt32(m_data_type_size * m_grid_size);
94 if (total_size <= m_grid_memory_info.m_grid_memory_values.bytes().size())
97 m_grid_buffer.resize(total_size);
100 m_grid_memory_info.m_grid_memory_values = mem_view;
106void ReduceMemoryImpl::
107_allocateMemoryForGridDeviceCount()
111 Int64 size =
sizeof(
unsigned int);
112 const unsigned int zero = 0;
113 m_grid_device_count.resize(1);
114 auto* ptr = m_grid_device_count.data();
116 m_grid_memory_info.m_grid_device_count = ptr;
119 MemoryCopyArgs copy_args(ptr, &zero, size);
120 m_command->internalStream()->copyMemory(copy_args);
126extern "C++" IReduceMemoryImpl*
127internalGetOrCreateReduceMemoryImpl(RunCommand* command)
129 return command->m_p->getOrCreateReduceMemoryImpl();
Fonctions utilitaires de gestion mémoire.
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.
@ Device
La mémoire est sur accélérateur.
eMemoryResource
Liste des ressources mémoire disponibles.
@ HostPinned
Alloue sur l'hôte.