60 virtual ~IModifierImpl() =
default;
65 virtual void resize(Int32 new_size) = 0;
66 virtual void endUpdate() = 0;
91 void resize(Int32 new_size) { m_p->resize(new_size); }
95 IModifierImpl* m_p =
nullptr;
121 class NumArrayModifierImpl
122 :
public IModifierImpl
136 void resize(Int32 new_size)
override
138 m_data->resizeDevice(new_size);
140 void endUpdate()
override
142 m_data->endUpdate(
true);
147 ThatClass* m_data =
nullptr;
150 class UniqueArrayModifierImpl
151 :
public IModifierImpl
153 friend class DualUniqueArray<DataType>;
157 UniqueArrayModifierImpl(ThatClass* v)
160 SmallSpan<DataType> view()
override
162 return m_data->m_array.view();
164 void resize(Int32 new_size)
override
166 m_data->m_array.resize(new_size);
168 void endUpdate()
override
170 m_data->endUpdate(
false);
175 ThatClass* m_data =
nullptr;
181 : m_numarray_modifier(this)
182 , m_array_modifier(this)
185 explicit DualUniqueArray(IMemoryAllocator* a)
188 m_array = UniqueArray<DataType>(a);
193 SmallSpan<const DataType> hostSmallSpan()
const {
return m_array.
view(); }
194 ConstArrayView<DataType> hostView()
const {
return m_array.
view(); }
196 void reserve(Int64 capacity)
200 void resizeHost(Int32 new_size)
203 m_is_valid_numarray =
false;
205 void fillHost(
const DataType& value)
208 m_is_valid_numarray =
false;
210 void resizeDevice(Int32 new_size)
212 _checkCreateNumArray();
213 m_device_array->resize(new_size);
214 m_is_valid_array =
false;
219 m_is_valid_numarray =
false;
221 Int64 size()
const {
return m_array.
size(); }
222 SmallSpan<const DataType> view(
bool is_device)
226 SmallSpan<const DataType> v = *(m_device_array.get());
230 return hostSmallSpan();
233 void sync(
bool is_device)
236 _checkUpdateDeviceView();
239 _checkUpdateHostView();
244 m_is_valid_array =
true;
245 m_is_valid_numarray =
false;
247 void endUpdate(
bool is_device)
249 m_is_valid_array = !is_device;
250 m_is_valid_numarray = is_device;
252 Modifier modifier(
bool is_device)
255 _checkCreateNumArray();
256 return Modifier(&m_numarray_modifier);
258 return Modifier(&m_array_modifier);
260 HostModifier hostModifier()
262 return HostModifier(
this);
267 UniqueArray<DataType> m_array;
268 std::unique_ptr<NumArrayType> m_device_array;
269 SmallSpan<DataType> m_device_view;
270 NumArrayModifierImpl m_numarray_modifier;
271 UniqueArrayModifierImpl m_array_modifier;
272 bool m_is_valid_array =
true;
273 bool m_is_valid_numarray =
false;
277 void _checkUpdateDeviceView()
279 if (!m_is_valid_numarray) {
280 _checkCreateNumArray();
281 MDSpan<DataType, MDDim1> s(m_array.data(), ArrayIndex<1>(m_array.size()));
282 m_device_array->copy(s);
283 m_is_valid_numarray =
true;
285 m_device_view = *(m_device_array.get());
287 void _checkUpdateHostView()
289 if (!m_is_valid_array) {
290 _checkCreateNumArray();
291 SmallSpan<const DataType> device_view = *(m_device_array.get());
292 m_array.resize(device_view.size());
294 m_is_valid_array =
true;
297 void _checkCreateNumArray()
299 if (!m_device_array) {
301 if (m_is_valid_array)
302 m_device_array->resize(m_array.size());
detail::SpanTypeFromSize< conststd::byte, SizeType >::SpanType asBytes(const SpanImpl< DataType, SizeType, Extent > &s)
Converti la vue en un tableau d'octets non modifiables.
detail::SpanTypeFromSize< std::byte, SizeType >::SpanType asWritableBytes(const SpanImpl< DataType, SizeType, Extent > &s)
Converti la vue en un tableau d'octets modifiables.