Skip to content

Commit 8d36ad2

Browse files
Allow zero-element tensors to get set (#737)
1 parent f89f64e commit 8d36ad2

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

onnxruntime/core/providers/openvino/ov_interface.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,22 @@ class OVInferRequest {
133133
auto tensor_ptr = std::make_shared<ov::Tensor>(type, shape, const_cast<void*>(ort_ptr));
134134
SetTensor(name, tensor_ptr);
135135
cached_binding = {tensor_ptr, ort_ptr};
136+
} else if (ort_ptr==nullptr) {
137+
// a null ort_ptr is expected for a tensor that has 0 elements.
138+
// for example, a tensor of shape=[1, 8, 0, 64], which is valid.
139+
// So, we check to see if at least one shape entry is 0.
140+
auto contains_zero = [](const ov::Shape& shape) {
141+
for (auto& s : shape)
142+
if (s == 0) return true;
143+
return false;
144+
};
145+
if (contains_zero(shape)) {
146+
// if there are zero elements (i.e. at least one shape entry is 0),
147+
// then create and set the tensor anyway.
148+
auto tensor_ptr = std::make_shared<ov::Tensor>(type, shape);
149+
SetTensor(name, tensor_ptr);
150+
cached_binding = {tensor_ptr, ort_ptr};
151+
}
136152
}
137153
}
138154

0 commit comments

Comments
 (0)