Repository navigation
Conversation
(cherry picked from commit 44976dc)
Pass explicit procedure pointers to the existing scalar constructors. Use pure module procedures for expected fields so Flang on macOS does not require executable-stack trampolines for a host-associated callback. Preserve the zero-boundary oracle and all numerical assertions.
(cherry picked from commit 3866131)
Preserve the operator-based solver as a numerical reference, retain normal CSV output, and add substantial benchmark and raw-field modes. On M4 Max with the coalescing LFortran build, the 2048x2048 Gaussian case takes 2.196 s wall / 2.186 s GPU and matches native Metal within 5.96e-8. (cherry picked from commit 39defc6)
(cherry picked from commit 48e70be)
(cherry picked from commit 481b33e)
(cherry picked from commit 96c841a)
(cherry picked from commit 846ffc5)
(cherry picked from commit 5a3bc75)
Match the scalar_2D_t constructor's callback interface using the existing pure module initializer. Preserve the reconstruction buffer, its lifetime, and every field value. (cherry picked from commit a0e4e8d)
(cherry picked from commit 72b4b28)
(cherry picked from commit db4b32a)
(cherry picked from commit adf0691)
This was referenced Oct 19, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
One comprehensive performance/discussion draft containing all current 2D advection-diffusion improvements, kept in focused commits so their CPU/GPU trade-offs can be discussed together. No platform-dependent layout extension is implemented, and no claim of universal performance optimality is made.
Depends on #70. Its two unchanged correctness commits are included while that PR remains unmerged. This PR does not modify #70.
Scope
--solver operators; order 4 defaults to workspace and order 2 uses operators.benchmarks/, outside FPM's automatic example discovery.No performance component is dropped. No compiler source, CI version removal, test skip or speculative layout-switching feature is added.
Measurements
Clean merged-main GPU result
Apple M4 Max, actual Gaussian input, 2048x2048 cells, 1000 steps, three interleaved pairs. Formal and native Metal use identical raw input and FP32 timestep; native geometry is direct 2D indexing with 128x1 threadgroups.
The compiler is an unpatched merged-main checkout at
lfortran/lfortran@2247d35082ea190408486b93c12ec2ead4771735, built with LLVM 11.1.0. Maximum full-field difference was 5.96e-8, relative L2 approximately 5.98e-9; fields evolved and fixed boundaries were preserved.Solve timings exclude compilation, initialization, warmup/JIT and field I/O. Native dispatch/synchronization counts in the detailed report are schedule-derived, not observed counters. GPU command-buffer time is not hardware occupancy, and bandwidth estimates are models rather than DRAM-counter measurements.
Controlled CPU comparisons
Each compiler used three interleaved comparisons with identical inputs and flags within its workload. The original/folded operator variants differ only in the three coefficient-helper implementations.
--fast, 51x51/1500 stepsThe coefficient-only changes are about 0.06% in opposite directions, within the observed sample spread. These measurements do not establish a CPU regression, speedup or equivalence across architectures/workloads. The workloads differ between compilers, so the table is not an absolute GFortran-versus-LFortran comparison.
The earlier GPU coefficient-only result, 9.603519 -> 4.057951 s (2.3666x) for 51x51/500 steps with byte-identical fields, remains explicitly historical: it used an older optimized compiler branch, not this clean-main measurement.
Verification and reproduction
The measurements above were captured at
70e73ee; subsequent changes harden host input validation and comparison tools rather than changing the numerical kernels. Kernel equivalence was checked, and four real small GPU executions were repeated at the currentef4fb6ehead, with CPU-oracle, finite-field, evolution and fixed-boundary checks. Gaussian maximum difference was2.33e-10; the nonzero-boundary case agreed exactly.Additional checks include allocation-free overflow/cap probes, non-finite timestep rejection, strict metadata/tolerance negative cases in normal Python and
python -O, and LFortran's 32/32 FPM tests in normal and fast modes. The independent code/measurement review has no remaining blocker or rework finding.For setup, exact compiler flags, medians/ranges, input provenance and paired commands, see:
The managed tooling selects the real Apple SDK compiler after Pixi activation; it does not patch LFortran or install a fake
clangwrapper. Default Pixi Clang 11 still has a current-Foundation SDK incompatibility; the separate compiler-driver work is tracked in lfortran/lfortran#12628.Known timing follow-up: raw dumps remain outside
final_io_seconds. That counter is not total final-output time, and the reported solve timings are not whole-process wall time. This limitation is documented; the timing code is unchanged.CI limitations
Current CI at
ef4fb6epasses 11/17 compiler jobs, including current LFortran and the other Flang configurations:numerical_arguments_t.LOCALclause.lfortran --version, before Formal compilation.These remain documented compiler/packaging limitations; versions and checks have not been removed to make CI green. Pre-existing GFortran 3D failures are also kept separate from this 2D work. The PR remains a discussion draft.
Performance portability discussion
Ap = -A(m:1:-1,n:1:-1)preserves coefficient values, shape and Fortran storage order. Compiler-dependent traversal and temporary generation can still affect performance.Which changes benefit other CPUs and workloads? Can the compiler own more temporary elimination, legal loop/thread mapping, fusion or layout transformations, avoiding separate source strategies? If annotations or a language extension become necessary, which measured trade-off and guarantees should motivate them?
Any automatic physical-layout transformation must preserve observable Fortran element order, storage association and ABI/interoperability requirements, including
SEQUENCE,BIND(C),EQUIVALENCE,TRANSFERand C pointers. Those are open discussion questions, not a proposed extension hidden in this implementation.