14#include "arcane/utils/MemoryView.h"
16#include "arcane/utils/FatalErrorException.h"
17#include "arcane/utils/internal/SpecificMemoryCopyList.h"
36 using InterfaceType = ISpecificMemoryCopy;
37 template <
typename DataType,
typename Extent>
using SpecificType = SpecificMemoryCopy<DataType, Extent>;
38 using RefType = SpecificMemoryCopyRef<IndexedCopyTraits>;
55 impl::SpecificMemoryCopyList<impl::IndexedCopyTraits> global_copy_list;
56 impl::ISpecificMemoryCopyList* default_global_copy_list =
nullptr;
58 impl::ISpecificMemoryCopyList* _getDefaultCopyList(
RunQueue* queue)
60 if (queue && !default_global_copy_list)
61 ARCANE_FATAL(
"No instance of copier is available for RunQueue");
62 if (default_global_copy_list && queue)
63 return default_global_copy_list;
64 return &global_copy_list;
66 Int32 _checkDataTypeSize(
const TraceInfo& trace, Int32 data_size1, Int32 data_size2)
68 if (data_size1 != data_size2)
69 throw FatalErrorException(trace, String::format(
"Datatype size are not equal this={0} v={1}", data_size1, data_size2));
77void impl::ISpecificMemoryCopyList::
78setDefaultCopyListIfNotSet(ISpecificMemoryCopyList* ptr)
80 if (!default_global_copy_list) {
81 default_global_copy_list = ptr;
88void MutableMemoryView::
89copyHost(ConstMemoryView v)
const
91 auto source = v.bytes();
92 auto destination = bytes();
93 Int64 source_size = source.size();
96 Int64 destination_size = destination.size();
97 if (source_size > destination_size)
98 ARCANE_FATAL(
"Destination is too small source_size={0} destination_size={1}",
99 source_size, destination_size);
100 auto* dest_data = destination.data();
101 auto* source_data = source.data();
104 std::memmove(destination.data(), source.data(), source_size);
110void MutableMemoryView::
111copyFromIndexesHost(ConstMemoryView v, Span<const Int32> indexes)
const
113 copyFromIndexes(v, indexes.smallView(),
nullptr);
116void MutableMemoryView::
117copyFromIndexes(ConstMemoryView v, SmallSpan<const Int32> indexes,
118 RunQueue* queue)
const
121 Int32 one_data_size = _checkDataTypeSize(A_FUNCINFO, m_datatype_size, v.datatypeSize());
123 Int64 nb_index = indexes.size();
127 auto source = v.bytes();
128 auto destination = bytes();
130 _getDefaultCopyList(queue)->copyFrom(one_data_size, { indexes, source, destination, queue });
136void MutableMemoryView::
137fillIndexes(ConstMemoryView v, SmallSpan<const Int32> indexes,
138 RunQueue* queue)
const
140 Int32 one_data_size = _checkDataTypeSize(A_FUNCINFO, m_datatype_size, v.datatypeSize());
142 Int64 nb_index = indexes.size();
146 auto source = v.bytes();
147 auto destination = bytes();
149 _getDefaultCopyList(queue)->fill(one_data_size, { indexes, source, destination, queue });
155void MutableMemoryView::
156fill(ConstMemoryView v, RunQueue* queue)
const
158 Int32 one_data_size = _checkDataTypeSize(A_FUNCINFO, m_datatype_size, v.datatypeSize());
160 auto source = v.bytes();
161 auto destination = bytes();
163 _getDefaultCopyList(queue)->fill(one_data_size, { {}, source, destination, queue });
169void ConstMemoryView::
170copyToIndexesHost(MutableMemoryView v, Span<const Int32> indexes)
const
172 copyToIndexes(v, indexes.smallView(),
nullptr);
175void ConstMemoryView::
176copyToIndexes(MutableMemoryView v, SmallSpan<const Int32> indexes,
177 RunQueue* queue)
const
179 Int32 one_data_size = _checkDataTypeSize(A_FUNCINFO, m_datatype_size, v.datatypeSize());
181 Int64 nb_index = indexes.size();
185 auto source = bytes();
186 auto destination = v.bytes();
188 _getDefaultCopyList(queue)->copyTo(one_data_size, { indexes, source, destination, queue });
195makeMutableMemoryView(
void* ptr, Int32 datatype_size, Int64 nb_element)
197 Span<std::byte> bytes(
reinterpret_cast<std::byte*
>(ptr), datatype_size * nb_element);
198 return { bytes, datatype_size, nb_element };
205makeConstMemoryView(
const void* ptr, Int32 datatype_size, Int64 nb_element)
207 Span<const std::byte> bytes(
reinterpret_cast<const std::byte*
>(ptr), datatype_size * nb_element);
208 return { bytes, datatype_size, nb_element };
217void MutableMultiMemoryView::
218copyFromIndexes(ConstMemoryView v, SmallSpan<const Int32> indexes,
221 Int32 one_data_size = _checkDataTypeSize(A_FUNCINFO, m_datatype_size, v.datatypeSize());
223 Int64 nb_index = indexes.size();
227 _getDefaultCopyList(queue)->copyFrom(one_data_size, { indexes, m_views, v.bytes(), queue });
233void MutableMultiMemoryView::
234fillIndexes(ConstMemoryView v, SmallSpan<const Int32> indexes, RunQueue* queue)
236 Int32 one_data_size = _checkDataTypeSize(A_FUNCINFO, m_datatype_size, v.datatypeSize());
238 Int64 nb_index = indexes.size();
242 _getDefaultCopyList(queue)->fill(one_data_size, { indexes, m_views, v.bytes(), queue });
248void MutableMultiMemoryView::
249fill(ConstMemoryView v, RunQueue* queue)
251 Int32 one_data_size = _checkDataTypeSize(A_FUNCINFO, m_datatype_size, v.datatypeSize());
253 _getDefaultCopyList(queue)->fill(one_data_size, { {}, m_views, v.bytes(), queue });
259void ConstMultiMemoryView::
260copyToIndexes(MutableMemoryView v, SmallSpan<const Int32> indexes,
263 Int32 one_data_size = _checkDataTypeSize(A_FUNCINFO, m_datatype_size, v.datatypeSize());
265 Int64 nb_index = indexes.size();
269 _getDefaultCopyList(queue)->copyTo(one_data_size, { indexes, m_views, v.bytes(), queue });
275extern "C++" ARCANE_UTILS_EXPORT
void
276arcanePrintSpecificMemoryStats()
#define ARCANE_CHECK_POINTER(ptr)
Macro retournant le pointeur ptr s'il est non nul ou lancant une exception s'il est nul.
#define ARCANE_FATAL(...)
Macro envoyant une exception FatalErrorException.
File d'exécution pour un accélérateur.
-*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
bool arcaneIsCheck()
Vrai si on est en mode vérification.