Arcane  4.1.12.0
User documentation
Loading...
Searching...
No Matches
SimdAVX512.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/* SimdAVX512.h (C) 2000-2016 */
9/* */
10/* Vectorization for AVX512. */
11/*---------------------------------------------------------------------------*/
12#ifndef ARCANE_UTILS_SIMDAVX512_H
13#define ARCANE_UTILS_SIMDAVX512_H
14/*---------------------------------------------------------------------------*/
15/*---------------------------------------------------------------------------*/
16
17/*
18 * This file should not be included directly.
19 * Use 'Simd.h' instead.
20 */
21
22/*---------------------------------------------------------------------------*/
23/*---------------------------------------------------------------------------*/
24
25// Define if you wish to directly use the AVX512 scatter/gather instructions.
26// There is no obvious reason not to do so.
27#define ARCANE_USE_AVX512_SCATTERGATHER
28
29/*---------------------------------------------------------------------------*/
30/*---------------------------------------------------------------------------*/
31
32namespace Arcane
33{
34
35/*---------------------------------------------------------------------------*/
36/*---------------------------------------------------------------------------*/
37
38/*!
39 * \ingroup ArcaneSimd
40 * \brief Vectorization of reals using AVX512 vectorization.
41 */
42class ARCANE_ALIGNAS_PACKED(64) AVX512SimdReal
43{
44 public:
45
46 static const int BLOCK_SIZE = 8;
47 enum
48 {
49 Length = 8
50 };
51 typedef AVXSimdX8Int32 Int32IndexType;
52
53 public:
54
55 __m512d v0;
56 AVX512SimdReal() {}
57 AVX512SimdReal(__m512d _v0)
58 : v0(_v0)
59 {}
60 explicit AVX512SimdReal(Real r)
61 : v0(_mm512_set1_pd(r))
62 {}
63
64 protected:
65
66 AVX512SimdReal(Real a7, Real a6, Real a5, Real a4, Real a3, Real a2, Real a1, Real a0)
67 : v0(_mm512_set_pd(a7, a6, a5, a4, a3, a2, a1, a0))
68 {}
69
70 public:
71
72 AVX512SimdReal(const Real* base, const Int32* idx)
73 {
74#ifdef ARCANE_USE_AVX512_SCATTERGATHER
75 __m256i idx2 = _mm256_loadu_si256((__m256i*)idx);
76 v0 = _mm512_i32gather_pd(idx2, (Real*)base, 8);
77#else
78 v0 = _mm512_set_pd(base[idx[7]], base[idx[6]], base[idx[5]], base[idx[4]],
79 base[idx[3]], base[idx[2]], base[idx[1]], base[idx[0]]);
80#endif
81 }
82 AVX512SimdReal(const Real* base, const Int32IndexType* simd_idx)
83 : AVX512SimdReal(base, (const Int32*)simd_idx)
84 {}
85
86 AVX512SimdReal(const Real* base, const Int32IndexType& simd_idx)
87#ifdef ARCANE_USE_AVX512_SCATTERGATHER
88 : v0(_mm512_i32gather_pd(simd_idx.v0, base, 8))
89#else
90 : AVX512SimdReal(base, (const Int32*)simd_idx)
91#endif
92 {
93 }
94
95 //! Loads continuous values located at the address \a base which must be aligned.
96 explicit AVX512SimdReal(const Real* base)
97 : v0(_mm512_load_pd(base))
98 {}
99
100 Real operator[](Integer i) const { return ((const Real*)&v0)[i]; }
101 Real& operator[](Integer i) { return ((Real*)&v0)[i]; }
102
103 // TODO: create an overload that takes a vector of Int32 with alignment directly.
104 void set(ARCANE_RESTRICT Real* base, const ARCANE_RESTRICT Int32* idx) const
105 {
106#ifdef ARCANE_USE_AVX512_SCATTERGATHER
107 __m256i idx2 = _mm256_loadu_si256((__m256i*)idx);
108 _mm512_i32scatter_pd(base, idx2, v0, 8);
109#else
110 const Real* x = (const Real*)(this);
111 base[idx[0]] = x[0];
112 base[idx[1]] = x[1];
113 base[idx[2]] = x[2];
114 base[idx[3]] = x[3];
115 base[idx[4]] = x[4];
116 base[idx[5]] = x[5];
117 base[idx[6]] = x[6];
118 base[idx[7]] = x[7];
119#endif
120 }
121
122 void set(ARCANE_RESTRICT Real* base, const Int32IndexType* simd_idx) const
123 {
124 this->set(base, (const Int32*)simd_idx);
125 }
126
127 void set(ARCANE_RESTRICT Real* base, const Int32IndexType& simd_idx) const
128 {
129#ifdef ARCANE_USE_AVX512_SCATTERGATHER
130 _mm512_i32scatter_pd(base, simd_idx.v0, v0, 8);
131#else
132 this->set(base, &simd_idx);
133#endif
134 }
135
136 //! Stores the instance values at the address \a base which must be aligned.
137 void set(ARCANE_RESTRICT Real* base) const
138 {
139 _mm512_store_pd(base, v0);
140 }
141
142 static AVX512SimdReal fromScalar(Real a0, Real a1, Real a2, Real a3, Real a4, Real a5, Real a6, Real a7)
143 {
144 return AVX512SimdReal(a7, a6, a5, a4, a3, a2, a1, a0);
145 }
146
147 // Unary operation operator-
148 inline AVX512SimdReal operator-() const
149 {
150 return AVX512SimdReal(_mm512_sub_pd(_mm512_setzero_pd(), v0));
151 }
152
153 private:
154
155 void operator=(Real _v);
156};
157
158/*---------------------------------------------------------------------------*/
159/*---------------------------------------------------------------------------*/
160
162{
163 public:
164
165 static const char* name() { return "AVX512"; }
166 enum
167 {
168 Int32IndexSize = 8
169 };
170 typedef AVX512SimdReal SimdReal;
171 typedef AVX512SimdReal::Int32IndexType SimdInt32IndexType;
172};
173
174/*---------------------------------------------------------------------------*/
175/*---------------------------------------------------------------------------*/
176
177ARCANE_UTILS_EXPORT std::ostream& operator<<(std::ostream& o, const AVX512SimdReal& s);
178
179/*---------------------------------------------------------------------------*/
180/*---------------------------------------------------------------------------*/
181
182} // namespace Arcane
183
184/*---------------------------------------------------------------------------*/
185/*---------------------------------------------------------------------------*/
186
187#endif
#define ARCANE_ALIGNAS_PACKED(value)
Macro to guarantee the packing and alignment of a class to value bytes.
Vectorization of reals using AVX512 vectorization.
Definition SimdAVX512.h:43
void set(ARCANE_RESTRICT Real *base) const
Stores the instance values at the address base which must be aligned.
Definition SimdAVX512.h:137
AVX512SimdReal(const Real *base)
Loads continuous values located at the address base which must be aligned.
Definition SimdAVX512.h:96
Vectorization of Int32 integers using AVX.
Definition SimdAVX.h:47
-- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature --
Int32 Integer
Type representing an integer.
double Real
Type representing a real number.
std::ostream & operator<<(std::ostream &ostr, eItemKind item_kind)
Output operator for a stream.
std::int32_t Int32
Signed integer type of 32 bits.