Skip to content

Commit

Permalink
[C API] fix element type mismatch issue (openvinotoolkit#24608)
Browse files Browse the repository at this point in the history
### Details:
 - *item1*
 - *...*

### Tickets:
 - *ticket-id*
  • Loading branch information
riverlijunjie authored May 22, 2024
1 parent 09c05f1 commit 0d95325
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 4 deletions.
12 changes: 12 additions & 0 deletions src/bindings/c/docs/api_overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,14 @@ typedef enum {
U1, //!< binary element type
U2, //!< u2 element type
U3, //!< u3 element type
U4, //!< u4 element type
U6, //!< u6 element type
U8, //!< u8 element type
U16, //!< u16 element type
Expand All @@ -193,6 +199,12 @@ typedef enum {
NF4, //!< nf4 element type
F8E4M3, //!< f8e4m3 element type
F8E5M3, //!< f8e5m2 element type
STRING, //!< string element type
} ov_element_type_e;
```

Expand Down
7 changes: 6 additions & 1 deletion src/bindings/c/include/openvino/c/ov_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,8 @@ typedef enum {
/**
* @enum ov_element_type_e
* @ingroup ov_base_c_api
* @brief This enum contains codes for element type.
* @brief This enum contains codes for element type, which is aligned with ov::element::Type_t in
* src/core/include/openvino/core/type/element_type.hpp
*/
typedef enum {
UNDEFINED = 0U, //!< Undefined element type
Expand All @@ -181,14 +182,18 @@ typedef enum {
I32, //!< i32 element type
I64, //!< i64 element type
U1, //!< binary element type
U2, //!< u2 element type
U3, //!< u3 element type
U4, //!< u4 element type
U6, //!< u6 element type
U8, //!< u8 element type
U16, //!< u16 element type
U32, //!< u32 element type
U64, //!< u64 element type
NF4, //!< nf4 element type
F8E4M3, //!< f8e4m3 element type
F8E5M3, //!< f8e5m2 element type
STRING, //!< string element type
} ov_element_type_e;

/**
Expand Down
1 change: 1 addition & 0 deletions src/bindings/c/src/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -209,5 +209,6 @@ struct mem_istream : virtual mem_stringbuf, std::istream {
};

char* str_to_char_array(const std::string& str);
ov_element_type_e find_ov_element_type_e(ov::element::Type type);
ov::element::Type get_element_type(ov_element_type_e type);
void dup_last_err_msg(const char* msg);
2 changes: 1 addition & 1 deletion src/bindings/c/src/ov_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ ov_status_e ov_port_get_element_type(const ov_output_const_port_t* port, ov_elem

try {
auto type = (ov::element::Type_t)port->object->get_element_type();
*tensor_type = (ov_element_type_e)type;
*tensor_type = find_ov_element_type_e(type);
}
CATCH_OV_EXCEPTIONS

Expand Down
8 changes: 6 additions & 2 deletions src/bindings/c/src/ov_tensor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,20 @@ const std::map<ov_element_type_e, ov::element::Type> element_type_map = {
{ov_element_type_e::I32, ov::element::i32},
{ov_element_type_e::I64, ov::element::i64},
{ov_element_type_e::U1, ov::element::u1},
{ov_element_type_e::U2, ov::element::u2},
{ov_element_type_e::U3, ov::element::u3},
{ov_element_type_e::U4, ov::element::u4},
{ov_element_type_e::U6, ov::element::u6},
{ov_element_type_e::U8, ov::element::u8},
{ov_element_type_e::U16, ov::element::u16},
{ov_element_type_e::U32, ov::element::u32},
{ov_element_type_e::U64, ov::element::u64},
{ov_element_type_e::NF4, ov::element::nf4},
{ov_element_type_e::F8E4M3, ov::element::f8e4m3},
{ov_element_type_e::F8E5M3, ov::element::f8e5m2}};
{ov_element_type_e::F8E5M3, ov::element::f8e5m2},
{ov_element_type_e::STRING, ov::element::string}};

inline ov_element_type_e find_ov_element_type_e(ov::element::Type type) {
ov_element_type_e find_ov_element_type_e(ov::element::Type type) {
for (auto iter = element_type_map.begin(); iter != element_type_map.end(); iter++) {
if (iter->second == type) {
return iter->first;
Expand Down

0 comments on commit 0d95325

Please sign in to comment.