Skip to content

Copy the ib flag to the device - #1937

Open
sbryngelson wants to merge 2 commits into
MFlowCode:masterfrom
sbryngelson:fix-ib-device-flag
Open

sbryngelson wants to merge 2 commits into
MFlowCode:masterfrom
sbryngelson:fix-ib-device-flag

Conversation

@sbryngelson

@sbryngelson sbryngelson commented Oct 1, 2026 •

Copy link
Copy Markdown
Member

Summary

ib gets a device copy (GPU_DECLARE(create=...) via SIM_GPU_DECL_VARS), but nothing ever copies its value to the GPU, so inside device kernels it stays .false.. #1792 added two device-side reads of it:

  • s_compute_dt (m_time_steppers.fpp): skip IB-interior cells in the adaptive-dt reduction
  • s_write_run_time_information (m_data_output.fpp): skip IB-interior cells in the CFL stability statistics

On GPU builds both checks are silently skipped. GPUs keep including IB-interior cells when choosing dt, while CPU builds exclude them. Any case with ib and cfl_adap_dt = T then runs with a different dt on GPU than on CPU. This adds ib to the existing GPU_UPDATE(device=...) in s_initialize_global_parameters_module.

How it showed up

In #1821, the 2D -> Example -> ibm_reacting_surface test (F52F0D4C) gives the same wrong numbers on every GPU build (Frontier CCE-acc, CCE-omp, AMD-omp, and Phoenix NVHPC-acc: 0.65037 vs. golden 0.6487849), while every CPU build (GNU, CCE, AMD) matches. Before the merge of #1792 into that branch, CPU and GPU agreed. After it, GPU stayed on the old value and only CPU moved. No master test currently triggers the bug.

The other device-declared parameters that are never updated (down_sample, igr_pres_lim, recon_type, weno_order) are case-optimization parameters that are read on the host or baked in at compile time, so this PR leaves them alone.

This PR was prepared with Claude Code (diagnosis from the #1821 CI logs and the fix).

Acknowledgement

  • I confirm this PR meets the above expectations and reflects my own understanding and real-world context.

MFlowCode#1792 added two device-side reads of ib -- skipping immersed-boundary
interior cells in the adaptive-dt reduction (s_compute_dt) and in the
CFL stability statistics (s_write_run_time_information). ib is
GPU_DECLARE'd through SIM_GPU_DECL_VARS but was never GPU_UPDATE'd,
so on the device it stayed .false. and GPU builds kept including IB
interior cells in dt while CPU builds excluded them. With
cfl_adap_dt=T this gives GPU runs a different dt from CPU runs.
Copilot AI balanced review requested due to automatic review settings October 1, 2026 14:57
@sbryngelson sbryngelson mentioned this pull request Oct 1, 2026
1 task
@sbryngelson

Copy link
Copy Markdown
Member Author

Verified on Frontier (CCE, OpenACC GPU build, --acc-gpu; job 5580862): with this change applied to #1821's head (e53c1572), 2D -> Example -> ibm_reacting_surface (F52F0D4C) passes against its CPU-generated golden. Without it, every GPU build in #1821's CI (CCE-acc, CCE-omp, AMD-omp, Phoenix NVHPC-acc) failed that test with identical values (0.65037 vs. 0.6487849).

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot review overview

🟢 Approval recommended

The targeted update correctly occurs before device kernels consume ib.

Review effort: Balanced
Findings: None

What changed in this PR

Synchronizes the immersed-boundary flag with GPU device storage, restoring CPU/GPU consistency for IB-aware CFL calculations.

Changes:

  • Adds ib to global GPU parameter initialization.
File Description
src/​simulation/​m_global_parameters.fpp Copies ib to its existing device allocation.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

2D -> 1 Fluid(s) -> IBM -> Adaptive dt: a rectangle moving through gas
at rest with cfl_adap_dt. The body's interior carries its velocity, so
if IB-interior cells enter the dt reduction (as they did on GPUs while
ib was never copied to the device) dt shrinks ~8% and the step-end
state moves by 2e-2. Edges sit on cell faces and the body moves 0.2 dx,
so no cell crosses the surface and the golden is portable.
@sbryngelson

Copy link
Copy Markdown
Member Author

Re: the Copilot finding asking for a GPU regression test: added in 5cea7a0.

2D -> 1 Fluid(s) -> IBM -> Adaptive dt (09FDDC81). A 0.2 × 0.2 rectangle moves at v = 0.1 through gas at rest (p = ρ = 1, c ≈ 1.18) with cfl_adap_dt = T. The IB interior carries the body velocity, so if IB-interior cells enter the dt reduction, dt shrinks by about 8%. The body's edges sit on cell faces and it moves 0.2 dx in total, so no cell crosses the surface and the golden stays portable. It takes about 5 steps.

Checked on Frontier (CCE), with the golden generated on CPU from this branch:

Build ib on device Result
CPU n/a (fixed code) pass
CPU, if (ib) in s_compute_dt forced .false. n/a fail, max abs err 2.01e-2
GPU (OpenACC), this PR updated pass
GPU (OpenACC), ib removed from the GPU_UPDATE stale .false. fail, max abs err 2.01e-2 (same values as the forced-off CPU run)

So removing the update again turns this test red.

@codecov

codecov Bot commented Oct 1, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 62.80%. Comparing base (ed7a238) to head (5cea7a0).
⚠️ Report is 3 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1937      +/-   ##
==========================================
- Coverage   62.82%   62.80%   -0.03%     
==========================================
  Files          86       86              
  Lines       22394    22387       -7     
  Branches     3305     3306       +1     
==========================================
- Hits        14070    14061       -9     
  Misses       6071     6071              
- Partials     2253     2255       +2     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

This branch has not been deployed

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

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants