Reuse reduction/dot buffer as sqrt output in linalg.norm - #3062
Conversation
Pass out= to dpnp.sqrt in the 2-norm and Frobenius-norm branches so the existing reduction (or dot) result is reused as the sqrt output buffer instead of allocating a new array.
|
View rendered docs @ https://intelpython.github.io/dpnp/index.html |
|
Array API standard conformance tests for dpnp=0.21.0dev8=py314ha0e2e8e_4 ran successfully. |
Performance & memory validationBenchmarked this branch against Coverage — 5 workloads, one per touched branch (a large-output variant to show the memory effect and a scalar-output variant as a no-regression control), across
Method — median of 400 pooled reps per config (4 rounds × 100, alternating master/PR order each round to cancel thermal drift; 5 cold warmup calls excluded, device queue synced per call), with a bootstrap 95% CI on each master-vs-PR ratio. Transient USM allocations were counted by instrumenting fresh Runtime — no regression
Memory — one buffer removed per call
ConclusionResults confirm the PR description: an allocation saving only — no change to results or kernel-launch count, no runtime regression, and a deterministic one-buffer-per-call memory reduction that scales with output size. |
In the `dpnp.linalg.norm` implementation, the 2-norm and Frobenius-norm branches computed `sqrt(sum(...))` (or `sqrt(dot(...))` on the `axis=None` fast path) allocating a fresh array for the `sqrt` output on top of the array already produced by the reduction. These branches now capture the reduction (or dot) result and pass it back as `out=` to `dpnp.sqrt`, so the intermediate buffer is reused as the output instead of allocating a new one. The reused buffer is a private, unaliased array in every case, and its dtype matches the `sqrt` output, so the in-place write is safe. On the `axis=None` fast path the reused buffer is a scalar, so the change there is for consistency. This is an allocation saving only; it does not change results or reduce the number of kernel launches. cbd45df
In the
dpnp.linalg.normimplementation, the 2-norm and Frobenius-norm branches computedsqrt(sum(...))(orsqrt(dot(...))on theaxis=Nonefast path) allocating a fresh array for thesqrtoutput on top of the array already produced by the reduction.These branches now capture the reduction (or dot) result and pass it back as
out=todpnp.sqrt, so the intermediate buffer is reused as the output instead of allocating a new one. The reused buffer is a private, unaliased array in every case, and its dtype matches thesqrtoutput, so the in-place write is safe. On theaxis=Nonefast path the reused buffer is a scalar, so the change there is for consistency.This is an allocation saving only; it does not change results or reduce the number of kernel launches.