Arcane  v4.1.1.0
Documentation développeur
Chargement...
Recherche...
Aucune correspondance
HostSpecificMemoryCopy.h
1// -*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
2//-----------------------------------------------------------------------------
3// Copyright 2000-2025 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/* HostSpecificMemoryCopy.h (C) 2000-2025 */
9/* */
10/* Classe template pour gérer des fonctions spécialisées de copie mémoire. */
11/*---------------------------------------------------------------------------*/
12#ifndef ARCCORE_COMMON_INTERNAL_HOSTSPECIFICMEMORYCOPYLIST_H
13#define ARCCORE_COMMON_INTERNAL_HOSTSPECIFICMEMORYCOPYLIST_H
14/*---------------------------------------------------------------------------*/
15/*---------------------------------------------------------------------------*/
16
17#include "arccore/common/internal/SpecificMemoryCopyList.h"
18
19/*---------------------------------------------------------------------------*/
20/*---------------------------------------------------------------------------*/
21
22namespace Arcane::impl
23{
24
25/*---------------------------------------------------------------------------*/
26/*---------------------------------------------------------------------------*/
30template <typename DataType, typename Extent>
32: public SpecificMemoryCopyBase<DataType, Extent>
33{
35 using BaseClass::_toTrueType;
36
37 public:
38
39 using BaseClass::m_extent;
40
41 public:
42
43 void copyFrom(const IndexedMemoryCopyArgs& args) override
44 {
45 _copyFrom(args.m_indexes, _toTrueType(args.m_source), _toTrueType(args.m_destination));
46 }
47 void copyTo(const IndexedMemoryCopyArgs& args) override
48 {
49 _copyTo(args.m_indexes, _toTrueType(args.m_source), _toTrueType(args.m_destination));
50 }
51 void fill(const IndexedMemoryCopyArgs& args) override
52 {
53 _fill(args.m_indexes, _toTrueType(args.m_source), _toTrueType(args.m_destination));
54 }
55 void copyFrom(const IndexedMultiMemoryCopyArgs& args) override
56 {
57 _copyFrom(args.m_indexes, args.m_multi_memory, _toTrueType(args.m_source_buffer));
58 }
59 void copyTo(const IndexedMultiMemoryCopyArgs& args) override
60 {
61 _copyTo(args.m_indexes, args.m_const_multi_memory, _toTrueType(args.m_destination_buffer));
62 }
63 void fill(const IndexedMultiMemoryCopyArgs& args) override
64 {
65 _fill(args.m_indexes, args.m_multi_memory, _toTrueType(args.m_source_buffer));
66 }
67
68 public:
69
70 void _copyFrom(SmallSpan<const Int32> indexes, Span<const DataType> source,
71 Span<DataType> destination)
72 {
73 ARCCORE_CHECK_POINTER(indexes.data());
74 ARCCORE_CHECK_POINTER(source.data());
75 ARCCORE_CHECK_POINTER(destination.data());
76
77 Int32 nb_index = indexes.size();
78 for (Int32 i = 0; i < nb_index; ++i) {
79 Int64 z_index = (Int64)i * m_extent.v;
80 Int64 zci = (Int64)(indexes[i]) * m_extent.v;
81 for (Int32 z = 0, n = m_extent.v; z < n; ++z)
82 destination[z_index + z] = source[zci + z];
83 }
84 }
85 void _copyFrom(SmallSpan<const Int32> indexes, SmallSpan<Span<std::byte>> multi_views,
87 {
88 ARCCORE_CHECK_POINTER(indexes.data());
89 ARCCORE_CHECK_POINTER(source.data());
90 ARCCORE_CHECK_POINTER(multi_views.data());
91
92 const Int32 value_size = indexes.size() / 2;
93 for (Int32 i = 0; i < value_size; ++i) {
94 Int32 index0 = indexes[i * 2];
95 Int32 index1 = indexes[(i * 2) + 1];
96 Span<std::byte> orig_view_bytes = multi_views[index0];
97 auto* orig_view_data = reinterpret_cast<DataType*>(orig_view_bytes.data());
98 // Utilise un span pour tester les débordements de tableau mais on
99 // pourrait directement utiliser 'orig_view_data' pour plus de performances
100 Span<DataType> orig_view = { orig_view_data, orig_view_bytes.size() / (Int64)sizeof(DataType) };
101 Int64 zci = ((Int64)(index1)) * m_extent.v;
102 Int64 z_index = (Int64)i * m_extent.v;
103 for (Int32 z = 0, n = m_extent.v; z < n; ++z)
104 orig_view[zci + z] = source[z_index + z];
105 }
106 }
107
114 Span<DataType> destination)
115 {
116 ARCCORE_CHECK_POINTER(source.data());
117 ARCCORE_CHECK_POINTER(destination.data());
118
119 // Si \a indexes est vide, cela signifie qu'on copie toutes les valeurs
120 Int32 nb_index = indexes.size();
121 if (nb_index == 0) {
122 Int64 nb_value = destination.size() / m_extent.v;
123 for (Int64 i = 0; i < nb_value; ++i) {
124 Int64 zci = i * m_extent.v;
125 for (Int32 z = 0, n = m_extent.v; z < n; ++z)
126 destination[zci + z] = source[z];
127 }
128 }
129 else {
130 ARCCORE_CHECK_POINTER(indexes.data());
131 for (Int32 i = 0; i < nb_index; ++i) {
132 Int64 zci = (Int64)(indexes[i]) * m_extent.v;
133 for (Int32 z = 0, n = m_extent.v; z < n; ++z)
134 destination[zci + z] = source[z];
135 }
136 }
137 }
138
139 void _fill(SmallSpan<const Int32> indexes, SmallSpan<Span<std::byte>> multi_views,
141 {
142 ARCCORE_CHECK_POINTER(source.data());
143 ARCCORE_CHECK_POINTER(multi_views.data());
144
145 const Int32 nb_index = indexes.size() / 2;
146 if (nb_index == 0) {
147 // Remplit toutes les valeurs du tableau avec la source.
148 const Int32 nb_dim1 = multi_views.size();
149 for (Int32 zz = 0; zz < nb_dim1; ++zz) {
150 Span<std::byte> orig_view_bytes = multi_views[zz];
151 Int64 nb_value = orig_view_bytes.size() / ((Int64)sizeof(DataType));
152 auto* orig_view_data = reinterpret_cast<DataType*>(orig_view_bytes.data());
153 Span<DataType> orig_view = { orig_view_data, nb_value };
154 for (Int64 i = 0; i < nb_value; i += m_extent.v) {
155 // Utilise un span pour tester les débordements de tableau mais on
156 // pourrait directement utiliser 'orig_view_data' pour plus de performances
157 for (Int32 z = 0, n = m_extent.v; z < n; ++z) {
158 orig_view[i + z] = source[z];
159 }
160 }
161 }
162 }
163 else {
164 ARCCORE_CHECK_POINTER(indexes.data());
165 for (Int32 i = 0; i < nb_index; ++i) {
166 Int32 index0 = indexes[i * 2];
167 Int32 index1 = indexes[(i * 2) + 1];
168 Span<std::byte> orig_view_bytes = multi_views[index0];
169 auto* orig_view_data = reinterpret_cast<DataType*>(orig_view_bytes.data());
170 // Utilise un span pour tester les débordements de tableau mais on
171 // pourrait directement utiliser 'orig_view_data' pour plus de performances
172 Span<DataType> orig_view = { orig_view_data, orig_view_bytes.size() / (Int64)sizeof(DataType) };
173 Int64 zci = ((Int64)(index1)) * m_extent.v;
174 for (Int32 z = 0, n = m_extent.v; z < n; ++z)
175 orig_view[zci + z] = source[z];
176 }
177 }
178 }
179
180 void _copyTo(SmallSpan<const Int32> indexes, Span<const DataType> source,
181 Span<DataType> destination)
182 {
183 ARCCORE_CHECK_POINTER(indexes.data());
184 ARCCORE_CHECK_POINTER(source.data());
185 ARCCORE_CHECK_POINTER(destination.data());
186
187 Int32 nb_index = indexes.size();
188
189 for (Int32 i = 0; i < nb_index; ++i) {
190 Int64 z_index = (Int64)i * m_extent.v;
191 Int64 zci = (Int64)(indexes[i]) * m_extent.v;
192 for (Int32 z = 0, n = m_extent.v; z < n; ++z)
193 destination[zci + z] = source[z_index + z];
194 }
195 }
196
197 void _copyTo(SmallSpan<const Int32> indexes, SmallSpan<const Span<const std::byte>> multi_views,
198 Span<DataType> destination)
199 {
200 ARCCORE_CHECK_POINTER(indexes.data());
201 ARCCORE_CHECK_POINTER(destination.data());
202 ARCCORE_CHECK_POINTER(multi_views.data());
203
204 const Int32 value_size = indexes.size() / 2;
205 for (Int32 i = 0; i < value_size; ++i) {
206 Int32 index0 = indexes[i * 2];
207 Int32 index1 = indexes[(i * 2) + 1];
208 Span<const std::byte> orig_view_bytes = multi_views[index0];
209 auto* orig_view_data = reinterpret_cast<const DataType*>(orig_view_bytes.data());
210 // Utilise un span pour tester les débordements de tableau mais on
211 // pourrait directement utiliser 'orig_view_data' pour plus de performances
212 Span<const DataType> orig_view = { orig_view_data, orig_view_bytes.size() / (Int64)sizeof(DataType) };
213 Int64 zci = ((Int64)(index1)) * m_extent.v;
214 Int64 z_index = (Int64)i * m_extent.v;
215 for (Int32 z = 0, n = m_extent.v; z < n; ++z)
216 destination[z_index + z] = orig_view[zci + z];
217 }
218 }
219};
220
221/*---------------------------------------------------------------------------*/
222/*---------------------------------------------------------------------------*/
223
224} // namespace Arcane::impl
225
226/*---------------------------------------------------------------------------*/
227/*---------------------------------------------------------------------------*/
228
229#endif
Vue d'un tableau d'éléments de type T.
Definition Span.h:801
constexpr __host__ __device__ pointer data() const noexcept
Pointeur sur le début de la vue.
Definition Span.h:537
constexpr __host__ __device__ SizeType size() const noexcept
Retourne la taille du tableau.
Definition Span.h:325
Vue d'un tableau d'éléments de type T.
Definition Span.h:633
Implémentation des copies et du remplissage sur hôte.
void _fill(SmallSpan< const Int32 > indexes, Span< const DataType > source, Span< DataType > destination)
Remplit les valeurs d'indices spécifiés par indexes.
Arguments pour une copie de certains indices entre deux zones mémoire.
Arguments pour une copie de certains indices vers/depuis une zone mémoire multiple.
std::int64_t Int64
Type entier signé sur 64 bits.
std::int32_t Int32
Type entier signé sur 32 bits.