Skip to content

bench: refactor to use dynamic memory allocation - #14099

Merged
kgryte merged 7 commits into
developfrom
philipp/fix-propagation-2026-08-09
Aug 9, 2026
Merged

bench: refactor to use dynamic memory allocation#14099
kgryte merged 7 commits into
developfrom
philipp/fix-propagation-2026-08-09

Conversation

@Planeshifter

Copy link
Copy Markdown
Member

Description

What is the purpose of this pull request?

This pull request:

  • propagates fixes merged to develop between 2026-08-08 16:20 (-0700) and 2026-08-09 06:04 (-0700) to sibling packages.

Applies the stack-allocation fix from 91c2fae (#14054, #8643) to the 13 remaining benchmark files still declaring runtime-sized C arrays on the stack. Worst offenders blow past the 8 MB default stack limit — lapack/base/dlacpy's double A[ N*N ] hits ~8 MB per array at N=1000, and blas/base/dznrm2/zscal's double X[ len*2 ] hits ~16 MB at len=10^6 — and VLAs are optional in C11 regardless. All affected files switch to malloc/free:

  • blas/base/{scnrm2,dznrm2,scasum,zdrot,zscal,zdscal,dgemv,sgemv,dger,sger}
  • lapack/base/dlacpy
  • stats/strided/{dcovmatmtk,dnanmskmax}

dnanmskmax was left partially converted by earlier work — x was already heap-allocated but mask remained a VLA — and is now brought in line with its siblings dnanmskmin/dnanmskrange.

Related Issues

Does this pull request have any related issues?

This pull request has the following related issues:

Questions

Any questions for reviewers of this pull request?

No.

Other

Any other information relevant to this pull request? This may include screenshots, references, and/or implementation notes.

Validation performed before inclusion: repo-wide VLA sweep over benchmark/**/*.c (multiple search patterns, false positives on #define-sized arrays and indexing expressions excluded); two independent validation passes reading each target file in full (confirming runtime-sized declarations, single-return control flow, no sizeof/address-of usage on candidate arrays, <stdlib.h> availability); a per-site adaptation pass; a style-consistency pass; and gcc -fsyntax-only over all modified files with resolved @stdlib include paths.

Deliberately excluded: blas/base/zaxpy (worst-case VLA is ~10 KB — main() passes N = floor(sqrt(10^i)), so the stack-overflow rationale does not apply); blas/ext/base/ndarray/{csum,zsum} addon.c const-view normalization (constness already handled via explicit cast; no defect present); comment-wording updates in blas/base/{scabs1,dcabs1} type tests (validators split on whether the legacy wording is defective in a zero-argument-only test block). Pre-existing latent issues in zdrot/dlacpy init loops were intentionally left untouched to keep the diff scoped to the propagated fix.

Checklist

Please ensure the following tasks are completed before submitting this pull request.

AI Assistance

When authoring the changes proposed in this PR, did you use any kind of AI assistance?

  • Yes
  • No

If you answered "yes" above, how did you use AI assistance?

  • Code generation (e.g., when writing an implementation or fixing a bug)
  • Test/benchmark generation
  • Documentation (including examples)
  • Research and understanding

Disclosure

If you answered "yes" to using AI assistance, please provide a short disclosure indicating how you used AI assistance. This helps reviewers determine how much scrutiny to apply when reviewing your contribution. Example disclosures: "This PR was written primarily by Claude Code." or "I consulted ChatGPT to understand the codebase, but the proposed changes were fully authored manually by myself.".

This PR was authored by Claude Code as part of an automated fix-propagation routine: candidate sites were enumerated by search, independently validated by two review passes, adapted per site, style-checked, and syntax-checked before committing.

🤖 Generated with Claude Code

https://claude.ai/code/session_01DSCf4wFDyy8QnpxnPxLFVr


Generated by Claude Code

Propagates fix from 91c2fae ("chore: clean-up") to sibling packages
with the same variable-length-array usage in C benchmark files.
Stack arrays sized by runtime benchmark lengths reach ~16 MB worst
case (e.g. `double A[ N*N ]` with N=1000), exceeding default stack
limits; converts them to malloc/free in `blas/base/*`,
`lapack/base/dlacpy`, and `stats/strided/*` benchmarks.

Ref: #8643

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DSCf4wFDyy8QnpxnPxLFVr
@stdlib-bot stdlib-bot added the Good First PR A pull request resolving a Good First Issue. label Aug 9, 2026
cppcheck's uninitdata checker cannot see that the heap-allocated
`stdlib_complex128_t` array is initialized via the struct-returning
`stdlib_complex128` constructor before the post-loop NaN checks.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DSCf4wFDyy8QnpxnPxLFVr
@stdlib-bot

stdlib-bot commented Aug 9, 2026

Copy link
Copy Markdown
Contributor

Coverage Report

Package Statements Branches Functions Lines
blas/base/dgemv $\\color{red}757/758$
$\\color{green}+0.00\\%$
$\\color{red}116/117$
$\\color{green}+0.00\\%$
$\\color{green}6/6$
$\\color{green}+0.00\\%$
$\\color{red}757/758$
$\\color{green}+0.00\\%$
blas/base/dger $\\color{green}715/715$
$\\color{green}+0.00\\%$
$\\color{green}84/84$
$\\color{green}+0.00\\%$
$\\color{green}5/5$
$\\color{green}+0.00\\%$
$\\color{green}715/715$
$\\color{green}+0.00\\%$
blas/base/dznrm2 $\\color{green}452/452$
$\\color{green}+0.00\\%$
$\\color{green}37/37$
$\\color{green}+0.00\\%$
$\\color{green}4/4$
$\\color{green}+0.00\\%$
$\\color{green}452/452$
$\\color{green}+0.00\\%$
blas/base/scasum $\\color{green}369/369$
$\\color{green}+0.00\\%$
$\\color{green}17/17$
$\\color{green}+0.00\\%$
$\\color{green}4/4$
$\\color{green}+0.00\\%$
$\\color{green}369/369$
$\\color{green}+0.00\\%$
blas/base/scnrm2 $\\color{green}453/453$
$\\color{green}+0.00\\%$
$\\color{green}37/37$
$\\color{green}+0.00\\%$
$\\color{green}4/4$
$\\color{green}+0.00\\%$
$\\color{green}453/453$
$\\color{green}+0.00\\%$
blas/base/sgemv $\\color{red}759/760$
$\\color{green}+0.00\\%$
$\\color{red}116/117$
$\\color{green}+0.00\\%$
$\\color{green}6/6$
$\\color{green}+0.00\\%$
$\\color{red}759/760$
$\\color{green}+0.00\\%$
blas/base/sger $\\color{green}715/715$
$\\color{green}+0.00\\%$
$\\color{green}84/84$
$\\color{green}+0.00\\%$
$\\color{green}5/5$
$\\color{green}+0.00\\%$
$\\color{green}715/715$
$\\color{green}+0.00\\%$
blas/base/zdrot $\\color{green}415/415$
$\\color{green}+0.00\\%$
$\\color{green}17/17$
$\\color{green}+0.00\\%$
$\\color{green}4/4$
$\\color{green}+0.00\\%$
$\\color{green}415/415$
$\\color{green}+0.00\\%$
blas/base/zdscal $\\color{green}376/376$
$\\color{green}+0.00\\%$
$\\color{green}18/18$
$\\color{green}+0.00\\%$
$\\color{green}4/4$
$\\color{green}+0.00\\%$
$\\color{green}376/376$
$\\color{green}+0.00\\%$
blas/base/zscal $\\color{green}400/400$
$\\color{green}+0.00\\%$
$\\color{green}17/17$
$\\color{green}+0.00\\%$
$\\color{green}4/4$
$\\color{green}+0.00\\%$
$\\color{green}400/400$
$\\color{green}+0.00\\%$
lapack/base/dlacpy $\\color{green}957/957$
$\\color{green}+0.00\\%$
$\\color{green}54/54$
$\\color{green}+0.00\\%$
$\\color{green}8/8$
$\\color{green}+0.00\\%$
$\\color{green}957/957$
$\\color{green}+0.00\\%$
stats/strided/dcovmatmtk $\\color{green}923/923$
$\\color{green}+0.00\\%$
$\\color{green}58/58$
$\\color{green}+0.00\\%$
$\\color{green}5/5$
$\\color{green}+0.00\\%$
$\\color{green}923/923$
$\\color{green}+0.00\\%$
stats/strided/dnanmskmax $\\color{green}406/406$
$\\color{green}+0.00\\%$
$\\color{green}31/31$
$\\color{green}+0.00\\%$
$\\color{green}4/4$
$\\color{green}+0.00\\%$
$\\color{green}406/406$
$\\color{green}+0.00\\%$

The above coverage report was generated for the changes in this PR.

kgryte added 5 commits August 9, 2026 13:53
Signed-off-by: Athan <kgryte@gmail.com>
Signed-off-by: Athan <kgryte@gmail.com>
Signed-off-by: Athan <kgryte@gmail.com>
Signed-off-by: Athan <kgryte@gmail.com>
Signed-off-by: Athan <kgryte@gmail.com>
@kgryte
kgryte marked this pull request as ready for review August 9, 2026 20:55
@kgryte
kgryte requested a review from a team August 9, 2026 20:55
@kgryte kgryte added the Benchmarks Pull requests adding or improving benchmarks for measuring performance. label Aug 9, 2026
@stdlib-bot stdlib-bot added the Needs Review A pull request which needs code review. label Aug 9, 2026
@kgryte kgryte changed the title chore: replace VLAs with heap allocation in C benchmarks bench: refactor to use dynamic memory allocation Aug 9, 2026
@kgryte
kgryte merged commit 3208321 into develop Aug 9, 2026
48 checks passed
@kgryte
kgryte deleted the philipp/fix-propagation-2026-08-09 branch August 9, 2026 21:40
@stdlib-bot stdlib-bot removed the Needs Review A pull request which needs code review. label Aug 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Benchmarks Pull requests adding or improving benchmarks for measuring performance. Good First PR A pull request resolving a Good First Issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants