Skip to content
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

[core] Tensor::data member preserve constness of tensor #29594

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

praasz
Copy link
Contributor

@praasz praasz commented Mar 20, 2025

Details:

  • The Tensor::data function member returns const/non-const pointer to data depends if tensor object is constant.

Blocked by:

Tickets:

praasz added 2 commits March 20, 2025 06:58
Signed-off-by: Raasz, Pawel <pawel.raasz@intel.com>
Signed-off-by: Raasz, Pawel <pawel.raasz@intel.com>
@praasz praasz added this to the 2025.2 milestone Mar 20, 2025
@praasz praasz requested review from a team as code owners March 20, 2025 08:09
@github-actions github-actions bot added category: inference OpenVINO Runtime library - Inference category: Core OpenVINO Core (aka ngraph) category: IE Tests OpenVINO Test: plugins and common category: TEMPLATE OpenVINO Template plugin category: CPP API OpenVINO CPP API bindings category: NPU OpenVINO NPU plugin category: NPUW NPUW plugin labels Mar 20, 2025
Signed-off-by: Raasz, Pawel <pawel.raasz@intel.com>
Copy link
Contributor

@ilya-lavrenov ilya-lavrenov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like we break source compatibility with this change?

@ilya-lavrenov ilya-lavrenov self-assigned this Mar 20, 2025
Signed-off-by: Raasz, Pawel <pawel.raasz@intel.com>
@praasz
Copy link
Contributor Author

praasz commented Mar 20, 2025

Looks like we break source compatibility with this change?

The compilation errors will points where cast of tensor data pointer is done wrong (programing errors: missing const) from this perspective it will break compatibility.

To avoid compile errors with current data() member there is a need to introduce new member or overload data with some tag and mark current data() as deprecated or it will work as new implementation of pointer cast, but still there will be get non-const pointer to const tensors.

@@ -96,7 +96,7 @@ bool Transpose::evaluate(TensorVector& outputs, const TensorVector& inputs) cons
};

auto out_ptr = int4_iterator(static_cast<uint8_t*>(out.data()));
auto in_ptr = int4_iterator(static_cast<uint8_t*>(arg.data()));
auto in_ptr = int4_iterator(static_cast<uint8_t*>(const_cast<void*>(arg.data())));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe add a comment to describe that data will not be changed here

praasz added 2 commits March 21, 2025 07:19
Signed-off-by: Raasz, Pawel <pawel.raasz@intel.com>
Signed-off-by: Raasz, Pawel <pawel.raasz@intel.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
category: Core OpenVINO Core (aka ngraph) category: CPP API OpenVINO CPP API bindings category: GPU OpenVINO GPU plugin category: IE Tests OpenVINO Test: plugins and common category: inference OpenVINO Runtime library - Inference category: NPU OpenVINO NPU plugin category: NPUW NPUW plugin category: TEMPLATE OpenVINO Template plugin
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants