Zeros-init + well-conditioned Gram-Schmidt; add dace_canonicalize_{cpu,gpu} frameworks#47
Open
ThrudPrimrose wants to merge 2 commits into
Open
Zeros-init + well-conditioned Gram-Schmidt; add dace_canonicalize_{cpu,gpu} frameworks#47ThrudPrimrose wants to merge 2 commits into
ThrudPrimrose wants to merge 2 commits into
Conversation
Two fixes for run-to-run reproducibility and numerical stability. 1. np.empty / np.empty_like -> np.zeros / np.zeros_like for output and work buffers across the whole suite (256 sites in 132 files, all backends: numpy, dace, numba, cupy, dpnp, pythran, legate, jax). An uninitialized `empty` buffer that a kernel writes only partially leaves stale/garbage memory in the result, so those kernels are read-nondeterministic and their comparison against the reference flakes across runs. Zeroing makes every run reproducible; for buffers that are fully overwritten before use it is equivalent, so all sites are converted uniformly. Commented-out code is left untouched. 2. gramschmidt: make the input matrix deterministically full column rank and well-conditioned via a diagonal-dominance term, replacing the reject-sampling `while matrix_rank(A) < N` loop. A plain random matrix is only full-rank in expectation and can be poorly conditioned, which makes the Gram-Schmidt QR numerically unstable and sensitive to harmless FMA-contraction reassociation. The added diagonal gives cond(A) ~= 1.5 with no nondeterministic resampling.
Two new frameworks that run DaCe's canonicalize pipeline instead of auto_optimize, to contrast the WCR (write-conflict-resolution) reduction lowering. - dace_canonicalize_cpu / dace_canonicalize_gpu build the SDFG, then run canonicalize(target=cpu|gpu, peel_limit=4, break_anti_dependence=True, interchange_carry_with_map=True, scatter_to_guarded_maps=True) followed by finalize_for_target, leaving sdfg.openmp_array_reductions = True (WCR-config ON): a whole-buffer WCR accumulator of a parallel map lowers to an OpenMP reduction(op:A[0:n]) array-section clause instead of per-element atomics. - The existing dace_cpu / dace_gpu now set openmp_array_reductions = False explicitly before compile (WCR-config OFF, the default per-element atomic path), so the contrast between the two families is explicit. Registered exactly like dace_cpu / dace_gpu: two framework_info/*.json files plus a DaceCanonicalizeFramework class (a DaceFramework subclass shared by both arches, selected by the JSON "arch" field). Reuses the existing *_dace.py benchmark implementations and every DaceFramework calling convention. Verified: the CPU variant builds, runs and validates against NumPy on atax (a reduction kernel). The GPU variant is defined/registered analogously and builds + canonicalizes; fully running it needs the GPU device-schedule assignment that DaCe's canonicalize(target='gpu') path does not yet emit, so it is definition-only for now.
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.
Three changes.
1.
np.empty/np.empty_like->np.zeros/np.zeros_like256 sites across 132 files, all backends (numpy, dace, numba, cupy, dpnp, pythran, legate, jax).
An uninitialized
emptybuffer that a kernel writes only partially leaves stale/garbage memory in the result. Those kernels are therefore read-nondeterministic: the same input can yield different outputs on different runs, and the comparison against the reference flakes. Zero-initializing makes every run reproducible. For buffers that are fully overwritten before use the change is equivalent, so all sites are converted uniformly. Commented-out code is left untouched.2. Well-conditioned Gram-Schmidt input
gramschmidt'sinitializenow builds a deterministically full-column-rank, well-conditioned matrix via a diagonal-dominance term, replacing the reject-samplingwhile np.linalg.matrix_rank(A) < Nloop:A plain random matrix is only full-rank in expectation and can still be poorly conditioned, which makes the QR numerically unstable and sensitive to harmless FMA-contraction reassociation. The added diagonal gives
cond(A) ~= 1.5deterministically. All framework implementations validate against the same-input NumPy reference, so the change is self-consistent.3. New frameworks:
dace_canonicalize_cpu/dace_canonicalize_gpuTwo frameworks that run DaCe's
canonicalizepipeline instead ofauto_optimize, to contrast the WCR (write-conflict-resolution) reduction lowering:canonicalize(target=cpu|gpu, peel_limit=4, break_anti_dependence=True, interchange_carry_with_map=True, scatter_to_guarded_maps=True)+finalize_for_target, leavingsdfg.openmp_array_reductions = True(WCR-config ON) so a whole-buffer WCR accumulator of a parallel map lowers to an OpenMPreduction(op:A[0:n])array-section clause instead of per-element atomics.dace_cpu/dace_gpunow setopenmp_array_reductions = Falseexplicitly before compile (WCR-config OFF, the default per-element atomic path).Registered exactly like
dace_cpu/dace_gpu:framework_info/dace_canonicalize_{cpu,gpu}.json+ aDaceCanonicalizeFrameworkclass (aDaceFrameworksubclass shared by both arches, selected by the JSONarchfield). Reuses the existing*_dace.pyimplementations and everyDaceFrameworkcalling convention.Verified: the CPU variant builds, runs and validates against NumPy on
atax(a reduction kernel). The GPU variant is defined/registered analogously and builds + canonicalizes; fully running it needs the GPU device-schedule assignment that DaCe'scanonicalize(target='gpu')path does not yet emit, so it is definition-only for now.