-
Notifications
You must be signed in to change notification settings - Fork 816
fix: Do not mutate external TensorInfo in import_memory() #1270
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
Open
morgolock
wants to merge
1
commit into
main
Choose a base branch
from
pr/tinfo_soft_init
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+147
−11
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| /* | ||
| * Copyright (c) 2016-2021, 2024-2025 Arm Limited. | ||
| * Copyright (c) 2016-2021, 2024-2026 Arm Limited. | ||
| * | ||
| * SPDX-License-Identifier: MIT | ||
| * | ||
|
|
@@ -110,10 +110,26 @@ class ITensorAllocator | |
| /** Interface to be implemented by the child class to unlock the memory allocation after the CPU is done accessing it. */ | ||
| virtual void unlock() = 0; | ||
|
|
||
| /** Returns whether allocator currently owns the TensorInfo metadata object. */ | ||
| bool owns_info() const; | ||
| /** Returns whether the allocator has imported external backing memory. */ | ||
| bool is_imported() const; | ||
| /** Track import state for derived allocators when ownership of backing memory changes. */ | ||
| void set_imported(bool imported); | ||
| /** For external TensorInfo metadata, import state determines resizable behavior from allocator perspective. */ | ||
| bool allocator_considers_resizable() const; | ||
| /** Set the resizable flag on the owned TensorInfo only if the allocator owns it. | ||
| * | ||
| * @return True if the TensorInfo was mutated, false otherwise. | ||
| */ | ||
| bool set_resizable_if_info_owned(bool is_resizable); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it is set function, we don't need to have return type. |
||
|
|
||
| private: | ||
| TensorInfo _info_owned{}; /**< Tensor's metadata. */ | ||
| TensorInfo *_info_external{nullptr}; /**< External Tensor's metadata */ | ||
| size_t _alignment{}; /**< Tensor's alignment in bytes */ | ||
| bool _owns_info{true}; /**< True when allocator owns metadata; false for soft_init(). */ | ||
| bool _is_imported{false}; /**< True when memory was imported instead of allocated by allocator. */ | ||
| }; | ||
| } // namespace arm_compute | ||
| #endif // ACL_ARM_COMPUTE_RUNTIME_ITENSORALLOCATOR_H | ||
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,75 @@ | ||
| /* | ||
| * Copyright (c) 2026 Arm Limited. | ||
| * | ||
| * SPDX-License-Identifier: MIT | ||
| * | ||
| * Permission is hereby granted, free of charge, to any person obtaining a copy | ||
| * of this software and associated documentation files (the "Software"), to | ||
| * deal in the Software without restriction, including without limitation the | ||
| * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or | ||
| * sell copies of the Software, and to permit persons to whom the Software is | ||
| * furnished to do so, subject to the following conditions: | ||
| * | ||
| * The above copyright notice and this permission notice shall be included in all | ||
| * copies or substantial portions of the Software. | ||
| * | ||
| * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
| * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
| * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
| * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
| * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
| * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
| * SOFTWARE. | ||
| */ | ||
| #include "arm_compute/core/Coordinates.h" | ||
| #include "arm_compute/core/TensorInfo.h" | ||
| #include "arm_compute/core/TensorShape.h" | ||
| #include "arm_compute/runtime/Tensor.h" | ||
|
|
||
| #include "tests/framework/Asserts.h" | ||
| #include "tests/framework/Macros.h" | ||
| #include "tests/validation/Validation.h" | ||
|
|
||
| namespace arm_compute | ||
| { | ||
| namespace test | ||
| { | ||
| namespace validation | ||
| { | ||
| TEST_SUITE(UNIT) | ||
| TEST_SUITE(TensorInfo) | ||
|
|
||
| TEST_CASE(ImportMemoryDoesNotMutateExternalInfo, framework::DatasetMode::ALL) | ||
| { | ||
| TensorInfo out_info(TensorShape(16U, 4U, 4U), 1, DataType::F32, DataLayout::NHWC); | ||
| out_info.set_is_resizable(true); | ||
|
|
||
| Tensor out_tensor; | ||
| out_tensor.allocator()->init(out_info); | ||
| out_tensor.allocator()->allocate(); | ||
|
|
||
| // Simulate a shared TensorInfo used as a view wrapper. | ||
| TensorInfo shared_info(out_info); | ||
| shared_info.set_is_resizable(true); | ||
|
|
||
| Tensor view_tensor; | ||
| view_tensor.allocator()->soft_init(shared_info); | ||
|
|
||
| // Ensure it's still resizable before import. | ||
| ARM_COMPUTE_EXPECT(shared_info.is_resizable(), framework::LogLevel::ERRORS); | ||
|
|
||
| // Import memory into the view tensor. | ||
| ARM_COMPUTE_ASSERT(bool(view_tensor.allocator()->import_memory(out_tensor.buffer()))); | ||
|
|
||
| // Regression assert: import_memory must NOT mutate the caller-owned shared_info. | ||
| ARM_COMPUTE_EXPECT(shared_info.is_resizable(), framework::LogLevel::ERRORS); | ||
|
|
||
| // extend_padding should succeed (not throw). | ||
| ARM_COMPUTE_EXPECT_NO_THROW(shared_info.extend_padding(PaddingSize(1, 1, 1, 1)), framework::LogLevel::ERRORS); | ||
| } | ||
|
|
||
| TEST_SUITE_END() // TensorInfo | ||
| TEST_SUITE_END() // UNIT | ||
| } // namespace validation | ||
| } // namespace test | ||
| } // namespace arm_compute |
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.
Uh oh!
There was an error while loading. Please reload this page.