Repository navigation
Conversation
Unlike the pointer overload `offset_of(const int *)`, which loops strictly over `0 <= i < this->dimensions()`, the variadic `Halide::Runtime::Buffer::offset_of(int d, int first, Args... rest)` overload previously indexed `this->buf.dim[d]` without checking whether `d` had already reached `this->dimensions()`. For `Buffer<T, AnyDims>`, passing more coordinates than `dimensions()` reads uninitialized `shape[d]` storage (for `d < InClassDimStorage`) or reads out-of-bounds past `buf.dim` (for `d >= InClassDimStorage` or external `halide_buffer_t` descriptors). Guard `offset_of` when `d >= this->dimensions()` so it asserts under `HALIDE_RUNTIME_BUFFER_CHECK_INDICES` (matching the compile-time `static_assert` on fixed-rank `Buffer<T, Dims>`) and returns `0` without reading `this->buf.dim[d]` when runtime index checks are disabled. Also update the 0-D scalar buffer check in `correctness_lerp` (`test/correctness/lerp.cpp`) from `result(0)` to `result()`. Co-authored-by: Gemini 4 <gemini-code-assist@google.com>
Member
|
Thanks for the PR! This code is intended to go in hot loops, and any kind of branching here is likely to break autovectorization of those loops. Please just assert d < dimensions() in the existing ifdef block |
This branch has not been deployed
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.
Unlike the pointer overload
offset_of(const int *), which loops strictly over0 <= i < this->dimensions(), the variadicHalide::Runtime::Buffer::offset_of(int d, int first, Args... rest)overload previously indexedthis->buf.dim[d]without checking whetherdhad already reachedthis->dimensions(). ForBuffer<T, AnyDims>, passing more coordinates thandimensions()reads uninitializedshape[d]storage (ford < InClassDimStorage) or reads out-of-bounds pastbuf.dim(ford >= InClassDimStorageor externalhalide_buffer_tdescriptors).Guard
offset_ofwhend >= this->dimensions()so it asserts underHALIDE_RUNTIME_BUFFER_CHECK_INDICES(matching the compile-timestatic_asserton fixed-rankBuffer<T, Dims>) and returns0without readingthis->buf.dim[d]when runtime index checks are disabled. Also update the 0-D scalar buffer check incorrectness_lerp(test/correctness/lerp.cpp) fromresult(0)toresult().Generated with Gemini 4 gemini-code-assist@google.com