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

Cerrado Apto para principiantes
#2,115 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
2/5
Tiempo estimado
1-3 horas
Aptitud para principiantes
69/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Activo
Stack tecnológico
cpp

Línea de trabajo

Empieza en networks/rhs.H, en locate_intermediate_rate_index, donde el issue señala un amrex::Array de tamaño cero y el acceso que falla. Comprueba cómo gestiona la función las redes sin reacciones intermedias y luego compila la red de prueba triple_alpha_plus_cago usando el comando make HIP del issue con libstdc++ 13 o posterior. El trabajo está terminado cuando la compilación HIP se complete correctamente; el issue sugiere dar al array al menos un elemento.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

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.

Lenguaje dominante
C++
Estrellas
44
Forks
47
Merge medio
5 d 5 h
PR fusionados (30 d)
6

Preparar el entorno

Este proyecto no incluye contenedor de desarrollo, Dockerfile ni guía de contribución, así que la configuración corre por tu cuenta: empieza por su README y consulta nuestra guía para la primera contribución para los pasos generales.

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de AMReX-Astro/Microphysics

Todos los issues de AMReX-Astro/Microphysics

Issues similares

Más issues de C++

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.