fix: Do not mutate external TensorInfo in import_memory()#1270
Open
fix: Do not mutate external TensorInfo in import_memory()#1270
Conversation
…soft_init When a TensorInfo is shared with a Tensor via allocator()->soft_init(), the allocator stores a reference to the caller-provided TensorInfo. If import_memory() is later called, the allocator currently sets TensorInfo::is_resizable(false). Because the TensorInfo is shared, this mutates the caller-owned metadata. Subsequent operations that expect the TensorInfo to remain resizable (e.g. extend_padding()) can fail. This is observable in multi-threaded or reused inference paths (for example multi-threaded CpuGemmConv2d), where the same TensorInfo is reused across runs. In such cases import_memory() unexpectedly changes the caller-visible TensorInfo state. Fix this by distinguishing between allocator-owned and external TensorInfo instances: - Track ownership with `_owns_info`. - Track imported buffers with `_is_imported`. - `soft_init()` marks the TensorInfo as externally owned. - `import_memory()` only mutates `TensorInfo::is_resizable()` when the allocator owns the TensorInfo. - When referencing external TensorInfo, allocator logic relies on the internal `_is_imported` state instead of mutating the caller metadata. This preserves existing behaviour for allocator-owned TensorInfo while avoiding unexpected mutations of caller-provided metadata. The change is minimal and does not modify public APIs. Test: - Add/enable UNIT test `ImportMemoryDoesNotMutateExternalInfo`. - Verify that `shared_info.is_resizable()` remains true after import_memory() and that `extend_padding()` succeeds. Change-Id: Iac9d5807789a8ed74205cdee098b36d0f5269d59 Signed-off-by: Pablo Marquez Tello <pablo.tello@arm.com>
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.
When a TensorInfo is shared with a Tensor via allocator()->soft_init(), the allocator stores a reference to the caller-provided TensorInfo. If import_memory() is later called, the allocator currently sets TensorInfo::is_resizable(false). Because the TensorInfo is shared, this mutates the caller-owned metadata. Subsequent operations that expect the TensorInfo to remain resizable (e.g. extend_padding()) can fail.
This is observable in multi-threaded or reused inference paths (for example multi-threaded CpuGemmConv2d), where the same TensorInfo is reused across runs. In such cases import_memory() unexpectedly changes the caller-visible TensorInfo state. Fix this by distinguishing between allocator-owned and external TensorInfo instances:
_owns_info._is_imported.soft_init()marks the TensorInfo as externally owned.import_memory()only mutatesTensorInfo::is_resizable()when the allocator owns the TensorInfo._is_importedstate instead of mutating the caller metadata.This preserves existing behaviour for allocator-owned TensorInfo while avoiding unexpected mutations of caller-provided metadata.
The change is minimal and does not modify public APIs.
Test:
ImportMemoryDoesNotMutateExternalInfo.shared_info.is_resizable()remains true after import_memory() and thatextend_padding()succeeds.Change-Id: Iac9d5807789a8ed74205cdee098b36d0f5269d59