Arcane  4.1.12.0
Developer documentation
Loading...
Searching...
No Matches
ReduceMemoryImpl.h
1// -*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
2//-----------------------------------------------------------------------------
3// Copyright 2000-2026 CEA (www.cea.fr) IFPEN (www.ifpenergiesnouvelles.com)
4// See the top-level COPYRIGHT file for details.
5// SPDX-License-Identifier: Apache-2.0
6//-----------------------------------------------------------------------------
7/*---------------------------------------------------------------------------*/
8/* ReduceMemoryImpl.h (C) 2000-2025 */
9/* */
10/* Memory management for reductions. */
11/*---------------------------------------------------------------------------*/
12#ifndef ARCCORE_COMMON_ACCELERATOR_INTERNAL_REDUCEMEMORYIMPL_H
13#define ARCCORE_COMMON_ACCELERATOR_INTERNAL_REDUCEMEMORYIMPL_H
14/*---------------------------------------------------------------------------*/
15/*---------------------------------------------------------------------------*/
16
17#include "arccore/common/accelerator/IReduceMemoryImpl.h"
18
19#include "arccore/common/Array.h"
20
21/*---------------------------------------------------------------------------*/
22/*---------------------------------------------------------------------------*/
23
24namespace Arcane::Accelerator::Impl
25{
26
27/*---------------------------------------------------------------------------*/
28/*---------------------------------------------------------------------------*/
29
30class ReduceMemoryImpl
31: public IReduceMemoryImpl
32{
33 public:
34
35 explicit ReduceMemoryImpl(RunCommandImpl* p);
36
37 public:
38
39 void allocateReduceDataMemory(Int32 data_type_size) override;
40 void setGridSizeAndAllocate(Int32 grid_size) override
41 {
42 m_grid_size = grid_size;
43 _allocateGridDataMemory();
44 }
45 Int32 gridSize() const override { return m_grid_size; }
46
48 {
49 return m_grid_memory_info;
50 }
51 void release() override;
52
53 private:
54
55 RunCommandImpl* m_command = nullptr;
56
59
62
65
68
69 GridMemoryInfo m_grid_memory_info;
70
73
76
82
83 private:
84
85 void _allocateGridDataMemory();
86 void _allocateMemoryForGridDeviceCount();
87 void _setReducePolicy();
88 void _allocateMemoryForReduceData(Int32 new_size);
89};
90
91/*---------------------------------------------------------------------------*/
92/*---------------------------------------------------------------------------*/
93
94} // namespace Arcane::Accelerator::Impl
95
96/*---------------------------------------------------------------------------*/
97/*---------------------------------------------------------------------------*/
98
99#endif
UniqueArray< std::byte > m_host_memory_bytes
Allocation for the reduced data in host memory.
void release() override
Releases the instance.
UniqueArray< Byte > m_grid_buffer
Array containing the reduction value for each block of a grid.
UniqueArray< unsigned int > m_grid_device_count
Array of 1 unsigned integer containing the number of grids that have already performed the reduction.
UniqueArray< std::byte > m_identity_buffer
Buffer to store the identity value.
void setGridSizeAndAllocate(Int32 grid_size) override
Sets the GPU grid size (the number of blocks) and allocates memory.
void allocateReduceDataMemory(Int32 data_type_size) override
Allocates memory for a data item that needs to be reduced.
Int32 gridSize() const override
GPU grid size (number of blocks).
GridMemoryInfo gridMemoryInfo() override
Information about the memory used by the reduction.
Int64 m_size
Size allocated for m_device_memory.
Int32 m_grid_size
Current grid size (number of blocks).
1D data vector with value semantics (STL style).
std::int64_t Int64
Signed integer type of 64 bits.
std::int32_t Int32
Signed integer type of 32 bits.