Hacktoberfest 2026: the issues maintainers tagged for October, open and beginner-friendly. Browse Hacktoberfest issues

HIP build fails for networks with no intermediate reactions with libstdc++ >= 13 (std::array<int, 0> in locate_intermediate_rate_index)

Closed Beginner friendly
#2,115 0 comments 0 reactions 0 assignees View on GitHub

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

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

bug GPU

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

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from AMReX-Astro/Microphysics

All issues in AMReX-Astro/Microphysics

Similar issues

More C++ issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.