Skip to content

fix: Do not mutate external TensorInfo in import_memory()#1270

Open
morgolock wants to merge 1 commit intomainfrom
pr/tinfo_soft_init
Open

fix: Do not mutate external TensorInfo in import_memory()#1270
morgolock wants to merge 1 commit intomainfrom
pr/tinfo_soft_init

Conversation

@morgolock
Copy link
Contributor

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

…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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant