Skip to content

Use 2D j-slab scratch arrays in horizontal_diffusion_2 routines - #2473

Open
g8j39 wants to merge 2 commits into
wrf-model:developfrom
g8j39:perf/hdiff-2d-jslab
Open

g8j39 wants to merge 2 commits into
wrf-model:developfrom
g8j39:perf/hdiff-2d-jslab

Conversation

@g8j39

@g8j39 g8j39 commented Nov 17, 2026

Copy link
Copy Markdown

Use 2D j-slab scratch arrays in horizontal_diffusion_2 routines.

TYPE: enhancement

KEYWORDS: dyn_em, horizontal diffusion, diff_opt=2, cache locality, stack memory

SOURCE: Yoel Sevi (Google)

DESCRIPTION OF CHANGES:
Problem:
When full-metric 3D horizontal diffusion is enabled (diff_opt == 2),
horizontal_diffusion_u_2, horizontal_diffusion_v_2, horizontal_diffusion_w_2,
and horizontal_diffusion_s in dyn_em/module_diffusion_em.F allocate 3D
tile-sized automatic arrays (titau1avg, titau2avg, zx_at_u/v/w, zy_at_u/v/w,
H1avg, H2avg, xkxavg, zx_at_m, zy_at_m, tmptendf, plus unused xkxavg and rravg
in the momentum routines) and sweep separate 3D loops over j. None of these
arrays carry dependencies across j, so they spill out of L1/L2 cache before reuse.

Solution:

  • Replace those per-row scratch arrays with 2D (i, k) j-slabs and fuse the
    per-row j sweeps with identical floating-point operand order.
  • Keep titau1, titau2, H1, and H2 3D where j stencil differences exist.
  • Remove the unused xkxavg and rravg declarations in the three momentum
    routines (net -57 code lines).

License: Notwithstanding anything else to the contrary set out in https://github.com/wrf-model/WRF, the material here is being released under the Apache 2.0 licence at https://www.apache.org/licenses/LICENSE-2.0 (see doc/licenses/google_license.txt).

LIST OF MODIFIED FILES:
A doc/licenses/google_license.txt
M dyn_em/module_diffusion_em.F

TESTS CONDUCTED:

  1. On gfortran 15.2.0 (x86-64 Linux), passed -fcheck=all and FPE-trap (zero,
    overflow) tests with quiet-NaN initialized locals across all four routines
    (r4 and -r8, OMP_NUM_THREADS=1,4) with max_abs_diff = 0.0. With
    signalling-NaN initialization the harness traps identically for unmodified
    and patched code, so bit-identity was checked in the quiet-NaN build.
    Earlier 16-rank x86-64 isolated runs measured ~31% less standalone
    horizontal_diffusion_2 kernel time; the ~1.4% solo solver time saved on a
    smaller 3D TKE LES proxy domain is within run-to-run spread.
    Built and verified as part of the full optimization series on x86-64 Linux
    (gfortran 15.2.0, MPICH, 4-core VMs, 5 interleaved repeats across 5 em_real
    workflows) across Make (serial, dmpar r4 and -r8, dm+sm), CMake (dmpar),
    and -DWRF_CHEM=1 with 0 new compiler warnings and bit-for-bit identical
    wrf.exe outputs (diffwrf = 0 with gfortran on x86-64 without fused
    multiply-add).
  2. Pending upstream Jenkins CI (including Intel and non-x86 compilers).

RELEASE NOTE: Replace 3D tile scratch arrays with 2D (i, k) j-slabs in horizontal_diffusion_u_2, v_2, w_2, and s (dyn_em/module_diffusion_em.F).

Part of the modular CPU performance series; combined multi-workflow benchmarks, hardware/compiler setup, and per-PR summary table are in the Series Overview comment on PR 01 (#2470).

Prepared with AI assistance (Google Gemini).

TYPE: text only

KEYWORDS: license, Apache-2.0, contributor license, doc/licenses

SOURCE: Yoel Sevi (Google)

DESCRIPTION OF CHANGES:
Problem:
Following the contributor-license mechanism established in PR wrf-model#2242
(doc/licenses/fraunhofer_license.txt), Google-authored code blocks in
subsequent performance pull requests need a standalone permissive license file
under doc/licenses/ while leaving WRF's root LICENSE.txt unmodified.

Solution:
Add doc/licenses/google_license.txt containing the Apache License, Version 2.0
(Copyright 2026 Google LLC), referenced by
`! THE FOLLOWING LINES OF CODE ARE LICENSED UNDER doc/licenses/google_license.txt`
and `! END LICENSE` comment markers around Google-authored code blocks. If
maintainers prefer lower inline marker density on PRs with interleaved edits,
I am happy to explore a lighter per-routine notice option.

License: Notwithstanding anything else to the contrary set out in https://github.com/wrf-model/WRF, the material here is being released under the Apache 2.0 licence at https://www.apache.org/licenses/LICENSE-2.0 (see doc/licenses/google_license.txt).

ISSUE:
None

LIST OF MODIFIED FILES:
A       doc/licenses/google_license.txt

TESTS CONDUCTED:
1. Documentation-only addition under doc/licenses/; zero source, build, or
   runtime changes.
2. Pending upstream Jenkins CI.

RELEASE NOTE: Add doc/licenses/google_license.txt (Apache-2.0) for Google-contributed performance patches.
TYPE: enhancement

KEYWORDS: dyn_em, horizontal diffusion, diff_opt=2, cache locality, stack memory

SOURCE: Yoel Sevi (Google)

DESCRIPTION OF CHANGES:
Problem:
When full-metric 3D horizontal diffusion is enabled (diff_opt == 2),
horizontal_diffusion_u_2, horizontal_diffusion_v_2, horizontal_diffusion_w_2,
and horizontal_diffusion_s in dyn_em/module_diffusion_em.F allocate 3D
tile-sized automatic arrays (titau1avg, titau2avg, zx_at_u/v/w, zy_at_u/v/w,
H1avg, H2avg, xkxavg, zx_at_m, zy_at_m, tmptendf, plus unused xkxavg and rravg
in the momentum routines) and sweep separate 3D loops over j. None of these
arrays carry dependencies across j, so they spill out of L1/L2 cache before reuse.

Solution:
- Replace those per-row scratch arrays with 2D (i, k) j-slabs and fuse the
  per-row j sweeps with identical floating-point operand order.
- Keep titau1, titau2, H1, and H2 3D where j stencil differences exist.
- Remove the unused xkxavg and rravg declarations in the three momentum
  routines (net -57 code lines).

License: Notwithstanding anything else to the contrary set out in https://github.com/wrf-model/WRF, the material here is being released under the Apache 2.0 licence at https://www.apache.org/licenses/LICENSE-2.0 (see doc/licenses/google_license.txt).

ISSUE:
None

LIST OF MODIFIED FILES:
M       dyn_em/module_diffusion_em.F

TESTS CONDUCTED:
1. On gfortran 15.2.0 (x86-64 Linux), passed -fcheck=all and FPE-trap (zero,
   overflow) tests with quiet-NaN initialized locals across all four routines
   (r4 and -r8, OMP_NUM_THREADS=1,4) with max_abs_diff = 0.0. With
   signalling-NaN initialization the harness traps identically for unmodified
   and patched code, so bit-identity was checked in the quiet-NaN build.
   Earlier 16-rank x86-64 isolated runs measured ~31% less standalone
   horizontal_diffusion_2 kernel time; the ~1.4% solo solver time saved on a
   smaller 3D TKE LES proxy domain is within run-to-run spread.
   Built and verified as part of the full optimization series on x86-64 Linux
   (gfortran 15.2.0, MPICH, 4-core VMs, 5 interleaved repeats across 5 em_real
   workflows) across Make (serial, dmpar r4 and -r8, dm+sm), CMake (dmpar),
   and -DWRF_CHEM=1 with 0 new compiler warnings and bit-for-bit identical
   wrf.exe outputs (diffwrf = 0 with gfortran on x86-64 without fused
   multiply-add).
2. Pending upstream Jenkins CI (including Intel and non-x86 compilers).

RELEASE NOTE: Replace 3D tile scratch arrays with 2D (i, k) j-slabs in horizontal_diffusion_u_2, v_2, w_2, and s (dyn_em/module_diffusion_em.F).
@weiwangncar

Copy link
Copy Markdown
Collaborator

The regression test results:

Test Type              | Expected  | Received |  Failed
= = = = = = = = = = = = = = = = = = = = = = = =  = = = =
Number of Tests        : 23           24
Number of Builds       : 60           57
Number of Simulations  : 158           150        0
Number of Comparisons  : 95           86        0

Failed Simulations are: 
None
Which comparisons are not bit-for-bit: 
None

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