Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[GCC14] Avoid std::clamp in device code #47266

Merged
merged 2 commits into from
Feb 5, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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