Skip to content

UGLMAT/GLMAT HYPRE on GPU crashes at setup on systems without HMM/ATS (IJ matrix initialized in device memory but filled from host arrays) #16833

Todo

Description

@dukehuang-tw

Summary

With a GPU build of FDS (-DWITH_HYPRE_DEVICE, hypre built with CUDA), &PRES SOLVER='UGLMAT HYPRE' (and 'GLMAT HYPRE') aborts during pressure solver setup on systems where the GPU cannot directly access ordinary host memory (no HMM/ATS, e.g. a regular PC or WSL2). SOLVER='ULMAT HYPRE' works on the same system.

The cause is a single call in Source/pres.f90: the global (UGLMAT/GLMAT) IJ matrix is created with HYPRE_IJMATRIXINITIALIZE, which uses hypre's default memory location (DEVICE when HYPRE_DEVICE_RUN), but it is then filled with HYPRE_IJMATRIXSETVALUES from host Fortran arrays. Initializing the matrix on the host, exactly as the ULMAT matrix and the vectors in the same routine already do, fixes it.

Error

HYPRE : Setting execution policy to device (GPU)
CUDA ERROR (code = 1, invalid argument) at .../src/utilities/memory.c:791
terminate called after throwing an instance of 'thrust::...::system_error'
  what():  after determining tmp storage requirements for exclusive_scan: cudaErrorInvalidDevice: invalid device ordinal

Environment

  • FDS: FireX branch, FDS-6.11.1-562-g2bbc148 (2026-11-13). The issue also exists at FDS-6.11.1.
  • hypre v3.0.0, built with CUDA, CMAKE_CUDA_ARCHITECTURES=89, Umpire OFF, unified memory OFF, GPU-aware MPI OFF
  • CUDA 13.0, NVIDIA RTX 4060 Laptop GPU (sm_89), driver 617.42
  • Ubuntu 24.04 on WSL2 (kernel 6.18), GNU Fortran 13.3, Open MPI 4.1.6
  • Build: Build/ompi_gnu_linux/make_fds.sh --with-gpu=cuda

How to reproduce

Use Verification/GPU_Tests/test_gpu.fds (or any case) with &PRES SOLVER='UGLMAT HYPRE' /, on a GPU build, on a system without HMM/ATS:

OMP_NUM_THREADS=1 FDS_RANKS_PER_GPU=4 mpirun -np 4 fds_ompi_gnu_linux test_gpu.fds

Results on the same system:

Solver Device Result
UGLMAT HYPRE GPU crash (above)
UGLMAT HYPRE CPU (HYPRE_DEVICE_RUN=.FALSE.) OK
ULMAT HYPRE GPU OK
UGLMAT HYPRE + fix below GPU OK, HRR identical to the CPU run

Root cause

Line numbers refer to Source/pres.f90 at 2bbc148. hypre references are to v3.0.0.

  1. When HYPRE_DEVICE_RUN is true, FDS sets hypre's default memory location to DEVICE: HYPRE_SETMEMORYLOCATION(HYPRE_MEMORY_DEVICE) at ~4434 (UGLMAT/GLMAT) and ~1180 (ULMAT).
  2. The UGLMAT/GLMAT matrix is created with plain HYPRE_IJMATRIXINITIALIZE(ZSL%HYPRE_ZSL%A_H, ...) at ~4741. This takes the default memory location (src/IJ_mv/IJMatrix_parcsr.c, hypre_IJMatrixInitializeParCSR), so the matrix lives on the device.
  3. HYPRE_IJMATRIXSETVALUES is then called (~4758 and ~4793) with ordinary host Fortran arrays (NCOLSARR, ROWARR, COLS0, VALS).
  4. HYPRE_IJMatrixSetValues picks its code path from the matrix's memory location (src/IJ_mv/HYPRE_IJMatrix.c). For a device matrix it goes to hypre_IJMatrixSetAddValuesParCSRDevice (src/IJ_mv/IJMatrix_parcsr_device.c). That function treats the input arrays as device pointers: it does a device-to-device copy of ncols followed by a thrust exclusive scan. The input arrays are not copied from the host first. The D→D copy of a host pointer fails at memory.c:791. The thrust error is a follow-on failure.
  5. On systems with HMM or ATS (e.g. Grace Hopper, or Linux with HMM-enabled drivers), the GPU can access ordinary host allocations. That is probably why this has not shown up on HPC systems. Without HMM/ATS it crashes. Enabling unified memory in hypre does not help, because the FDS arrays are not managed allocations.

The rest of the code already handles this correctly:

  • ULMAT matrix: HYPRE_IJMATRIXINITIALIZE_V2(ZM%HYPRE_ZM%A_H, HYPRE_MEMORY_HOST, ...) (~2965)
  • UGLMAT/GLMAT vectors in the same routine: HYPRE_IJVECTORINITIALIZE_V2(..., HYPRE_MEMORY_HOST, ...) (~4803, ~4807)
  • After assembly, the matrix and vectors are migrated with HYPRE_IJMATRIXMIGRATE / HYPRE_IJVECTORMIGRATE(..., HYPRE_MEMORY_DEVICE, ...) (~4821–4823).

So the UGLMAT/GLMAT matrix is the only object that is initialized on the device. A scan of Source/ found no other plain HYPRE_IJMATRIXINITIALIZE / HYPRE_IJVECTORINITIALIZE call.

Proposed fix

--- a/Source/pres.f90
+++ b/Source/pres.f90
@@ -4737,7 +4737,7 @@ IPZ_LOOP : DO IPZ=0,N_ZONE_GLOBMAT
                                 ZSL%LOWER_ROW-1,ZSL%UPPER_ROW-1,ZSL%HYPRE_ZSL%A_H,HYPRE_IERR)
 
       CALL HYPRE_IJMATRIXSETOBJECTTYPE(ZSL%HYPRE_ZSL%A_H,HYPRE_PARCSR,HYPRE_IERR)
-      CALL HYPRE_IJMATRIXINITIALIZE(ZSL%HYPRE_ZSL%A_H,HYPRE_IERR)
+      CALL HYPRE_IJMATRIXINITIALIZE_V2(ZSL%HYPRE_ZSL%A_H,HYPRE_MEMORY_HOST,HYPRE_IERR)
 
       ! Assemble from per-row storage
       DO IROW=1,ZSL%NUNKH_LOCAL_RS

Notes on the fix:

  • Assembly is unchanged. The matrix is built on the host and then moved to the device by the existing HYPRE_IJMATRIXMIGRATE at ~4821. This is the same pattern as ULMAT.
  • The ParCSR handle stays valid. The object returned by HYPRE_IJMATRIXGETOBJECT (~4799) is still valid after migration, because migrate replaces the internal arrays in place. No matrix values are set after migration.
  • The CPU path is unaffected. With HYPRE_DEVICE_RUN=.FALSE., or with a non-device build, the default memory location is already HOST.
  • No new API is needed. HYPRE_IJMATRIXINITIALIZE_V2 and HYPRE_MEMORY_HOST are already declared in Source/imkl.f90 and used by the ULMAT path. They exist in hypre 2.33.0 and 3.0.0. I did not check 2.32.0, the minimum in CMakeLists.txt, but ULMAT already depends on them.
  • An alternative was not chosen. The matrix could stay on the device if the row arrays were copied to device buffers before SetValues. That would need extra device buffers and Fortran/CUDA interop for little benefit, because the matrix is assembled only once at setup. The proposed one-line change is smaller and matches ULMAT.

Testing

  • Test case: Verification/GPU_Tests/test_gpu.fds, scaled down to 8 meshes of 24³ and run on 4 MPI ranks, with UGLMAT HYPRE.
  • At FDS-6.11.1-309-g835588b + fix: the case runs to completion on the GPU. Its HRR output is identical to the CPU run (HYPRE_DEVICE_RUN=.FALSE.).
  • At FDS-6.11.1-562-g2bbc148 + fix: the case runs to completion on the GPU. HYPRE : Setting execution policy to device (GPU) is printed.

I can open a PR with this change if that is helpful.

Activity

  1. marcosvanella commented on Nov 30, 2026

    @marcosvanella
    Contributor

    @quantumglen5 thank you for the report. This is a merge regression:

    • Original GPU port: commit 8bc1723 (V. Magri, Jan 2025) set the UGLMAT matrix to _V2(..., HYPRE_MEMORY_HOST) together with the MIGRATE.
    • The merge: the 2025-06-04 master→FireX sync (88c4791, merged via FireX: Merge with firemodels/master #14726) brought in master’s restructured UGLMAT block with a plain INITIALIZE. That dropped the host init but kept the migrate.

    I'll bring in master into FireX and add the IJMATRIXINITIALIZE fix.

  2. marcosvanella commented on Nov 30, 2026

    @marcosvanella
    Contributor

    @quantumglen5 , I pushed the change to the FireX branch, also brought in latest master and fixed some preexistent vtk issues. Try it and close if working.
    BTW, I don't open .zip files from the internet as a general rule. Next time just post the case and a picture of what you see.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions