Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions onnxruntime/core/providers/openvino/ov_allocator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,10 @@ void* OVRTAllocator::Alloc(size_t size) {
ov::Tensor* tensor = new ov::Tensor(remote_ctx_.create_host_tensor(ov::element::Type_t::u8,
{size}));
std::lock_guard<std::mutex> lock(mutex_);
allocated_.insert({tensor->data(), tensor});
return reinterpret_cast<void*>(tensor->data());
// Use raw data() accessor for OV 2026.0 compatibility
void* ptr = const_cast<void*>(static_cast<const ov::Tensor&>(*tensor).data());
allocated_.insert({ptr, tensor});
return ptr;
} catch (const ov::Exception& e) {
ORT_THROW(std::string("Alloc failed: ") + e.what());
}
Expand Down
8 changes: 6 additions & 2 deletions onnxruntime/core/providers/openvino/ov_bin_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ static inline uint64_t AlignUp(uint64_t value, uint64_t alignment) {
class TensorStreamBuf : public std::streambuf {
public:
explicit TensorStreamBuf(ov::Tensor& tensor) {
char* data = const_cast<char*>(tensor.data<char>());
// Use raw data() accessor since memory-mapped tensors are read-only in OV 2026.0
// The templated data<T>() method is not allowed on read-only tensors
char* data = static_cast<char*>(const_cast<void*>(static_cast<const ov::Tensor&>(tensor).data()));
size_t size = tensor.get_byte_size();
setg(data, data, data + size);
}
Expand Down Expand Up @@ -170,10 +172,12 @@ ov::Tensor BinManager::GetNativeBlob(const std::string& blob_name) {

if (mapped_bin_) {
// Create a tensor from memory-mapped external file
// Use raw data() accessor since memory-mapped tensors are read-only in OV 2026.0
// The templated data<T>() method is not allowed on read-only tensors
blob_container.tensor = ov::Tensor(
ov::element::u8,
ov::Shape{blob_container.serialized_info.size},
mapped_bin_.data<uint8_t>() + blob_container.serialized_info.file_offset);
static_cast<uint8_t*>(const_cast<void*>(static_cast<const ov::Tensor&>(mapped_bin_).data())) + blob_container.serialized_info.file_offset);
} else {
// Create a tensor from embedded data vector
blob_container.tensor = ov::Tensor(
Expand Down
10 changes: 8 additions & 2 deletions onnxruntime/core/providers/openvino/ov_shared_context.cc
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,9 @@ void* SharedContext::WeightsFile::TryGetOrCreateDeviceMapping(std::optional<ov::
} else if (dev_name.empty()) {
// CPU/virtual device case, create a CPU tensor memory mapped from file
auto&& mmaped_tensor = ov::read_tensor_data(file_path_);
it->second = MappingContainer{.ptr_ = mmaped_tensor.data(), .tensor_ = mmaped_tensor};
// Use raw data() accessor since memory-mapped tensors are read-only in OV 2026.0
// The templated data<T>() method is not allowed on read-only tensors
it->second = MappingContainer{.ptr_ = const_cast<void*>(static_cast<const ov::Tensor&>(mmaped_tensor).data()), .tensor_ = mmaped_tensor};
}
}

Expand Down Expand Up @@ -85,7 +87,11 @@ void SharedContext::LoadTensorFromFile(
// Can't mmap the file to device tensor, create a host tensor and copy the data
tensor = remote_context->create_host_tensor(element_type, dimensions);
ORT_ENFORCE(tensor.get_byte_size() == value.serialized.size, "Remote tensor size mismatch");
weights_file->LoadWeights(value.serialized.data_offset, tensor.data(), value.serialized.size);
// Use raw data() accessor for sub-byte types (i4, u4) compatibility in OV 2026.0
// The templated data<T>() method fails is_pointer_representable check for sub-byte types
weights_file->LoadWeights(value.serialized.data_offset,
const_cast<void*>(static_cast<const ov::Tensor&>(tensor).data()),
value.serialized.size);
}

ORT_ENFORCE(tensor.get_byte_size() == value.serialized.size, "Tensor size mismatch");
Expand Down
Loading