Repository navigation
Description
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 atFDS-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.
- When
HYPRE_DEVICE_RUNis true, FDS sets hypre's default memory location to DEVICE:HYPRE_SETMEMORYLOCATION(HYPRE_MEMORY_DEVICE)at ~4434 (UGLMAT/GLMAT) and ~1180 (ULMAT). - 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. HYPRE_IJMATRIXSETVALUESis then called (~4758 and ~4793) with ordinary host Fortran arrays (NCOLSARR,ROWARR,COLS0,VALS).HYPRE_IJMatrixSetValuespicks its code path from the matrix's memory location (src/IJ_mv/HYPRE_IJMatrix.c). For a device matrix it goes tohypre_IJMatrixSetAddValuesParCSRDevice(src/IJ_mv/IJMatrix_parcsr_device.c). That function treats the input arrays as device pointers: it does a device-to-device copy ofncolsfollowed by a thrust exclusive scan. The input arrays are not copied from the host first. The D→D copy of a host pointer fails atmemory.c:791. The thrust error is a follow-on failure.- 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_RSNotes on the fix:
- Assembly is unchanged. The matrix is built on the host and then moved to the device by the existing
HYPRE_IJMATRIXMIGRATEat ~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_V2andHYPRE_MEMORY_HOSTare already declared inSource/imkl.f90and 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 inCMakeLists.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, withUGLMAT 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
marcosvanella commentedon Nov 30, 2026
@quantumglen5 thank you for the report. This is a merge regression:
I'll bring in master into FireX and add the IJMATRIXINITIALIZE fix.
FDS Source: Init UGLMAT/GLMAT HYPRE matrix on host before GPU migrate…
marcosvanella commentedon Nov 30, 2026
@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.