From 3cd8e546ff8af65221b70ede84e568ca4713f6e6 Mon Sep 17 00:00:00 2001 From: Giulio Eulisse <10544+ktf@users.noreply.github.com> Date: Thu, 24 Sep 2026 12:59:05 +0200 Subject: [PATCH] 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. --- .../include/MathUtils/detail/Bracket.h | 14 ++++++----- GPU/Common/GPUCommonAlgorithm.h | 24 +++++++++---------- GPU/Common/GPUCommonDefAPI.h | 7 +++++- 3 files changed, 26 insertions(+), 19 deletions(-) diff --git a/Common/MathUtils/include/MathUtils/detail/Bracket.h b/Common/MathUtils/include/MathUtils/detail/Bracket.h index 2da6949c4a6f8..450174dc9737f 100644 --- a/Common/MathUtils/include/MathUtils/detail/Bracket.h +++ b/Common/MathUtils/include/MathUtils/detail/Bracket.h @@ -16,6 +16,8 @@ #ifndef ALICEO2_BRACKET_H #define ALICEO2_BRACKET_H +#include "GPUCommonDef.h" + #include #ifndef GPUCA_GPUCODE_DEVICE #include @@ -53,9 +55,9 @@ class Bracket bool operator==(const Bracket& other) const; bool operator!=(const Bracket& other) const; - void setMax(T v) noexcept; - void setMin(T v) noexcept; - void set(T minv, T maxv) noexcept; + void setMax(T v) GPUnoexcept(); + void setMin(T v) GPUnoexcept(); + void set(T minv, T maxv) GPUnoexcept(); T& getMax(); T& getMin(); @@ -129,19 +131,19 @@ inline bool Bracket::operator!=(const Bracket& rhs) const } template -inline void Bracket::setMax(T v) noexcept +inline void Bracket::setMax(T v) GPUnoexcept() { mMax = v; } template -inline void Bracket::setMin(T v) noexcept +inline void Bracket::setMin(T v) GPUnoexcept() { mMin = v; } template -inline void Bracket::set(T minv, T maxv) noexcept +inline void Bracket::set(T minv, T maxv) GPUnoexcept() { this->setMin(minv); this->setMax(maxv); diff --git a/GPU/Common/GPUCommonAlgorithm.h b/GPU/Common/GPUCommonAlgorithm.h index be88973561e0a..938c60b0b0cf2 100644 --- a/GPU/Common/GPUCommonAlgorithm.h +++ b/GPU/Common/GPUCommonAlgorithm.h @@ -51,32 +51,32 @@ class GPUCommonAlgorithm private: // Quicksort implementation template - GPUd() static void QuickSort(I f, I l) noexcept; + GPUd() static void QuickSort(I f, I l) GPUnoexcept(); // Quicksort implementation template - GPUd() static void QuickSort(I f, I l, Cmp cmp) noexcept; + GPUd() static void QuickSort(I f, I l, Cmp cmp) GPUnoexcept(); // Insertionsort implementation template - GPUd() static void InsertionSort(I f, I l, Cmp cmp) noexcept; + GPUd() static void InsertionSort(I f, I l, Cmp cmp) GPUnoexcept(); // Helper for Quicksort implementation template - GPUd() static I MedianOf3Select(I f, I l, Cmp cmp) noexcept; + GPUd() static I MedianOf3Select(I f, I l, Cmp cmp) GPUnoexcept(); // Helper for Quicksort implementation template - GPUd() static I UnguardedPartition(I f, I l, T piv, Cmp cmp) noexcept; + GPUd() static I UnguardedPartition(I f, I l, T piv, Cmp cmp) GPUnoexcept(); // Helper template - GPUd() static void IterSwap(I a, I b) noexcept; + GPUd() static void IterSwap(I a, I b) GPUnoexcept(); }; #ifndef GPUCA_ALGORITHM_STD template -GPUdi() void GPUCommonAlgorithm::IterSwap(I a, I b) noexcept +GPUdi() void GPUCommonAlgorithm::IterSwap(I a, I b) GPUnoexcept() { auto tmp = *a; *a = *b; @@ -84,7 +84,7 @@ GPUdi() void GPUCommonAlgorithm::IterSwap(I a, I b) noexcept } template -GPUdi() void GPUCommonAlgorithm::InsertionSort(I f, I l, Cmp cmp) noexcept +GPUdi() void GPUCommonAlgorithm::InsertionSort(I f, I l, Cmp cmp) GPUnoexcept() { auto it0{f}; while (it0 != l) { @@ -102,7 +102,7 @@ GPUdi() void GPUCommonAlgorithm::InsertionSort(I f, I l, Cmp cmp) noexcept } template -GPUdi() I GPUCommonAlgorithm::MedianOf3Select(I f, I l, Cmp cmp) noexcept +GPUdi() I GPUCommonAlgorithm::MedianOf3Select(I f, I l, Cmp cmp) GPUnoexcept() { auto m = f + (l - f) / 2; @@ -126,7 +126,7 @@ GPUdi() I GPUCommonAlgorithm::MedianOf3Select(I f, I l, Cmp cmp) noexcept } template -GPUdi() I GPUCommonAlgorithm::UnguardedPartition(I f, I l, T piv, Cmp cmp) noexcept +GPUdi() I GPUCommonAlgorithm::UnguardedPartition(I f, I l, T piv, Cmp cmp) GPUnoexcept() { do { while (cmp(*f, piv)) { @@ -146,7 +146,7 @@ GPUdi() I GPUCommonAlgorithm::UnguardedPartition(I f, I l, T piv, Cmp cmp) noexc } template -GPUdi() void GPUCommonAlgorithm::QuickSort(I f, I l, Cmp cmp) noexcept +GPUdi() void GPUCommonAlgorithm::QuickSort(I f, I l, Cmp cmp) GPUnoexcept() { if (f == l) { return; @@ -204,7 +204,7 @@ GPUdi() void GPUCommonAlgorithm::QuickSort(I f, I l, Cmp cmp) noexcept } template -GPUdi() void GPUCommonAlgorithm::QuickSort(I f, I l) noexcept +GPUdi() void GPUCommonAlgorithm::QuickSort(I f, I l) GPUnoexcept() { QuickSort(f, l, [](auto&& x, auto&& y) { return x < y; }); } diff --git a/GPU/Common/GPUCommonDefAPI.h b/GPU/Common/GPUCommonDefAPI.h index 4cc2c8e69074d..36e8cd403e083 100644 --- a/GPU/Common/GPUCommonDefAPI.h +++ b/GPU/Common/GPUCommonDefAPI.h @@ -49,6 +49,7 @@ #define GPUconstant() // constant memory variable declaraion #define GPUconstexpr() static constexpr // constexpr on GPU that needs to be instantiated for dynamic access (e.g. arrays), becomes __constant on GPU #define GPUglobalconstexpr() constexpr // constexpr variable at program scope, needs the constant address space in MSL + #define GPUnoexcept() noexcept // noexcept where the backend supports it #define GPUprivate() // private memory variable declaration #define GPUgeneric() // reference / ptr to generic address space #define GPUbarrier() // synchronize all GPU threads in block @@ -162,6 +163,7 @@ #define GPUconstant() constant // TODO: possibly add const __restrict where possible later! #define GPUconstexpr() constant #define GPUglobalconstexpr() constant constexpr + #define GPUnoexcept() #define GPUprivate() thread #define GPUgeneric() #define GPUglobalref() device @@ -259,6 +261,9 @@ #ifndef GPUglobalconstexpr #define GPUglobalconstexpr() constexpr #endif +#ifndef GPUnoexcept +#define GPUnoexcept() noexcept +#endif #define GPUrestrict() __restrict__ @@ -281,5 +286,5 @@ #define get_group_id(dim) iBlock #endif - // clang-format on +// clang-format on #endif