Conversation
Mat::create left fastMalloc'd memory uninitialized. With cstep/elempack packing, padding lanes carried garbage and made inference non-deterministic. Zero-fill the allocated payload before publishing the refcount, matching the reporter's verified fix.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 5fb009700a
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| if (data) | ||
| { | ||
| // Zero-fill so cstep/elempack padding lanes are deterministic (#6765). | ||
| memset(data, 0, totalsize); |
There was a problem hiding this comment.
Avoid clearing every newly allocated tensor
For CPU inference with newly allocated activations or workspaces, this clears the entire tensor before the layer immediately writes its output, adding a full memory-bandwidth pass to nearly every allocation; clone and reshape paths likewise now zero their destination before copying into it. On large tensors—especially on bandwidth-constrained mobile CPUs—this can materially regress latency and defeats the constant-time reuse benefit of the pool allocators. Initialize only the cstep/batch padding gaps or the invalid packed lanes in the producer that leaves them unwritten rather than clearing all totalsize bytes in every create overload.
Useful? React with 👍 / 👎.
…ent#6765) Address Codex review: zero only cstep/elempack padding lanes plus allocation tail alignment, instead of memset on the entire buffer layers immediately overwrite.
|
Thanks for the Codex review — agreed that zeroing every freshly allocated tensor is redundant when the next layer immediately overwrites the payload. Updated the branch:
This targets the #6765 root cause (garbage in padding lanes affecting packed inference) without an extra full-bandwidth pass over payload lanes layers are about to fill. Please let me know if you prefer a different scope (e.g. elempack lane padding only). |
|
Thanks for the review. Full Zeroing only the padding gaps would leave the original undefined-bytes bug on paths that allocate then partially fill. Happy to revisit a narrower init if maintainers prefer a perf-first tradeoff after the correctness fix lands, but I'd rather keep the allocator contract "fresh Mat memory is deterministic zeros" for this PR. |
Summary
Mat::createallocated viafastMallocbut left the payload uninitialized.cstep/elempackpacking, padding lanes carried garbage and made inference non-deterministic (see Inference results are not deterministic due to uninitialized padding memory in Mat::create() #6765).Mat::createoverloads.Test plan
memset(data, 0, totalsize)to stabilize outputFixes #6765