forked from AliceO2Group/AliceO2
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVcShim.h
More file actions
192 lines (151 loc) · 3.92 KB
/
VcShim.h
File metadata and controls
192 lines (151 loc) · 3.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
// Copyright 2020-2025 CERN and copyright holders of ALICE O2.
// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
// All rights not expressly granted are reserved.
//
// This software is distributed under the terms of the GNU General Public
// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
//
// In applying this license CERN does not waive the privileges and immunities
// granted to it by virtue of its status as an Intergovernmental Organization
// or submit itself to any jurisdiction.
/// \file VcShim.h
/// \brief Provides a basic fallback implementation for Vc
///
/// \author Felix Weiglhofer
#ifndef GPU_UTILS_VCSHIM_H
#define GPU_UTILS_VCSHIM_H
#ifndef GPUCA_NO_VC
#include <Vc/Vc>
#else
#include <algorithm>
#include <array>
#include <bitset>
#include <cstddef>
namespace Vc
{
constexpr struct VectorSpecialInitializerZero {
} Zero;
constexpr struct AlignedTag {
} Aligned;
template <typename T>
typename T::vector_type& internal_data(T& v)
{
return v.mData;
}
template <typename T>
const typename T::vector_type& internal_data(const T& v)
{
return v.mData;
}
namespace Common
{
template <typename V, typename M>
class WriteMaskVector
{
private:
const M& mMask;
V& mVec;
public:
using value_type = typename V::value_type;
WriteMaskVector(V& v, const M& m) : mMask(m), mVec(v) {}
WriteMaskVector& operator++(int)
{
for (size_t i = 0; i < mVec.size(); i++)
mVec[i] += value_type(mMask[i]);
return *this;
}
WriteMaskVector& operator=(const value_type& v)
{
for (size_t i = 0; i < mVec.size(); i++) {
if (mMask[i])
mVec[i] = v;
}
return *this;
}
};
inline void prefetchMid(const void*) {}
inline void prefetchFar(const void*) {}
inline void prefetchForOneRead(const void*) {}
} // namespace Common
template <typename T, size_t N>
class fixed_size_simd_mask
{
private:
std::bitset<N> mData;
public:
bool isNotEmpty() const { return mData.any(); }
std::bitset<N>::reference operator[](size_t i) { return mData[i]; }
bool operator[](size_t i) const { return mData[i]; }
fixed_size_simd_mask operator!() const
{
auto o = *this;
o.mData.flip();
return o;
}
};
template <typename T, size_t N>
class fixed_size_simd
{
private:
std::array<T, N> mData;
public:
using vector_type = std::array<T, N>;
using value_type = T;
using mask_type = fixed_size_simd_mask<T, N>;
static constexpr size_t size() { return N; }
fixed_size_simd() = default;
explicit fixed_size_simd(VectorSpecialInitializerZero) { mData = {}; }
template <typename U>
fixed_size_simd(const fixed_size_simd<U, N>& w)
{
std::copy_n(internal_data(w).begin(), N, mData.begin());
}
fixed_size_simd(const T* d, AlignedTag) { std::copy_n(d, N, mData.begin()); }
T& operator[](size_t i) { return mData[i]; }
const T& operator[](size_t i) const { return mData[i]; }
Common::WriteMaskVector<fixed_size_simd, mask_type> operator()(const mask_type& m) { return {*this, m}; }
fixed_size_simd& operator=(const T& v)
{
for (auto& x : mData)
x = v;
return *this;
}
fixed_size_simd& operator+=(const T& v)
{
for (auto& x : mData)
x += v;
return *this;
}
fixed_size_simd& operator/=(const T& v)
{
for (auto& x : mData)
x /= v;
return *this;
}
fixed_size_simd operator/(const T& v) const
{
auto x = *this;
return x /= v;
}
mask_type operator==(const T& v) const
{
mask_type m;
for (size_t i = 0; i < N; i++)
m[i] = mData[i] == v;
return m;
}
mask_type operator!=(const T& v) const { return !(*this == v); }
friend vector_type& internal_data<>(fixed_size_simd& x);
friend const vector_type& internal_data<>(const fixed_size_simd& x);
};
template <typename V>
V max(const V& a, const V& b)
{
V o;
for (size_t i = 0; i < a.size(); i++)
o[i] = std::max(a[i], b[i]);
return o;
}
} // namespace Vc
#endif // ifndef GPUCA_NO_VC
#endif