HIP build fails for networks with no intermediate reactions with libstdc++ >= 13 (std::array<int, 0> in locate_intermediate_rate_index)
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 69/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Active
- Tech stack
- cpp
- Domain
- backend, build-system
Research direction
Start in networks/rhs.H at locate_intermediate_rate_index, where the issue identifies a zero-sized amrex::Array and the failing access. Check how the function handles networks with no intermediate reactions, then build the triple_alpha_plus_cago test network using the issue's HIP make command with libstdc++ 13 or newer. Done when that HIP build compiles successfully; the issue suggests giving the array at least one element.
Written by the indexing model from the issue text.
Description
HIP builds of networks with no intermediate reactions (e.g. triple_alpha_plus_cago) fail to compile when the host C++ standard library is libstdc++ 13 or newer. libstdc++ 13 is the default on Ubuntu 24.04.
Error
On current development (60562512):
cd unit_test/test_react
make USE_HIP=TRUE AMD_ARCH=gfx90a NETWORK_DIR=triple_alpha_plus_cago
/usr/lib/gcc/x86_64-linux-gnu/14/../../../../include/c++/14/array:209:9: error: reference to __host__ function 'operator[]' in __host__ __device__ function
209 | return _M_elems[__n];
| ^
/usr/lib/gcc/x86_64-linux-gnu/14/../../../../include/c++/14/array:74:13: note: 'operator[]' declared here
74 | _Tp& operator[](size_t) const noexcept { __builtin_trap(); }
| ^
../../networks/rhs.H:142:28: note: called by 'locate_intermediate_rate_index'
142 | if (indices[n-1] == data.additional_reaction_1) {
Environment: Ubuntu 24.04, ROCm 10.1 (hipcc: HIP 7.16, AMD clang 24.0.0git), libstdc++ 13.3 and 14.
Cause
locate_intermediate_rate_index in networks/rhs.H declares
amrex::Array<int, num_intermediate> indices = {};
which is a std::array<int, 0> when the network has no intermediate reactions. Starting with GCC 13, libstdc++ implements the zero-size std::array storage as an empty struct whose operator[] is a plain, non-constexpr host function that just traps. hipcc rejects any reference to it from a __host__ __device__ function, even inside a loop that never executes (n <= num_intermediate with num_intermediate == 0). libstdc++ 11 used a constexpr static helper there, so this compiled before.
CI doesn't catch it because .github/workflows/hip.yml only builds iso7 and URCA-simple, which both have intermediate reactions.
Minimal reproducer (no Microphysics)
// repro.cpp
#include <hip/hip_runtime.h>
#include <array>
__host__ __device__ constexpr int find_index (int x)
{
constexpr int n_items = 0;
std::array<int, n_items> a = {};
for (int n = 1; n <= n_items; ++n) {
if (a[n-1] == x) {
return n;
}
}
return -1;
}
__global__ void kernel (int* out) { *out = find_index(3); }
hipcc --offload-arch=gfx90a -std=c++20 --gcc-install-dir=/usr/lib/gcc/x86_64-linux-gnu/11 -c repro.cpp # compiles
hipcc --offload-arch=gfx90a -std=c++20 --gcc-install-dir=/usr/lib/gcc/x86_64-linux-gnu/13 -c repro.cpp # error above
hipcc --offload-arch=gfx90a -std=c++20 --gcc-install-dir=/usr/lib/gcc/x86_64-linux-gnu/14 -c repro.cpp # error above
Possible fix
Give the array at least one element, e.g. int indices[num_intermediate > 0 ? num_intermediate : 1] = {};. The loops only touch the first num_intermediate elements, so the results don't change.
This was found while porting triple_alpha_plus_cago to Loom, but it is a stock HIP build failure with no Loom code involved. CUDA builds against libstdc++ 13+ probably fail the same way, but that is untested.
- Dominant language
- C++
- Stars
- 44
- Forks
- 46
- Avg merge
- 3d 7h
- Merged PRs (30d)
- 10
Getting set up
This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from AMReX-Astro/Microphysics
-
Difficulty 5/5 Over a week Newbie friendliness 25/100
AMReX-Astro/Microphysics#2104 · 3 comments ·
Maintainers usually reply within 1 day
-
ai-code-audit screening
Difficulty 4/5 3-5 days Newbie friendliness 55/100
AMReX-Astro/Microphysics#2097 · 1 comment ·
Maintainers usually reply within 1 day
-
ai-code-audit screening
Difficulty 4/5 3-5 days Newbie friendliness 72/100
AMReX-Astro/Microphysics#2096 ·
Maintainers usually reply within 1 day
-
ai-code-audit screening
Difficulty 4/5 3-5 days Newbie friendliness 66/100
AMReX-Astro/Microphysics#2095 · 1 comment ·
Maintainers usually reply within 1 day
-
ai-code-audit nse
Difficulty 3/5 1-2 days Newbie friendliness 68/100
AMReX-Astro/Microphysics#2075 ·
Maintainers usually reply within 1 day
All issues in AMReX-Astro/Microphysics
Similar issues
-
v9.6.0: CMake incorrectly enforces presence of libevdevPossibly taken A pull request linked to this issue is open or already merged. Open
Difficulty 2/5 1-3 hours Newbie friendliness 67/100
Maintainers usually reply within 1 day
-
Difficulty 1/5 Under an hour Newbie friendliness 65/100
mltframework/shotcut#1943 ·
Maintainers usually reply within 1 day
-
Rowan (2017) electron heating gives NaN for beta > beta_max; clip() then sets electrons to kel_minOpen
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
parthenon-hpc-lab/kharma#213 · 1 comment ·
Maintainers usually reply within 3 days
-
enhancement
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
metasequoiaime/msime#9113 ·
Maintainers usually reply within 1 day
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
tone-3000/tone3000-plugin#257 · 1 comment ·
Maintainers usually reply within 1 day