12#ifndef ARCANE_ACCELERATOR_COMMONUTILS_H
13#define ARCANE_ACCELERATOR_COMMONUTILS_H
17#include "arcane/utils/Array.h"
19#include "arcane/accelerator/AcceleratorGlobal.h"
20#include "arcane/accelerator/core/RunQueue.h"
21#include "arcane/accelerator/AcceleratorUtils.h"
23#if defined(ARCANE_COMPILING_HIP)
24#include "arcane/accelerator/hip/HipAccelerator.h"
25#include <hip/hip_runtime.h>
26#include <rocprim/rocprim.hpp>
28#if defined(ARCANE_COMPILING_CUDA)
29#include "arcane/accelerator/cuda/CudaAccelerator.h"
32#if defined(ARCANE_COMPILING_SYCL) && defined(__INTEL_LLVM_COMPILER)
33#include <oneapi/dpl/execution>
34#include <oneapi/dpl/algorithm>
40namespace Arcane::Accelerator::impl
61 void* address() {
return m_storage.data(); }
62 size_t size()
const {
return m_storage.largeSize(); }
63 void* allocate(
size_t new_size)
65 m_storage.resize(new_size);
66 return m_storage.data();
76 return m_storage.span();
108template <
typename DataType, Int32 N = 1>
114 DataType* address() {
return reinterpret_cast<DataType*
>(m_storage.address()); }
115 size_t size()
const {
return m_storage.size(); }
118 m_storage.allocate(
sizeof(DataType) * N);
121 void deallocate() { m_storage.deallocate(); }
141 using value_type =
Int32;
142 using iterator_category = std::random_access_iterator_tag;
143 using reference = value_type&;
144 using difference_type = ptrdiff_t;
145 using pointer = void;
177 return m_value - x.m_value;
179 ARCCORE_HOST_DEVICE
Int32 operator*()
const {
return m_value; }
180 ARCCORE_HOST_DEVICE
Int32 operator[](
Int32 x)
const {
return m_value + x; }
183 return a.m_value == b.m_value;
185 ARCCORE_HOST_DEVICE
friend bool operator<(
const ThatClass& iter1,
const ThatClass& iter2)
187 return iter1.m_value < iter2.m_value;
199template <
typename DataType>
204 constexpr ARCCORE_HOST_DEVICE DataType operator()(
const DataType& a,
const DataType& b)
const
208 static DataType defaultValue() {
return {}; }
209#if defined(ARCANE_COMPILING_SYCL)
210 static sycl::plus<DataType> syclFunctor() {
return {}; }
218template <
typename DataType>
223 constexpr ARCCORE_HOST_DEVICE DataType operator()(
const DataType& a,
const DataType& b)
const
225 return (a < b) ? a : b;
227 static DataType defaultValue() {
return std::numeric_limits<DataType>::max(); }
228#if defined(ARCANE_COMPILING_SYCL)
229 static sycl::minimum<DataType> syclFunctor() {
return {}; }
237template <
typename DataType>
242 constexpr ARCCORE_HOST_DEVICE DataType operator()(
const DataType& a,
const DataType& b)
const
244 return (a < b) ? b : a;
246 static DataType defaultValue() {
return std::numeric_limits<DataType>::lowest(); }
247#if defined(ARCANE_COMPILING_SYCL)
248 static sycl::maximum<DataType> syclFunctor() {
return {}; }
257template <
typename DataType,
typename GetterLambda>
262 using value_type = DataType;
263 using iterator_category = std::random_access_iterator_tag;
264 using reference = DataType&;
265 using difference_type = ptrdiff_t;
266 using pointer = void;
281 ARCCORE_HOST_DEVICE ThatClass& operator++()
286 ARCCORE_HOST_DEVICE ThatClass& operator+=(
Int32 x)
291 ARCCORE_HOST_DEVICE
friend ThatClass operator+(
const ThatClass& iter,
Int32 x)
293 return ThatClass(iter.m_lambda, iter.m_index + x);
295 ARCCORE_HOST_DEVICE
friend ThatClass operator+(
Int32 x,
const ThatClass& iter)
297 return ThatClass(iter.m_lambda, iter.m_index + x);
299 ARCCORE_HOST_DEVICE
friend bool operator<(
const ThatClass& iter1,
const ThatClass& iter2)
301 return iter1.m_index < iter2.m_index;
304 ARCCORE_HOST_DEVICE ThatClass operator-(
Int32 x)
const
306 return ThatClass(m_lambda, m_index - x);
308 ARCCORE_HOST_DEVICE
Int32 operator-(
const ThatClass& x)
const
310 return m_index - x.m_index;
312 ARCCORE_HOST_DEVICE value_type operator*()
const
314 return m_lambda(m_index);
316 ARCCORE_HOST_DEVICE value_type operator[](
Int32 x)
const {
return m_lambda(m_index + x); }
317 ARCCORE_HOST_DEVICE
friend bool operator!=(
const ThatClass& a,
const ThatClass& b)
319 return a.m_index != b.m_index;
321 ARCCORE_HOST_DEVICE
friend bool operator==(
const ThatClass& a,
const ThatClass& b)
323 return a.m_index == b.m_index;
329 GetterLambda m_lambda;
339template <
typename SetterLambda>
349 ARCCORE_HOST_DEVICE
explicit Setter(
const SetterLambda& s,
Int32 output_index)
350 : m_output_index(output_index)
353 ARCCORE_HOST_DEVICE
void operator=(
Int32 input_index)
355 m_lambda(input_index, m_output_index);
357 Int32 m_output_index = 0;
358 SetterLambda m_lambda;
361 using value_type =
Int32;
362 using iterator_category = std::random_access_iterator_tag;
364 using difference_type = ptrdiff_t;
365 using pointer = void;
381 ARCCORE_HOST_DEVICE SetterLambdaIterator<SetterLambda>& operator++()
386 ARCCORE_HOST_DEVICE SetterLambdaIterator<SetterLambda>& operator--()
391 ARCCORE_HOST_DEVICE reference operator*()
const
393 return Setter(m_lambda, m_index);
395 ARCCORE_HOST_DEVICE reference operator[](Int32 x)
const {
return Setter(m_lambda, m_index + x); }
396 ARCCORE_HOST_DEVICE
friend ThatClass operator+(Int32 x,
const ThatClass& iter)
398 return ThatClass(iter.m_lambda, iter.m_index + x);
400 ARCCORE_HOST_DEVICE
friend ThatClass operator+(
const ThatClass& iter, Int32 x)
402 return ThatClass(iter.m_lambda, iter.m_index + x);
404 ARCCORE_HOST_DEVICE Int32 operator-(
const ThatClass& x)
const
406 return m_index - x.m_index;
408 ARCCORE_HOST_DEVICE
friend bool operator<(
const ThatClass& iter1,
const ThatClass& iter2)
410 return iter1.m_index < iter2.m_index;
416 SetterLambda m_lambda;
433template <
typename DataType>
using ScannerSumOperator = impl::SumOperator<DataType>;
434template <
typename DataType>
using ScannerMaxOperator = impl::MaxOperator<DataType>;
435template <
typename DataType>
using ScannerMinOperator = impl::MinOperator<DataType>;
File d'exécution pour un accélérateur.
void _copyToAsync(Span< std::byte > destination, Span< const std::byte > source, const RunQueue &queue)
Copie l'instance dans dest_ptr.
void copyToAsync(SmallSpan< DataType > dest_ptr, const RunQueue &queue)
Copie l'instance dans dest_ptr.
Itérateur sur une lambda pour récupérer une valeur via un index.
Opérateur de Scan/Reduce pour le maximum.
Opérateur de Scan/Reduce pour le minimum.
Permet de positionner un élément de l'itérateur de sortie.
Itérateur sur une lambda pour positionner une valeur via un index.
Opérateur de Scan/Reduce pour les sommes.
Vue d'un tableau d'éléments de type T.
Vue d'un tableau d'éléments de type T.
Vecteur 1D de données avec sémantique par valeur (style STL).
Espace de nom pour l'utilisation des accélérateurs.
detail::SpanTypeFromSize< std::byte, SizeType >::SpanType asWritableBytes(const SpanImpl< DataType, SizeType, Extent > &s)
Converti la vue en un tableau d'octets modifiables.
std::int32_t Int32
Type entier signé sur 32 bits.