forked from openvinotoolkit/openvino
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ov_node.cpp
105 lines (86 loc) · 2.97 KB
/
ov_node.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
// Copyright (C) 2018-2024 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//
#include "openvino/c/ov_node.h"
#include "common.h"
ov_status_e ov_const_port_get_shape(const ov_output_const_port_t* port, ov_shape_t* tensor_shape) {
if (!port || !tensor_shape) {
return ov_status_e::INVALID_C_PARAM;
}
try {
auto shape = port->object->get_shape();
ov_shape_create(shape.size(), nullptr, tensor_shape);
std::copy_n(shape.begin(), shape.size(), tensor_shape->dims);
}
CATCH_OV_EXCEPTIONS
return ov_status_e::OK;
}
ov_status_e ov_port_get_shape(const ov_output_port_t* port, ov_shape_t* tensor_shape) {
if (!port || !tensor_shape) {
return ov_status_e::INVALID_C_PARAM;
}
try {
auto shape = port->object->get_shape();
ov_shape_create(shape.size(), nullptr, tensor_shape);
std::copy_n(shape.begin(), shape.size(), tensor_shape->dims);
}
CATCH_OV_EXCEPTIONS
return ov_status_e::OK;
}
ov_status_e ov_port_get_any_name(const ov_output_const_port_t* port, char** tensor_name) {
if (!port || !tensor_name) {
return ov_status_e::INVALID_C_PARAM;
}
try {
*tensor_name = str_to_char_array(port->object->get_any_name());
}
CATCH_OV_EXCEPTIONS
return ov_status_e::OK;
}
ov_status_e ov_port_get_partial_shape(const ov_output_const_port_t* port, ov_partial_shape_t* partial_shape) {
if (!port || !partial_shape) {
return ov_status_e::INVALID_C_PARAM;
}
try {
auto pshape = port->object->get_partial_shape();
auto rank = pshape.rank();
partial_shape->rank.min = rank.get_min_length();
partial_shape->rank.max = rank.get_max_length();
if (rank.is_dynamic()) {
partial_shape->dims = nullptr;
} else {
auto size = rank.get_length();
if (static_cast<size_t>(size) != pshape.size()) {
return ov_status_e::PARAMETER_MISMATCH;
}
std::unique_ptr<ov_dimension_t> _dimensions(new ov_dimension_t[size]);
partial_shape->dims = _dimensions.release();
auto iter = pshape.begin();
for (auto i = 0; iter != pshape.end(); iter++, i++) {
partial_shape->dims[i].min = iter->get_min_length();
partial_shape->dims[i].max = iter->get_max_length();
}
}
}
CATCH_OV_EXCEPTIONS
return ov_status_e::OK;
}
ov_status_e ov_port_get_element_type(const ov_output_const_port_t* port, ov_element_type_e* tensor_type) {
if (!port) {
return ov_status_e::INVALID_C_PARAM;
}
try {
auto type = (ov::element::Type_t)port->object->get_element_type();
*tensor_type = find_ov_element_type_e(type);
}
CATCH_OV_EXCEPTIONS
return ov_status_e::OK;
}
void ov_output_port_free(ov_output_port_t* port) {
if (port)
delete port;
}
void ov_output_const_port_free(ov_output_const_port_t* port) {
if (port)
delete port;
}