Skip to content

Commit

Permalink
Merge pull request #47266 from iarspider/no-std-clamp
Browse files Browse the repository at this point in the history
[GCC14] Avoid std::clamp in device code
  • Loading branch information
cmsbuild authored Feb 5, 2025
2 parents 6a35b52 + 9291eee commit 1cd573e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,11 @@ namespace pixelCPEforDevice {
int high_value = kNumErrorBins - 1;
int bin_value = float(kNumErrorBins) * (cp.xpos[ic] + xoff) / (2 * xoff);
// return estimated bin value truncated to [0, 15]
int jx = std::clamp(bin_value, low_value, high_value);
// Equivalent of jx = std::clamp(bin_value, low_value, high_value)
// which doesn't compile with gcc14 due to reference to __glibcxx_assert
// See https://github.com/llvm/llvm-project/issues/95183
int tmp_max = std::max<int>(bin_value, low_value);
int jx = std::min<int>(tmp_max, high_value);

auto toCM = [](uint8_t x) { return float(x) * 1.e-4f; };

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,11 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE::vertexFinder {
// fill hist (bin shall be wider than "eps")
for (auto i : cms::alpakatools::uniform_elements(acc, nt)) {
int iz = static_cast<int>(zt[i] * 10.f); // valid if eps <= 0.1
iz = std::clamp(iz, INT8_MIN, INT8_MAX);
// Equivalent of iz = std::clamp(iz, INT8_MIN, INT8_MAX)
// which doesn't compile with gcc14 due to reference to __glibcxx_assert
// See https://github.com/llvm/llvm-project/issues/95183
int tmp_max = std::max<int>(iz, INT8_MIN);
iz = std::min<int>(tmp_max, INT8_MAX);
ALPAKA_ASSERT_ACC(iz - INT8_MIN >= 0);
ALPAKA_ASSERT_ACC(iz - INT8_MIN < 256);
izt[i] = iz - INT8_MIN;
Expand Down

0 comments on commit 1cd573e

Please sign in to comment.