ONE - On-device Neural Engine
Loading...
Searching...
No Matches
nnfw_api_wrapper.cc File Reference
#include "nnfw_api_wrapper.h"
#include <iostream>

Go to the source code of this file.

Functions

void ensure_status (NNFW_STATUS status)
 Handle errors with NNFW_STATUS in API functions.
 
NNFW_LAYOUT getLayout (const char *layout)
 
NNFW_TYPE getType (const char *type)
 
const char * getStringType (NNFW_TYPE type)
 
uint64_t num_elems (const nnfw_tensorinfo *tensor_info)
 Get the total number of elements in nnfw_tensorinfo->dims.
 
py::list get_dims (const tensorinfo &tensor_info)
 Get nnfw_tensorinfo->dims.
 
void set_dims (tensorinfo &tensor_info, const py::list &array)
 Set nnfw_tensorinfo->dims.
 

Function Documentation

◆ ensure_status()

void ensure_status ( NNFW_STATUS  status)

Handle errors with NNFW_STATUS in API functions.

This only handles NNFW_STATUS errors.

Parameters
[in]statusThe status returned by API functions

Definition at line 21 of file nnfw_api_wrapper.cc.

22{
23 switch (status)
24 {
26 break;
28 std::cout << "[ERROR]\tNNFW_STATUS_ERROR\n";
29 exit(1);
31 std::cout << "[ERROR]\tNNFW_STATUS_UNEXPECTED_NULL\n";
32 exit(1);
34 std::cout << "[ERROR]\tNNFW_STATUS_INVALID_STATE\n";
35 exit(1);
37 std::cout << "[ERROR]\tNNFW_STATUS_OUT_OF_MEMORY\n";
38 exit(1);
40 std::cout << "[ERROR]\tNNFW_STATUS_INSUFFICIENT_OUTPUT_SIZE\n";
41 exit(1);
43 std::cout << "[ERROR]\tNNFW_STATUS_DEPRECATED_API\n";
44 exit(1);
45 }
46}
@ NNFW_STATUS_INVALID_STATE
Definition onert-micro.h:97
@ NNFW_STATUS_UNEXPECTED_NULL
Definition onert-micro.h:95
@ NNFW_STATUS_NO_ERROR
Definition onert-micro.h:88
@ NNFW_STATUS_DEPRECATED_API
@ NNFW_STATUS_INSUFFICIENT_OUTPUT_SIZE
@ NNFW_STATUS_ERROR
Definition onert-micro.h:93
@ NNFW_STATUS_OUT_OF_MEMORY
Definition onert-micro.h:99

References NNFW_STATUS_DEPRECATED_API, NNFW_STATUS_ERROR, NNFW_STATUS_INSUFFICIENT_OUTPUT_SIZE, NNFW_STATUS_INVALID_STATE, NNFW_STATUS_NO_ERROR, NNFW_STATUS_OUT_OF_MEMORY, and NNFW_STATUS_UNEXPECTED_NULL.

Referenced by NNFW_SESSION::close_session(), NNFW_SESSION::input_size(), NNFW_SESSION::input_tensorinfo(), NNFW_SESSION::NNFW_SESSION(), NNFW_SESSION::output_size(), NNFW_SESSION::output_tensorinfo(), NNFW_SESSION::run(), NNFW_SESSION::run_async(), NNFW_SESSION::set_input(), NNFW_SESSION::set_input_layout(), NNFW_SESSION::set_input_tensorinfo(), NNFW_SESSION::set_output(), NNFW_SESSION::set_output_layout(), and NNFW_SESSION::wait().

◆ get_dims()

py::list get_dims ( const tensorinfo tensor_info)

Get nnfw_tensorinfo->dims.

This function is called to get dimension array of tensorinfo.

Parameters
[in]tensor_infoTensor info (shape, type, etc)
Returns
python list of dims

Definition at line 142 of file nnfw_api_wrapper.cc.

143{
144 py::list dims_list;
145 for (int32_t i = 0; i < tensor_info.rank; ++i)
146 {
147 dims_list.append(tensor_info.dims[i]);
148 }
149 return dims_list;
150}
int32_t dims[NNFW_MAX_RANK]

References tensorinfo::dims, and tensorinfo::rank.

Referenced by PYBIND11_MODULE().

◆ getLayout()

NNFW_LAYOUT getLayout ( const char *  layout = "")

Convert the layout with string to NNFW_LAYOUT

Parameters
[in]layoutlayout to be converted
Returns
proper layout if exists

Definition at line 48 of file nnfw_api_wrapper.cc.

49{
50 if (!strcmp(layout, "NCHW"))
51 {
53 }
54 else if (!strcmp(layout, "NHWC"))
55 {
57 }
58 else if (!strcmp(layout, "NONE"))
59 {
61 }
62 else
63 {
64 std::cout << "[ERROR]\tLAYOUT_TYPE\n";
65 exit(1);
66 }
67}
@ NNFW_LAYOUT_CHANNELS_LAST
Definition nnfw.h:141
@ NNFW_LAYOUT_CHANNELS_FIRST
Definition nnfw.h:146
@ NNFW_LAYOUT_NONE
Definition nnfw.h:136

References NNFW_LAYOUT_CHANNELS_FIRST, NNFW_LAYOUT_CHANNELS_LAST, and NNFW_LAYOUT_NONE.

Referenced by NNFW_SESSION::set_input_layout(), and NNFW_SESSION::set_output_layout().

◆ getStringType()

const char * getStringType ( NNFW_TYPE  type)

Convert the type with NNFW_TYPE to string

Parameters
[in]typetype to be converted
Returns
proper type

Definition at line 107 of file nnfw_api_wrapper.cc.

108{
109 switch (type)
110 {
112 return "float32";
114 return "int32";
115 case NNFW_TYPE::NNFW_TYPE_TENSOR_QUANT8_ASYMM:
116 case NNFW_TYPE::NNFW_TYPE_TENSOR_UINT8:
117 return "uint8";
118 case NNFW_TYPE::NNFW_TYPE_TENSOR_BOOL:
119 return "bool";
120 case NNFW_TYPE::NNFW_TYPE_TENSOR_INT64:
121 return "int64";
122 case NNFW_TYPE::NNFW_TYPE_TENSOR_QUANT8_ASYMM_SIGNED:
123 return "int8";
124 case NNFW_TYPE::NNFW_TYPE_TENSOR_QUANT16_SYMM_SIGNED:
125 return "int16";
126 default:
127 std::cout << "[ERROR] NNFW_TYPE to String Failure\n";
128 exit(1);
129 }
130}
@ NNFW_TYPE_TENSOR_INT32
Definition onert-micro.h:79
@ NNFW_TYPE_TENSOR_FLOAT32
Definition onert-micro.h:77

References NNFW_TYPE_TENSOR_FLOAT32, and NNFW_TYPE_TENSOR_INT32.

Referenced by NNFW_SESSION::input_tensorinfo(), and NNFW_SESSION::output_tensorinfo().

◆ getType()

NNFW_TYPE getType ( const char *  type = "")

Convert the type with string to NNFW_TYPE

Parameters
[in]typetype to be converted
Returns
proper type if exists

Definition at line 69 of file nnfw_api_wrapper.cc.

70{
71 if (!strcmp(type, "float32"))
72 {
74 }
75 else if (!strcmp(type, "int32"))
76 {
78 }
79 else if (!strcmp(type, "uint8"))
80 {
81 return NNFW_TYPE::NNFW_TYPE_TENSOR_UINT8;
82 // return NNFW_TYPE::NNFW_TYPE_TENSOR_QUANT8_ASYMM;
83 }
84 else if (!strcmp(type, "bool"))
85 {
86 return NNFW_TYPE::NNFW_TYPE_TENSOR_BOOL;
87 }
88 else if (!strcmp(type, "int64"))
89 {
90 return NNFW_TYPE::NNFW_TYPE_TENSOR_INT64;
91 }
92 else if (!strcmp(type, "int8"))
93 {
94 return NNFW_TYPE::NNFW_TYPE_TENSOR_QUANT8_ASYMM_SIGNED;
95 }
96 else if (!strcmp(type, "int16"))
97 {
98 return NNFW_TYPE::NNFW_TYPE_TENSOR_QUANT16_SYMM_SIGNED;
99 }
100 else
101 {
102 std::cout << "[ERROR] String to NNFW_TYPE Failure\n";
103 exit(1);
104 }
105}

References NNFW_TYPE_TENSOR_FLOAT32, and NNFW_TYPE_TENSOR_INT32.

Referenced by mir_onnx::convertExpandV8(), mir::Operation::Output::getElementType(), mir::Operation::Output::getShape(), and NNFW_SESSION::set_input_tensorinfo().

◆ num_elems()

uint64_t num_elems ( const nnfw_tensorinfo tensor_info)

Get the total number of elements in nnfw_tensorinfo->dims.

This function is called to set the size of the input, output array.

Parameters
[in]tensor_infoTensor info (shape, type, etc)
Returns
total number of elements

Definition at line 132 of file nnfw_api_wrapper.cc.

133{
134 uint64_t n = 1;
135 for (int32_t i = 0; i < tensor_info->rank; ++i)
136 {
137 n *= tensor_info->dims[i];
138 }
139 return n;
140}
int32_t dims[NNFW_MAX_RANK]

◆ set_dims()

void set_dims ( tensorinfo tensor_info,
const py::list &  array 
)

Set nnfw_tensorinfo->dims.

This function is called to set dimension array of tensorinfo.

Parameters
[in]tensor_infoTensor info (shape, type, etc)
[in]arrayarray to set dimension

Definition at line 152 of file nnfw_api_wrapper.cc.

153{
154 tensor_info.rank = py::len(array);
155 for (int32_t i = 0; i < tensor_info.rank; ++i)
156 {
157 tensor_info.dims[i] = py::cast<int32_t>(array[i]);
158 }
159}

References tensorinfo::dims, and tensorinfo::rank.

Referenced by PYBIND11_MODULE().