Skip to content

Call HYPRE_DeviceInitialize after HYPRE_Init if using GPUs#5336

Open
jrood-nrel wants to merge 1 commit intoAMReX-Codes:developmentfrom
jrood-nrel:jrood/hdi
Open

Call HYPRE_DeviceInitialize after HYPRE_Init if using GPUs#5336
jrood-nrel wants to merge 1 commit intoAMReX-Codes:developmentfrom
jrood-nrel:jrood/hdi

Conversation

@jrood-nrel
Copy link
Copy Markdown
Contributor

Summary

Without this, I was experiencing errors during init on a machine where MPI ranks can see multiple GPUs:

CUDA ERROR (code = 1, invalid argument) at /whatever/hypre/src/utilities/memory.c:136

Setting export CUDA_VISIBLE_DEVICES=0 was able to avoid the error, but the actual fix seems to be to include the call to HYPRE_DeviceInitialize() after HYPRE_Init() when using GPUs.

I can verify this solves the error I was seeing when using hypre with AMReX in AMR-Wind.

Additional background

Checklist

The proposed changes:

  • fix a bug or incorrect behavior in AMReX
  • add new capabilities to AMReX
  • changes answers in the test suite to more than roundoff level
  • are likely to significantly affect the results of downstream AMReX users
  • include documentation in the code and/or rst files, if appropriate

Comment thread Src/Base/AMReX.cpp
hypre_HandleDefaultExecPolicy(hypre_handle()) = HYPRE_EXEC_DEVICE;
hypre_HandleSpgemmUseCusparse(hypre_handle()) = 0;
#endif
HYPRE_DeviceInitialize();
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we move this line right after HYPRE_init, in case it needs to be called before functions like HYPRE_SetGPUMemoryPoolSize?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot (Opus) claimed it should be at this location. I'm going to convert this to a draft anyway, because it seems like there is more to this I think I need to understand.

@jrood-nrel jrood-nrel marked this pull request as draft April 15, 2026 19:20
@jrood-nrel jrood-nrel marked this pull request as ready for review April 16, 2026 15:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants