OpenVINO™ is an open source toolkit for optimizing and deploying AI inference
C++ aicomputer-visiondeep-learningdeploy-aidiffusion-modelsgenerative-aigood-first-issueinferencellm-inferencenatural-language-processingnlpopenvinooptimize-aiperformance-boostrecommendation-systemspeech-recognitionstable-diffusiontransformersyolo
[core] Remove and change deprecated data() member in tensor (#32569)
Pawel Raaszfa61863abbc1
diff --git a/samples/cpp/benchmark_app/inputs_filling.cpp b/samples/cpp/benchmark_app/inputs_filling.cppindex ce77e43adda..96a0d3190b5 100644--- a/samples/cpp/benchmark_app/inputs_filling.cpp+++ b/samples/cpp/benchmark_app/inputs_filling.cpp@@ -1015,7 +1015,5 @@ void copy_tensor_data(ov::Tensor& dst, const ov::Tensor& src) {throw std::runtime_error("Source and destination tensors shapes and byte sizes are expected to be equal for data copying.");}- OPENVINO_SUPPRESS_DEPRECATED_START // keep until 2026.0 release- memcpy(dst.data(), src.data(), src.get_byte_size());- OPENVINO_SUPPRESS_DEPRECATED_END // keep until 2026.0 release+ memcpy(dst.data(), src.data(), src.get_byte_size());}diff --git a/samples/cpp/common/utils/include/samples/classification_results.h b/samples/cpp/common/utils/include/samples/classification_results.hindex 9be3bd6a279..eeb9c48a487 100644--- a/samples/cpp/common/utils/include/samples/classification_results.h+++ b/samples/cpp/common/utils/include/samples/classification_results.h@@ -66,9 +66,7 @@ private:for (size_t i = 0; i < batchSize; i++) {const size_t offset = i * (input.get_size() / batchSize);- OPENVINO_SUPPRESS_DEPRECATED_START // keep until 2026.0 release- const T* batchData = input.data<T>();- OPENVINO_SUPPRESS_DEPRECATED_END+ const T* batchData = input.data<T>();batchData += offset;diff --git a/samples/cpp/model_creation_sample/main.cpp b/samples/cpp/model_creation_sample/main.cppindex 523424138fd..8d6e1c271d4 100644--- a/samples/cpp/model_creation_sample/main.cpp+++ b/samples/cpp/model_creation_sample/main.cpp@@ -77,9 +77,7 @@ ov::Tensor read_weights(const std::string& filepath) {*/std::shared_ptr<ov::Model> create_model(const std::string& path_to_weights) {const ov::Tensor weights = read_weights(path_to_weights);- OPENVINO_SUPPRESS_DEPRECATED_START // keep until 2026.0 release- const std::uint8_t* data = weights.data<std::uint8_t>();- OPENVINO_SUPPRESS_DEPRECATED_END+ const std::uint8_t* data = weights.data<std::uint8_t>();// -------input------std::vector<ptrdiff_t> padBegin{0, 0};diff --git a/src/core/dev_api/openvino/runtime/shared_buffer.hpp b/src/core/dev_api/openvino/runtime/shared_buffer.hppindex 2d3d29fc8f8..9aa01b09b8f 100644--- a/src/core/dev_api/openvino/runtime/shared_buffer.hpp+++ b/src/core/dev_api/openvino/runtime/shared_buffer.hpp@@ -93,7 +93,7 @@ protected:}const char* m_data;- size_t m_size;+ const size_t m_size;size_t m_offset;};diff --git a/src/core/include/openvino/runtime/tensor.hpp b/src/core/include/openvino/runtime/tensor.hppindex 218f65e64aa..211d3b3328a 100644--- a/src/core/include/openvino/runtime/tensor.hpp+++ b/src/core/include/openvino/runtime/tensor.hpp@@ -222,26 +222,19 @@ public:* @return A host pointer to tensor memory* @{*/--#ifndef IN_OV_COMPONENT- OPENVINO_DEPRECATED("This function will return const void* in 2026.0. Check if used correctly")-#endif- void* data() const;+ const void* data() const;void* data();-/// @}+ /// @}-/**- * @brief Provides an access to the underlying host memory- * @param type Optional type parameter.- * @note The method throws an exception- * if specified type's fundamental type does not match with tensor element type's fundamental type- * @return A host pointer to tensor memory- * @{- */-#ifndef IN_OV_COMPONENT- OPENVINO_DEPRECATED("This function will return const void* in 2026.0. Check if used correctly")-#endif- void* data(const element::Type& type) const;+ /**+ * @brief Provides an access to the underlying host memory+ * @param type Optional type parameter.+ * @note The method throws an exception+ * if specified type's fundamental type does not match with tensor element type's fundamental type+ * @return A host pointer to tensor memory+ * @{+ */+ const void* data(const element::Type& type) const;void* data(const element::Type& type);/// @}@@ -252,22 +245,14 @@ public:* @{*/template <typename T, typename datatype = std::decay_t<T>>-#ifndef IN_OV_COMPONENT- OPENVINO_DEPRECATED("This function will return const T* in 2026.0. Check if used correctly")-#endif- T* data() const {- OPENVINO_SUPPRESS_DEPRECATED_START // keep until 2026.0 release- return static_cast<T*>(data(element::from<datatype>()));- OPENVINO_SUPPRESS_DEPRECATED_END // keep until 2026.0 release+ const T* data() const {+ return static_cast<const T*>(data(element::from<datatype>()));}template <typename T, typename datatype = std::decay_t<T>>T* data() {if constexpr (std::is_const_v<T>) {- OPENVINO_SUPPRESS_DEPRECATED_START // keep until 2026.0 release- return std::as_const(*this)- .data<T>();- OPENVINO_SUPPRESS_DEPRECATED_END // keep until 2026.0 release+ return std::as_const(*this).data<T>();} else {return static_cast<T*>(data(element::from<datatype>()));}diff --git a/src/core/src/op/shape_of.cpp b/src/core/src/op/shape_of.cppindex 139c48be9b0..8a2f37bda8b 100644--- a/src/core/src/op/shape_of.cpp+++ b/src/core/src/op/shape_of.cpp@@ -75,16 +75,16 @@ bool evaluate_bound(const Node* const node, ov::TensorVector& outputs, const booconst auto get_val = is_upper ? &Interval::get_max_val : &Interval::get_min_val;auto limit_val = is_upper ? max_et_val : static_cast<decltype(max_et_val)>(0);- const TensorVector inputs{- {element::boolean, Shape{in_shape_rank}}, // mask- {out_et, Shape{}, &limit_val}, // limit- outputs[0] // output- };- auto& dynamic_mask = inputs[0];+ auto dynamic_mask = Tensor{element::boolean, Shape{in_shape_rank}};std::transform(in_shape.begin(), in_shape.end(), dynamic_mask.data<char>(), [&](const Dimension& d) {return static_cast<char>((d.get_interval().*get_val)() >= max_et_val);});+ const TensorVector inputs{+ dynamic_mask, // mask+ {out_et, Shape{}, &limit_val}, // limit+ outputs[0] // output+ };eval_status = v1::Select().evaluate(outputs, inputs);}return eval_status;diff --git a/src/core/src/runtime/tensor.cpp b/src/core/src/runtime/tensor.cppindex f5fb6cd5ba4..a172949dded 100644--- a/src/core/src/runtime/tensor.cpp+++ b/src/core/src/runtime/tensor.cpp@@ -109,16 +109,16 @@ void* Tensor::data() {OV_TENSOR_STATEMENT(return _impl->data());}-void* Tensor::data() const {- OV_TENSOR_STATEMENT(return const_cast<void*>(std::as_const(*_impl).data()););+const void* Tensor::data() const {+ OV_TENSOR_STATEMENT(return std::as_const(*_impl).data());}void* Tensor::data(const element::Type& element_type) {OV_TENSOR_STATEMENT(return _impl->data(element_type));}-void* Tensor::data(const element::Type& element_type) const {- OV_TENSOR_STATEMENT(return const_cast<void*>(std::as_const(*_impl).data(element_type)););+const void* Tensor::data(const element::Type& element_type) const {+ OV_TENSOR_STATEMENT(return std::as_const(*_impl).data(element_type));}bool Tensor::operator!() const noexcept {diff --git a/src/plugins/intel_cpu/src/plugin.cpp b/src/plugins/intel_cpu/src/plugin.cppindex 722b8f0ebd3..30f49a87404 100644--- a/src/plugins/intel_cpu/src/plugin.cpp+++ b/src/plugins/intel_cpu/src/plugin.cpp@@ -767,10 +767,11 @@ std::shared_ptr<ov::ICompiledModel> Plugin::import_model(const ov::Tensor& modelauto decrypt_from_string = get_cache_decrypt_fn(config, decrypt);const auto origin_weights_path = get_origin_weights_path(config);+ // `const_cast` intentionally used as AlignedBuffer requires non-const pointer+ // but is used as read-only in deserializer+ auto* model_data_ptr = reinterpret_cast<char*>(const_cast<void*>(model_tensor.data()));std::shared_ptr<ov::AlignedBuffer> model_buffer =- std::make_shared<ov::SharedBuffer<ov::Tensor>>(reinterpret_cast<char*>(model_tensor.data()),- model_tensor.get_byte_size(),- model_tensor);+ std::make_shared<ov::SharedBuffer<ov::Tensor>>(model_data_ptr, model_tensor.get_byte_size(), model_tensor);ModelDeserializer deserializer(model_buffer, get_core(), decrypt, decrypt_from_string, origin_weights_path);diff --git a/src/plugins/intel_npu/src/compiler_adapter/include/ze_graph_ext_wrappers.hpp b/src/plugins/intel_npu/src/compiler_adapter/include/ze_graph_ext_wrappers.hppindex 505c988e411..2cf92aef7cf 100644--- a/src/plugins/intel_npu/src/compiler_adapter/include/ze_graph_ext_wrappers.hpp+++ b/src/plugins/intel_npu/src/compiler_adapter/include/ze_graph_ext_wrappers.hpp@@ -37,7 +37,7 @@ public:const std::string& buildFlags,const bool bypassUmdCache = false) const;- GraphDescriptor getGraphDescriptor(void* data, size_t size) const;+ GraphDescriptor getGraphDescriptor(const void* data, size_t size) const;NetworkMetadata getNetworkMeta(GraphDescriptor& graphDescriptor) const;@@ -67,7 +67,7 @@ private:void initializeGraphThroughCommandList(ze_graph_handle_t graphHandle, uint32_t commandQueueGroupOrdinal) const;- bool canCpuVaBeImported(void* data, size_t size) const;+ bool canCpuVaBeImported(const void* data, size_t size) const;std::shared_ptr<ZeroInitStructsHolder> _zeroInitStruct;uint32_t _graphExtVersion;diff --git a/src/plugins/intel_npu/src/compiler_adapter/src/ze_graph_ext_wrappers.cpp b/src/plugins/intel_npu/src/compiler_adapter/src/ze_graph_ext_wrappers.cppindex a37ebff363b..1643bcbedd2 100644--- a/src/plugins/intel_npu/src/compiler_adapter/src/ze_graph_ext_wrappers.cpp+++ b/src/plugins/intel_npu/src/compiler_adapter/src/ze_graph_ext_wrappers.cpp@@ -312,7 +312,7 @@ std::unordered_set<std::string> ZeGraphExtWrappers::queryGraph(SerializedIR serireturn parseQueryResult(supportedLayers);}-bool ZeGraphExtWrappers::canCpuVaBeImported(void* data, size_t size) const {+bool ZeGraphExtWrappers::canCpuVaBeImported(const void* data, size_t size) const {if (_graphExtVersion < ZE_MAKE_VERSION(1, 13) ||!utils::memory_and_size_aligned_to_standard_page_size(data, size)) {return false;@@ -362,7 +362,7 @@ GraphDescriptor ZeGraphExtWrappers::getGraphDescriptor(SerializedIR serializedIRreturn GraphDescriptor{graphHandle};}-GraphDescriptor ZeGraphExtWrappers::getGraphDescriptor(void* blobData, size_t blobSize) const {+GraphDescriptor ZeGraphExtWrappers::getGraphDescriptor(const void* blobData, size_t blobSize) const {ze_graph_handle_t graphHandle = nullptr;if (blobSize == 0) {diff --git a/src/plugins/intel_npu/src/plugin/npuw/lazy_tensor.cpp b/src/plugins/intel_npu/src/plugin/npuw/lazy_tensor.cppindex f30ac6c42c4..d99232d9c4e 100644--- a/src/plugins/intel_npu/src/plugin/npuw/lazy_tensor.cpp+++ b/src/plugins/intel_npu/src/plugin/npuw/lazy_tensor.cpp@@ -406,7 +406,7 @@ std::size_t Gather::hash() const {auto ttype = t.get_element_type();NPUW_ASSERT(ttype == ov::element::f8e4m3 || ttype == ov::element::f8e5m2 || ttype == ov::element::f8e8m0);std::vector<uint8_t> t_data(t.get_size());- std::memcpy(t_data.data(), static_cast<uint8_t*>(t.data()), t.get_size());+ std::memcpy(t_data.data(), static_cast<const uint8_t*>(t.data()), t.get_size());seed ^= t_data.size();for (const auto& el : t_data) {seed ^= std::hash<uint8_t>()(el) + 0x9e3779b9;@@ -422,13 +422,13 @@ bool Gather::operator==(const Gather& other) const {auto ttype = t.get_element_type();NPUW_ASSERT(ttype == ov::element::f8e4m3 || ttype == ov::element::f8e5m2 || ttype == ov::element::f8e8m0);std::vector<uint8_t> t_data(t.get_size());- std::memcpy(t_data.data(), static_cast<uint8_t*>(t.data()), t.get_size());+ std::memcpy(t_data.data(), static_cast<const uint8_t*>(t.data()), t.get_size());auto ttype_other = other.t.get_element_type();NPUW_ASSERT(ttype_other == ov::element::f8e4m3 || ttype_other == ov::element::f8e5m2 ||ttype_other == ov::element::f8e8m0);std::vector<uint8_t> t_other_data(other.t.get_size());- std::memcpy(t_other_data.data(), static_cast<uint8_t*>(other.t.data()), other.t.get_size());+ std::memcpy(t_other_data.data(), static_cast<const uint8_t*>(other.t.data()), other.t.get_size());return (w == other.w && t.get_element_type() == other.t.get_element_type() &&t.get_shape() == other.t.get_shape() && t_data == t_other_data && dst_type == other.dst_type &&diff --git a/src/plugins/intel_npu/tests/unit/npuw/set_tensor.cpp b/src/plugins/intel_npu/tests/unit/npuw/set_tensor.cppindex 76e5b625af1..b7a88a46d7a 100644--- a/src/plugins/intel_npu/tests/unit/npuw/set_tensor.cpp+++ b/src/plugins/intel_npu/tests/unit/npuw/set_tensor.cpp@@ -64,7 +64,7 @@ TEST(SetTensorNPUW, RemoteTensorOutputJust) {auto output_tensor = request.get_tensor(compiled.outputs()[0]);auto check_non_zero = [](const ov::Tensor& t, size_t size) {- int64_t* tdata = t.data<int64_t>();+ const int64_t* tdata = t.data<const int64_t>();for (size_t i = 0; i < size; ++i) {if (tdata[i] == 0) {return false;@@ -72,7 +72,7 @@ TEST(SetTensorNPUW, RemoteTensorOutputJust) {}return true;};-+EXPECT_EQ(output_tensor.data(), output.data());EXPECT_TRUE(check_non_zero(output_tensor, total_elements));}diff --git a/src/plugins/intel_npu/tools/common/src/tensor_utils.cpp b/src/plugins/intel_npu/tools/common/src/tensor_utils.cppindex e71c197ee0e..ad88a65737e 100644--- a/src/plugins/intel_npu/tools/common/src/tensor_utils.cpp+++ b/src/plugins/intel_npu/tools/common/src/tensor_utils.cpp@@ -507,7 +507,7 @@ std::list<ov::Tensor> splitBatchedTensor(const ov::Tensor &tensor, const ov::Lay}pivotShape[ov::layout::batch_idx(layout)] /= parts;std::list<ov::Tensor> ret;- const auto *inputBuffer = static_cast<unsigned char*>(tensor.data());+ const auto* inputBuffer = static_cast<const unsigned char*>(tensor.data());for (size_t i = 0; i < parts; i ++) {ov::Tensor out(pivotPrecision, pivotShape);memcpy(out.data(), inputBuffer, out.get_byte_size());diff --git a/src/tests/functional/plugin/shared/src/single_op/multinomial.cpp b/src/tests/functional/plugin/shared/src/single_op/multinomial.cppindex 8314366ef10..c973e9006a2 100644--- a/src/tests/functional/plugin/shared/src/single_op/multinomial.cpp+++ b/src/tests/functional/plugin/shared/src/single_op/multinomial.cpp@@ -28,9 +28,9 @@ std::string MultinomialLayerTest::getTestCaseName(const testing::TestParamInfo<Mresult << test_type << separator;result << "probs_shape=" << probs.get_shape().to_string() << separator;if (num_samples.get_element_type() == ov::test::ElementType::i32) {- result << "num_samples=" << static_cast<int*>(num_samples.data())[0] << separator;+ result << "num_samples=" << static_cast<const int*>(num_samples.data())[0] << separator;} else { // i64- result << "num_samples=" << static_cast<long*>(num_samples.data())[0] << separator;+ result << "num_samples=" << static_cast<const long*>(num_samples.data())[0] << separator;}result << "inType=" << probs.get_element_type() << separator;result << "convert_type=" << convert_type << separator;