Arcane  4.1.12.0
Developer documentation
Loading...
Searching...
No Matches
DataOperation.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/* DataOperation.h (C) 2000-2024 */
9/* */
10/* Data operation. */
11/*---------------------------------------------------------------------------*/
12#ifndef ARCANE_IMPL_DATAOPERATION_H
13#define ARCANE_IMPL_DATAOPERATION_H
14/*---------------------------------------------------------------------------*/
15/*---------------------------------------------------------------------------*/
16
18#include "arccore/base/Span.h"
19
20#include "arcane/utils/Real2.h"
21#include "arcane/utils/Real3.h"
22#include "arcane/utils/Real2x2.h"
23#include "arcane/utils/Real3x3.h"
24#include "arcane/utils/Float16.h"
25#include "arcane/utils/BFloat16.h"
26
27#include "arcane/datatype/IDataOperation.h"
28
29#include "arcane/Parallel.h"
30
31/*---------------------------------------------------------------------------*/
32/*---------------------------------------------------------------------------*/
33
34namespace Arcane
35{
36
37/*---------------------------------------------------------------------------*/
38/*---------------------------------------------------------------------------*/
39
40template <typename DataOperator>
41class DataOperationT
42: public IDataOperation
43{
44 public:
45
46 DataOperationT() {}
47 DataOperationT(const DataOperator& op)
48 : m_operator(op)
49 {}
50
51 private:
52
53 template <typename DataType> void
54 _applyView(ArrayView<DataType> output, ConstArrayView<DataType> input)
55 {
56 for (Int32 i = 0, n = input.size(); i < n; ++i)
57 output[i] = m_operator(output[i], input[i]);
58 }
59
60 public:
61
62 void apply(ByteArrayView output, ByteConstArrayView input) override
63 {
64 _applyView(output, input);
65 }
66 void apply(RealArrayView output, RealConstArrayView input) override
67 {
68 _applyView(output, input);
69 }
70 void apply(Int32ArrayView output, Int32ConstArrayView input) override
71 {
72 _applyView(output, input);
73 }
74 void apply(Int16ArrayView output, Int16ConstArrayView input) override
75 {
76 _applyView(output, input);
77 }
78 void apply(Int64ArrayView output, Int64ConstArrayView input) override
79 {
80 _applyView(output, input);
81 }
82 void apply(Real2ArrayView output, Real2ConstArrayView input) override
83 {
84 _applyView(output, input);
85 }
86 void apply(Real3ArrayView output, Real3ConstArrayView input) override
87 {
88 _applyView(output, input);
89 }
90 void apply(Real2x2ArrayView output, Real2x2ConstArrayView input) override
91 {
92 _applyView(output, input);
93 }
94 void apply(Real3x3ArrayView output, Real3x3ConstArrayView input) override
95 {
96 _applyView(output, input);
97 }
98 void apply(ArrayView<Int8> output, ConstArrayView<Int8> input) override
99 {
100 _applyView(output, input);
101 }
102 void apply(ArrayView<Float16> output, ConstArrayView<Float16> input) override
103 {
104 _applyView(output, input);
105 }
106 void apply(ArrayView<BFloat16> output, ConstArrayView<BFloat16> input) override
107 {
108 _applyView(output, input);
109 }
110 void apply(ArrayView<Float32> output, ConstArrayView<Float32> input) override
111 {
112 _applyView(output, input);
113 }
114
115 private:
116
117 template <typename DataType> void
118 _applySpan(Span<DataType> output, Span<const DataType> input)
119 {
120 for (Int64 i = 0, n = input.size(); i < n; ++i)
121 output[i] = m_operator(output[i], input[i]);
122 }
123
124 public:
125
126 void applySpan(Span<Byte> output, Span<const Byte> input) override
127 {
128 _applySpan(output, input);
129 }
130 void applySpan(Span<Real> output, Span<const Real> input) override
131 {
132 _applySpan(output, input);
133 }
134 void applySpan(Span<Int16> output, Span<const Int16> input) override
135 {
136 _applySpan(output, input);
137 }
138 void applySpan(Span<Int32> output, Span<const Int32> input) override
139 {
140 _applySpan(output, input);
141 }
142 void applySpan(Span<Int64> output, Span<const Int64> input) override
143 {
144 _applySpan(output, input);
145 }
146 void applySpan(Span<Real2> output, Span<const Real2> input) override
147 {
148 _applySpan(output, input);
149 }
150 void applySpan(Span<Real3> output, Span<const Real3> input) override
151 {
152 _applySpan(output, input);
153 }
154 void applySpan(Span<Real2x2> output, Span<const Real2x2> input) override
155 {
156 _applySpan(output, input);
157 }
158 void applySpan(Span<Real3x3> output, Span<const Real3x3> input) override
159 {
160 _applySpan(output, input);
161 }
162 void applySpan(Span<Int8> output, Span<const Int8> input) override
163 {
164 _applySpan(output, input);
165 }
166 void applySpan(Span<Float16> output, Span<const Float16> input) override
167 {
168 _applySpan(output, input);
169 }
170 void applySpan(Span<BFloat16> output, Span<const BFloat16> input) override
171 {
172 _applySpan(output, input);
173 }
174 void applySpan(Span<Float32> output, Span<const Float32> input) override
175 {
176 _applySpan(output, input);
177 }
178
179 private:
180
181 DataOperator m_operator;
182};
183
184/*---------------------------------------------------------------------------*/
185/*---------------------------------------------------------------------------*/
186
187extern "C++" ARCANE_IMPL_EXPORT IDataOperation*
188arcaneCreateDataOperation(Parallel::eReduceType rt);
189
190/*---------------------------------------------------------------------------*/
191/*---------------------------------------------------------------------------*/
192
193} // End namespace Arcane
194
195/*---------------------------------------------------------------------------*/
196/*---------------------------------------------------------------------------*/
197
198#endif
Types and functions associated with the classes SpanImpl, SmallSpan and Span.
Types and functions associated with the classes ArrayView and ConstArrayView.
Modifiable view of an array of type T.
Constant view of an array of type T.
constexpr Integer size() const noexcept
Number of elements in the array.
Interface of an operation on a data.
constexpr __host__ __device__ SizeType size() const noexcept
Returns the size of the array.
Definition Span.h:327
View of an array of elements of type T.
Definition Span.h:635
eReduceType
Supported reduction types.
-- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature --
ArrayView< Int64 > Int64ArrayView
C equivalent of a 1D array of 64-bit integers.
Definition UtilsTypes.h:451
ConstArrayView< Real3 > Real3ConstArrayView
C equivalent of a 1D array of Real3.
Definition UtilsTypes.h:496
ArrayView< Real2x2 > Real2x2ArrayView
C equivalent of a 1D array of Real2x2.
Definition UtilsTypes.h:469
ArrayView< Byte > ByteArrayView
C equivalent of a 1D array of characters.
Definition UtilsTypes.h:447
std::int64_t Int64
Signed integer type of 64 bits.
ArrayView< Real3 > Real3ArrayView
C equivalent of a 1D array of Real3.
Definition UtilsTypes.h:467
ArrayView< Int16 > Int16ArrayView
C equivalent of a 1D array of 16-bit integers.
Definition UtilsTypes.h:455
ConstArrayView< Int32 > Int32ConstArrayView
C equivalent of a 1D array of 32-bit integers.
Definition UtilsTypes.h:482
ArrayView< Real3x3 > Real3x3ArrayView
C equivalent of a 1D array of Real3x3.
Definition UtilsTypes.h:471
ConstArrayView< Int16 > Int16ConstArrayView
C equivalent of a 1D array of 16-bit integers.
Definition UtilsTypes.h:484
ConstArrayView< Int64 > Int64ConstArrayView
C equivalent of a 1D array of 64-bit integers.
Definition UtilsTypes.h:480
ArrayView< Int32 > Int32ArrayView
C equivalent of a 1D array of 32-bit integers.
Definition UtilsTypes.h:453
ConstArrayView< Byte > ByteConstArrayView
C equivalent of a 1D array of characters.
Definition UtilsTypes.h:476
ConstArrayView< Real2 > Real2ConstArrayView
C equivalent of a 1D array of Real2.
Definition UtilsTypes.h:494
ArrayView< Real2 > Real2ArrayView
C equivalent of a 1D array of Real2.
Definition UtilsTypes.h:465
ArrayView< Real > RealArrayView
C equivalent of a 1D array of reals.
Definition UtilsTypes.h:459
ConstArrayView< Real3x3 > Real3x3ConstArrayView
C equivalent of a 1D array of Real3x3.
Definition UtilsTypes.h:500
ConstArrayView< Real2x2 > Real2x2ConstArrayView
C equivalent of a 1D array of Real2x2.
Definition UtilsTypes.h:498
std::int32_t Int32
Signed integer type of 32 bits.
ConstArrayView< Real > RealConstArrayView
C equivalent of a 1D array of reals.
Definition UtilsTypes.h:488