14#include "arcane/accelerator/core/internal/ReduceMemoryImpl.h"
16#include "arcane/utils/CheckedConvert.h"
17#include "arcane/utils/PlatformUtils.h"
18#include "arcane/utils/IMemoryRessourceMng.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
43ReduceMemoryImpl(RunCommandImpl* p)
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::
76allocateReduceDataMemory(ConstMemoryView identity_view)
78 auto identity_span = identity_view.bytes();
79 Int32 data_type_size =
static_cast<Int32
>(identity_span.size());
80 m_data_type_size = data_type_size;
81 if (data_type_size > m_size)
82 _allocateMemoryForReduceData(data_type_size);
86 m_identity_buffer.copy(identity_view.bytes());
87 MemoryCopyArgs copy_args(m_device_memory, m_identity_buffer.span().data(), data_type_size);
88 m_command->internalStream()->copyMemory(copy_args.addAsync());
90 return m_device_memory;
96void ReduceMemoryImpl::
97_allocateGridDataMemory()
101 Int32 total_size = CheckedConvert::toInt32(m_data_type_size * m_grid_size);
102 if (total_size <= m_grid_memory_info.m_grid_memory_values.bytes().size())
105 m_grid_buffer.resize(total_size);
107 auto mem_view = makeMutableMemoryView(m_grid_buffer.span());
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;
127 MemoryCopyArgs copy_args(ptr, &zero, size);
128 m_command->internalStream()->copyMemory(copy_args);
134void ReduceMemoryImpl::
135copyReduceValueFromDevice()
137 void* destination = m_grid_memory_info.m_host_memory_for_reduced_value;
138 void* source = m_device_memory;
139 MemoryCopyArgs copy_args(destination, source, m_data_type_size);
140 m_command->internalStream()->copyMemory(copy_args);
146extern "C++" IReduceMemoryImpl*
147internalGetOrCreateReduceMemoryImpl(RunCommand* command)
149 return command->m_p->getOrCreateReduceMemoryImpl();
virtual IMemoryAllocator * getAllocator(eMemoryRessource r)=0
Allocateur mémoire pour la ressource r.
eMemoryRessource
Liste des ressources mémoire disponibles.
@ HostPinned
Alloue sur l'hôte.
@ Device
Alloue sur le device.