Skip to content

Commit 9a93b68

Browse files
committed
GPU: route noexcept through GPUnoexcept() for Metal
MSL rejects the noexcept specifier outright, with a diagnostic of its own: "'noexcept' is not supported in Metal". It applies to free functions, to function templates and to out-of-line member definitions alike; only a noexcept inside a class body slips through, which does not help a header that defines its members out of line.
1 parent 52af41a commit 9a93b68

3 files changed

Lines changed: 26 additions & 19 deletions

File tree

‎Common/MathUtils/include/MathUtils/detail/Bracket.h‎

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
#ifndef ALICEO2_BRACKET_H
1717
#define ALICEO2_BRACKET_H
1818

19+
#include "GPUCommonDef.h"
20+
1921
#include <GPUCommonRtypes.h>
2022
#ifndef GPUCA_GPUCODE_DEVICE
2123
#include <string>
@@ -53,9 +55,9 @@ class Bracket
5355
bool operator==(const Bracket<T>& other) const;
5456
bool operator!=(const Bracket<T>& other) const;
5557

56-
void setMax(T v) noexcept;
57-
void setMin(T v) noexcept;
58-
void set(T minv, T maxv) noexcept;
58+
void setMax(T v) GPUnoexcept();
59+
void setMin(T v) GPUnoexcept();
60+
void set(T minv, T maxv) GPUnoexcept();
5961

6062
T& getMax();
6163
T& getMin();
@@ -129,19 +131,19 @@ inline bool Bracket<T>::operator!=(const Bracket<T>& rhs) const
129131
}
130132

131133
template <typename T>
132-
inline void Bracket<T>::setMax(T v) noexcept
134+
inline void Bracket<T>::setMax(T v) GPUnoexcept()
133135
{
134136
mMax = v;
135137
}
136138

137139
template <typename T>
138-
inline void Bracket<T>::setMin(T v) noexcept
140+
inline void Bracket<T>::setMin(T v) GPUnoexcept()
139141
{
140142
mMin = v;
141143
}
142144

143145
template <typename T>
144-
inline void Bracket<T>::set(T minv, T maxv) noexcept
146+
inline void Bracket<T>::set(T minv, T maxv) GPUnoexcept()
145147
{
146148
this->setMin(minv);
147149
this->setMax(maxv);

‎GPU/Common/GPUCommonAlgorithm.h‎

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -51,40 +51,40 @@ class GPUCommonAlgorithm
5151
private:
5252
// Quicksort implementation
5353
template <typename I>
54-
GPUd() static void QuickSort(I f, I l) noexcept;
54+
GPUd() static void QuickSort(I f, I l) GPUnoexcept();
5555

5656
// Quicksort implementation
5757
template <typename I, typename Cmp>
58-
GPUd() static void QuickSort(I f, I l, Cmp cmp) noexcept;
58+
GPUd() static void QuickSort(I f, I l, Cmp cmp) GPUnoexcept();
5959

6060
// Insertionsort implementation
6161
template <typename I, typename Cmp>
62-
GPUd() static void InsertionSort(I f, I l, Cmp cmp) noexcept;
62+
GPUd() static void InsertionSort(I f, I l, Cmp cmp) GPUnoexcept();
6363

6464
// Helper for Quicksort implementation
6565
template <typename I, typename Cmp>
66-
GPUd() static I MedianOf3Select(I f, I l, Cmp cmp) noexcept;
66+
GPUd() static I MedianOf3Select(I f, I l, Cmp cmp) GPUnoexcept();
6767

6868
// Helper for Quicksort implementation
6969
template <typename I, typename T, typename Cmp>
70-
GPUd() static I UnguardedPartition(I f, I l, T piv, Cmp cmp) noexcept;
70+
GPUd() static I UnguardedPartition(I f, I l, T piv, Cmp cmp) GPUnoexcept();
7171

7272
// Helper
7373
template <typename I>
74-
GPUd() static void IterSwap(I a, I b) noexcept;
74+
GPUd() static void IterSwap(I a, I b) GPUnoexcept();
7575
};
7676

7777
#ifndef GPUCA_ALGORITHM_STD
7878
template <typename I>
79-
GPUdi() void GPUCommonAlgorithm::IterSwap(I a, I b) noexcept
79+
GPUdi() void GPUCommonAlgorithm::IterSwap(I a, I b) GPUnoexcept()
8080
{
8181
auto tmp = *a;
8282
*a = *b;
8383
*b = tmp;
8484
}
8585

8686
template <typename I, typename Cmp>
87-
GPUdi() void GPUCommonAlgorithm::InsertionSort(I f, I l, Cmp cmp) noexcept
87+
GPUdi() void GPUCommonAlgorithm::InsertionSort(I f, I l, Cmp cmp) GPUnoexcept()
8888
{
8989
auto it0{f};
9090
while (it0 != l) {
@@ -102,7 +102,7 @@ GPUdi() void GPUCommonAlgorithm::InsertionSort(I f, I l, Cmp cmp) noexcept
102102
}
103103

104104
template <typename I, typename Cmp>
105-
GPUdi() I GPUCommonAlgorithm::MedianOf3Select(I f, I l, Cmp cmp) noexcept
105+
GPUdi() I GPUCommonAlgorithm::MedianOf3Select(I f, I l, Cmp cmp) GPUnoexcept()
106106
{
107107
auto m = f + (l - f) / 2;
108108

@@ -126,7 +126,7 @@ GPUdi() I GPUCommonAlgorithm::MedianOf3Select(I f, I l, Cmp cmp) noexcept
126126
}
127127

128128
template <typename I, typename T, typename Cmp>
129-
GPUdi() I GPUCommonAlgorithm::UnguardedPartition(I f, I l, T piv, Cmp cmp) noexcept
129+
GPUdi() I GPUCommonAlgorithm::UnguardedPartition(I f, I l, T piv, Cmp cmp) GPUnoexcept()
130130
{
131131
do {
132132
while (cmp(*f, piv)) {
@@ -146,7 +146,7 @@ GPUdi() I GPUCommonAlgorithm::UnguardedPartition(I f, I l, T piv, Cmp cmp) noexc
146146
}
147147

148148
template <typename I, typename Cmp>
149-
GPUdi() void GPUCommonAlgorithm::QuickSort(I f, I l, Cmp cmp) noexcept
149+
GPUdi() void GPUCommonAlgorithm::QuickSort(I f, I l, Cmp cmp) GPUnoexcept()
150150
{
151151
if (f == l) {
152152
return;
@@ -204,7 +204,7 @@ GPUdi() void GPUCommonAlgorithm::QuickSort(I f, I l, Cmp cmp) noexcept
204204
}
205205

206206
template <typename I>
207-
GPUdi() void GPUCommonAlgorithm::QuickSort(I f, I l) noexcept
207+
GPUdi() void GPUCommonAlgorithm::QuickSort(I f, I l) GPUnoexcept()
208208
{
209209
QuickSort(f, l, [](auto&& x, auto&& y) { return x < y; });
210210
}

‎GPU/Common/GPUCommonDefAPI.h‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
#define GPUconstant() // constant memory variable declaraion
5050
#define GPUconstexpr() static constexpr // constexpr on GPU that needs to be instantiated for dynamic access (e.g. arrays), becomes __constant on GPU
5151
#define GPUglobalconstexpr() constexpr // constexpr variable at program scope, needs the constant address space in MSL
52+
#define GPUnoexcept() noexcept // noexcept where the backend supports it
5253
#define GPUprivate() // private memory variable declaration
5354
#define GPUgeneric() // reference / ptr to generic address space
5455
#define GPUbarrier() // synchronize all GPU threads in block
@@ -162,6 +163,7 @@
162163
#define GPUconstant() constant // TODO: possibly add const __restrict where possible later!
163164
#define GPUconstexpr() constant
164165
#define GPUglobalconstexpr() constant constexpr
166+
#define GPUnoexcept()
165167
#define GPUprivate() thread
166168
#define GPUgeneric()
167169
#define GPUglobalref() device
@@ -259,6 +261,9 @@
259261
#ifndef GPUglobalconstexpr
260262
#define GPUglobalconstexpr() constexpr
261263
#endif
264+
#ifndef GPUnoexcept
265+
#define GPUnoexcept() noexcept
266+
#endif
262267

263268
#define GPUrestrict() __restrict__
264269

@@ -281,5 +286,5 @@
281286
#define get_group_id(dim) iBlock
282287
#endif
283288

284-
// clang-format on
289+
// clang-format on
285290
#endif

0 commit comments

Comments
 (0)