-
Notifications
You must be signed in to change notification settings - Fork 4k
Fix Conv LHS packing padding/uninitialized ptrs #27214
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -395,6 +395,12 @@ static std::shared_ptr<const void*[]> LhsPtrFill(const size_t ci, const size_t i | |
| auto lhs_ptrs = std::shared_ptr<const void*[]>(new const void*[lhs_ptrs_k * lhs_ptrs_m], | ||
| std::default_delete<const void*[]>()); | ||
|
|
||
| // Initialize all padding entries. For partial tiles (m < m_step), | ||
| // the kai LHS packing kernel may still read pointer entries beyond the logically | ||
| // filled 'm' positions. Leaving these uninitialized can cause non-deterministic | ||
| // reads and corrupt packed LHS data. | ||
| auto lhs_ptrs_ = lhs_ptrs.get(); | ||
| std::fill(lhs_ptrs_, lhs_ptrs_ + (lhs_ptrs_k * lhs_ptrs_m), reinterpret_cast<const void*>(&pad_ptr[0])); | ||
|
|
||
| auto ih_out_size = ComputeConvOutSize(ih, kh, padding, 1); | ||
| auto iw_out_size = ComputeConvOutSize(iw, kw, padding, 1); | ||
|
|
@@ -430,7 +436,6 @@ static std::shared_ptr<const void*[]> LhsPtrFill(const size_t ci, const size_t i | |
| }; | ||
|
|
||
| size_t m_{0}; | ||
| auto lhs_ptrs_ = lhs_ptrs.get(); | ||
| for (size_t ih_ = 0; ih_ < ih_out_size; ih_ += sh) { | ||
| for (size_t iw_ = 0; iw_ < iw_out_size; iw_ += sw, ++m_) { | ||
| size_t k_{0}; | ||
|
|
@@ -460,7 +465,17 @@ static std::unique_ptr<std::byte[]> LhsPackImageDataSme(const size_t ci, const s | |
| // figure out how many blocks needed to correctly fill padding | ||
| padsize = ((ci + padsize - 1) / padsize) * padsize; | ||
| } | ||
| static std::vector<float>pad_ptr(padsize, 0.f); | ||
|
|
||
| // pad_ptr must be at least 'ci' floats for padding pixels. | ||
| // Using a thread_local grow-only buffer to avoid cross-thread interference and ensure sizing is correct. | ||
| thread_local std::vector<float> pad_ptr; | ||
| if (pad_ptr.size() < padsize) { | ||
| pad_ptr.resize(padsize, 0.f); | ||
| } else { | ||
| // Ensure any previously-used region remains zeroed (grow-only means it should already be zeros, | ||
| // but keep this explicit for safety). | ||
| std::fill(pad_ptr.begin(), pad_ptr.end(), 0.f); | ||
| } | ||
|
Comment on lines
+471
to
+478
|
||
|
|
||
| LhsCacheKey key = { | ||
| ci, ih, iw, | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would a stack local vector avoid cross-thread interference? And if indeed there is an issue, should this be synchronized?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So each thread would have its own individual instance of this vector, and no synchronization mechanism is required because the storage is thread-local and not shared between threads.