Avoid redundant LUT buffer initialization#29690
Open
GopalakrishnanN wants to merge 1 commit into
Open
Conversation
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
tianleiwu
approved these changes
Jul 13, 2026
Contributor
There was a problem hiding this comment.
Pull request overview
This PR optimizes the MLAS MlasLutGemm temporary LUT buffer allocation by avoiding redundant value-initialization while preserving the existing full-buffer zeroing that the implementation relies on.
Changes:
- Switch LUT scratch buffer allocation to
std::make_unique_for_overwrite<int8_t[]>to skip default initialization. - Keep the existing
memset(..., 0, lut_buffer_size)to preserve the required zero-initialized LUT data/padding.
hariharans29
approved these changes
Jul 13, 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.
Description
std::make_unique_for_overwrite.memset, preserving zero-initialized LUT data and padding while avoiding the allocation's redundant value-initialization pass.Motivation and Context
MlasLutGemmcurrently value-initializes the temporary byte buffer and immediately zeroes the entire buffer again. The buffer ranges from a few KB during decode to multiple MB for representative prefill shapes, so the first write consumes memory bandwidth without affecting behavior.Local Windows MSVC Release measurements used four alternating baseline/changed process runs with five repetitions each. The unaffected
Dequant+SGEMMfallback served as a control.(M, N, K)(128, 384, 1024)(128, 1024, 4096)Testing
onnxruntime_mlas_benchmarkandonnxruntime_mlas_testin Release mode.onnxruntime_mlas_test.exe --gtest_filter=SQLutGemmBlkBitWidth2BlkLen*.*(102 tests passed).lintrunner -a onnxruntime/core/mlas/lib/qlutgemm.cpp.