Arcane  4.1.12.0
Developer documentation
Loading...
Searching...
No Matches
IBufferCopier.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/* IBufferCopier.h (C) 2000-2025 */
9/* */
10/* Interface for buffer copying. */
11/*---------------------------------------------------------------------------*/
12/*---------------------------------------------------------------------------*/
13#ifndef ARCANE_IMPL_IBUFFERCOPIER_H
14#define ARCANE_IMPL_IBUFFERCOPIER_H
15/*---------------------------------------------------------------------------*/
16/*---------------------------------------------------------------------------*/
17
18#include "arcane/utils/MemoryView.h"
20
21#include "arcane/core/GroupIndexTable.h"
22#include "arcane/accelerator/core/RunQueue.h"
23
24/*---------------------------------------------------------------------------*/
25/*---------------------------------------------------------------------------*/
26
27namespace Arcane
28{
29
30/*---------------------------------------------------------------------------*/
31/*---------------------------------------------------------------------------*/
32
42{
43 public:
44
45 virtual ~IBufferCopier() = default;
46
47 public:
48
49 virtual void copyFromBufferAsync(ConstArrayView<Int32> indexes,
50 ConstMemoryView buffer,
51 MutableMemoryView var_value) = 0;
52
53 virtual void copyToBufferAsync(ConstArrayView<Int32> indexes,
54 MutableMemoryView buffer,
55 ConstMemoryView var_value) = 0;
56
58 virtual void barrier() = 0;
59
60 public:
61
62 virtual void setRunQueue(const RunQueue& queue) = 0;
63};
64
65/*---------------------------------------------------------------------------*/
66/*---------------------------------------------------------------------------*/
67
68/*---------------------------------------------------------------------------*/
69/*---------------------------------------------------------------------------*/
70
72: public IBufferCopier
73{
74 public:
75
76 void copyFromBufferAsync(ConstArrayView<Int32> indexes,
77 ConstMemoryView buffer,
78 MutableMemoryView var_value) override
79 {
80 RunQueue* q = (m_queue.isNull()) ? nullptr : &m_queue;
81 MemoryUtils::copyWithIndexedSource(var_value, buffer, indexes, q);
82 }
83
84 void copyToBufferAsync(ConstArrayView<Int32> indexes,
85 MutableMemoryView buffer,
86 ConstMemoryView var_value) override
87 {
88 RunQueue* q = (m_queue.isNull()) ? nullptr : &m_queue;
89 MemoryUtils::copyWithIndexedDestination(buffer, var_value, indexes, q);
90 }
91
92 void barrier() override;
93 void setRunQueue(const RunQueue& queue) override { m_queue = queue; }
94
95 private:
96
97 RunQueue m_queue;
98};
99
100/*---------------------------------------------------------------------------*/
101/*---------------------------------------------------------------------------*/
102
103class TableBufferCopier
104: public IBufferCopier
105{
106 public:
107
108 explicit TableBufferCopier(GroupIndexTable* table)
109 : m_table(table)
110 {}
111
112 void copyFromBufferAsync(ConstArrayView<Int32> indexes,
113 ConstMemoryView buffer,
114 MutableMemoryView var_value) override
115 {
117 _buildFinalIndexes(final_indexes, indexes);
118 m_base_copier.copyFromBufferAsync(final_indexes, buffer, var_value);
119 }
120
121 void copyToBufferAsync(ConstArrayView<Int32> indexes,
122 MutableMemoryView buffer,
123 ConstMemoryView var_value) override
124 {
126 _buildFinalIndexes(final_indexes, indexes);
127 m_base_copier.copyToBufferAsync(final_indexes, buffer, var_value);
128 }
129 void barrier() override { m_base_copier.barrier(); }
130
131 void setRunQueue(const RunQueue& queue) override { m_base_copier.setRunQueue(queue); }
132
133 private:
134
135 GroupIndexTable* m_table = nullptr;
136 DirectBufferCopier m_base_copier;
137
138 private:
139
140 void _buildFinalIndexes(Array<Int32>& final_indexes, ConstArrayView<Int32> orig_indexes)
141 {
142 // TODO: do this allocation only once and keep it.
143 // Check to allocate on the device if we are on GPU (in this case, it
144 // would need to run the following code on the device as well)
145 GroupIndexTable& table = *m_table;
146 Int32 n = orig_indexes.size();
147 final_indexes.resize(n);
148 for (Int32 i = 0; i < n; ++i)
149 final_indexes[i] = table[orig_indexes[i]];
150 }
151};
152
153/*---------------------------------------------------------------------------*/
154/*---------------------------------------------------------------------------*/
155
156} // End namespace Arcane
157
158/*---------------------------------------------------------------------------*/
159/*---------------------------------------------------------------------------*/
160
161#endif
Memory and allocator management functions.
Constant view of an array of type T.
Constant view on a contiguous memory region containing fixed-size elements.
void barrier() override
Blocks until the copies are finished.
Base class of a hash table between group items and their positions in the table.
Interface for copying elements between two regions with indexing.
virtual void barrier()=0
Blocks until the copies are finished.
Mutable view on a contiguous memory region containing fixed-size elements.
void barrier() override
Blocks until the copies are finished.
1D data vector with value semantics (STL style).
void copyWithIndexedDestination(MutableMemoryView destination, ConstMemoryView source, SmallSpan< const Int32 > indexes, RunQueue *run_queue=nullptr)
Memory copy with indirection.
IMemoryAllocator * getDefaultDataAllocator()
Default allocator for data.
void copyWithIndexedSource(MutableMemoryView destination, ConstMemoryView source, SmallSpan< const Int32 > indexes, RunQueue *run_queue=nullptr)
Copies data on the host with indirection.
-- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature --