ONE - On-device Neural Engine
Loading...
Searching...
No Matches
onert::api::python Namespace Reference

Data Structures

class  NNFW_SESSION
 
struct  tensorinfo
 tensor info describes the type and shape of tensors More...
 

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.
 
void bind_nnfw_session (pybind11::module_ &m)
 
void bind_experimental_nnfw_session (pybind11::module_ &m)
 
void bind_tensorinfo (pybind11::module_ &m)
 
void bind_nnfw_session (py::module_ &m)
 
void bind_experimental_nnfw_session (py::module_ &m)
 
void bind_tensorinfo (py::module_ &m)
 

Function Documentation

◆ bind_experimental_nnfw_session() [1/2]

void onert::api::python::bind_experimental_nnfw_session ( py::module_ &  m)

Definition at line 229 of file nnfw_session_bindings.cc.

230{
231 // Add experimental APIs for the `NNFW_SESSION` class
232 m.attr("nnfw_session")
233 .cast<py::class_<NNFW_SESSION>>()
234 .def("train_get_traininfo", &NNFW_SESSION::train_get_traininfo,
235 "Retrieve training information for the model.")
236 .def("train_set_traininfo", &NNFW_SESSION::train_set_traininfo, py::arg("info"),
237 "Set training information for the model.")
238 .def("train_prepare", &NNFW_SESSION::train_prepare, "Prepare for training")
239 .def("train", &NNFW_SESSION::train, py::arg("update_weights") = true,
240 "Run a training step, optionally updating weights.")
241 .def("train_get_loss", &NNFW_SESSION::train_get_loss, py::arg("index"),
242 "Retrieve the training loss for a specific index.")
243 .def("train_set_input", &NNFW_SESSION::train_set_input<float>, py::arg("index"),
244 py::arg("buffer"), "Set training input tensor for the given index (float).")
245 .def("train_set_input", &NNFW_SESSION::train_set_input<int>, py::arg("index"),
246 py::arg("buffer"), "Set training input tensor for the given index (int).")
247 .def("train_set_input", &NNFW_SESSION::train_set_input<uint8_t>, py::arg("index"),
248 py::arg("buffer"), "Set training input tensor for the given index (uint8).")
249 .def("train_set_expected", &NNFW_SESSION::train_set_expected<float>, py::arg("index"),
250 py::arg("buffer"), "Set expected output tensor for the given index (float).")
251 .def("train_set_expected", &NNFW_SESSION::train_set_expected<int>, py::arg("index"),
252 py::arg("buffer"), "Set expected output tensor for the given index (int).")
253 .def("train_set_expected", &NNFW_SESSION::train_set_expected<uint8_t>, py::arg("index"),
254 py::arg("buffer"), "Set expected output tensor for the given index (uint8).")
255 .def("train_set_output", &NNFW_SESSION::train_set_output<float>, py::arg("index"),
256 py::arg("buffer"), "Set output tensor for the given index (float).")
257 .def("train_set_output", &NNFW_SESSION::train_set_output<int>, py::arg("index"),
258 py::arg("buffer"), "Set output tensor for the given index (int).")
259 .def("train_set_output", &NNFW_SESSION::train_set_output<uint8_t>, py::arg("index"),
260 py::arg("buffer"), "Set output tensor for the given index (uint8).")
261 .def("train_export_circle", &NNFW_SESSION::train_export_circle, py::arg("path"),
262 "Export the trained model to a circle file.")
263 .def("train_import_checkpoint", &NNFW_SESSION::train_import_checkpoint, py::arg("path"),
264 "Import a training checkpoint from a file.")
265 .def("train_export_checkpoint", &NNFW_SESSION::train_export_checkpoint, py::arg("path"),
266 "Export the training checkpoint to a file.");
267}

References m, onert::api::python::NNFW_SESSION::train(), onert::api::python::NNFW_SESSION::train_export_checkpoint(), onert::api::python::NNFW_SESSION::train_export_circle(), onert::api::python::NNFW_SESSION::train_get_loss(), onert::api::python::NNFW_SESSION::train_get_traininfo(), onert::api::python::NNFW_SESSION::train_import_checkpoint(), onert::api::python::NNFW_SESSION::train_prepare(), and onert::api::python::NNFW_SESSION::train_set_traininfo().

◆ bind_experimental_nnfw_session() [2/2]

void onert::api::python::bind_experimental_nnfw_session ( pybind11::module_ &  m)

Referenced by PYBIND11_MODULE().

◆ bind_nnfw_session() [1/2]

void onert::api::python::bind_nnfw_session ( py::module_ &  m)

Definition at line 31 of file nnfw_session_bindings.cc.

32{
33 py::class_<NNFW_SESSION>(m, "nnfw_session", py::module_local())
34 .def(
35 py::init<const char *, const char *>(), py::arg("package_file_path"), py::arg("backends"),
36 "Create a new session instance, load model from nnpackage file or directory, "
37 "set available backends and prepare session to be ready for inference\n"
38 "Parameters:\n"
39 "\tpackage_file_path (str): Path to the nnpackage file or unzipped directory to be loaded\n"
40 "\tbackends (str): Available backends on which nnfw uses\n"
41 "\t\tMultiple backends can be set and they must be separated by a semicolon "
42 "(ex: \"acl_cl;cpu\")\n"
43 "\t\tAmong the multiple backends, the 1st element is used as the default backend.")
44 .def("set_input_tensorinfo", &NNFW_SESSION::set_input_tensorinfo, py::arg("index"),
45 py::arg("tensor_info"),
46 "Set input model's tensor info for resizing.\n"
47 "Parameters:\n"
48 "\tindex (int): Index of input to be set (0-indexed)\n"
49 "\ttensor_info (tensorinfo): Tensor info to be set")
50 .def("prepare", &NNFW_SESSION::prepare, "Prepare for inference")
51 .def("run", &NNFW_SESSION::run, "Run inference")
52 .def("run_async", &NNFW_SESSION::run_async, "Run inference asynchronously")
53 .def("wait", &NNFW_SESSION::wait, "Wait for asynchronous run to finish")
54 .def(
55 "set_input",
56 [](NNFW_SESSION &session, uint32_t index, py::array_t<float> &buffer) {
57 session.set_input<float>(index, buffer);
58 },
59 py::arg("index"), py::arg("buffer"),
60 "Set input buffer\n"
61 "Parameters:\n"
62 "\tindex (int): Index of input to be set (0-indexed)\n"
63 "\tbuffer (numpy): Raw buffer for input")
64 .def(
65 "set_input",
66 [](NNFW_SESSION &session, uint32_t index, py::array_t<int> &buffer) {
67 session.set_input<int>(index, buffer);
68 },
69 py::arg("index"), py::arg("buffer"),
70 "Set input buffer\n"
71 "Parameters:\n"
72 "\tindex (int): Index of input to be set (0-indexed)\n"
73 "\tbuffer (numpy): Raw buffer for input")
74 .def(
75 "set_input",
76 [](NNFW_SESSION &session, uint32_t index, py::array_t<uint8_t> &buffer) {
77 session.set_input<uint8_t>(index, buffer);
78 },
79 py::arg("index"), py::arg("buffer"),
80 "Set input buffer\n"
81 "Parameters:\n"
82 "\tindex (int): Index of input to be set (0-indexed)\n"
83 "\tbuffer (numpy): Raw buffer for input")
84 .def(
85 "set_input",
86 [](NNFW_SESSION &session, uint32_t index, py::array_t<bool> &buffer) {
87 session.set_input<bool>(index, buffer);
88 },
89 py::arg("index"), py::arg("buffer"),
90 "Set input buffer\n"
91 "Parameters:\n"
92 "\tindex (int): Index of input to be set (0-indexed)\n"
93 "\tbuffer (numpy): Raw buffer for input")
94 .def(
95 "set_input",
96 [](NNFW_SESSION &session, uint32_t index, py::array_t<int64_t> &buffer) {
97 session.set_input<int64_t>(index, buffer);
98 },
99 py::arg("index"), py::arg("buffer"),
100 "Set input buffer\n"
101 "Parameters:\n"
102 "\tindex (int): Index of input to be set (0-indexed)\n"
103 "\tbuffer (numpy): Raw buffer for input")
104 .def(
105 "set_input",
106 [](NNFW_SESSION &session, uint32_t index, py::array_t<int8_t> &buffer) {
107 session.set_input<int8_t>(index, buffer);
108 },
109 py::arg("index"), py::arg("buffer"),
110 "Set input buffer\n"
111 "Parameters:\n"
112 "\tindex (int): Index of input to be set (0-indexed)\n"
113 "\tbuffer (numpy): Raw buffer for input")
114 .def(
115 "set_input",
116 [](NNFW_SESSION &session, uint32_t index, py::array_t<int16_t> &buffer) {
117 session.set_input<int16_t>(index, buffer);
118 },
119 py::arg("index"), py::arg("buffer"),
120 "Set input buffer\n"
121 "Parameters:\n"
122 "\tindex (int): Index of input to be set (0-indexed)\n"
123 "\tbuffer (numpy): Raw buffer for input")
124 .def(
125 "set_output",
126 [](NNFW_SESSION &session, uint32_t index, py::array_t<float> &buffer) {
127 session.set_output<float>(index, buffer);
128 },
129 py::arg("index"), py::arg("buffer"),
130 "Set output buffer\n"
131 "Parameters:\n"
132 "\tindex (int): Index of output to be set (0-indexed)\n"
133 "\tbuffer (numpy): Raw buffer for output")
134 .def(
135 "set_output",
136 [](NNFW_SESSION &session, uint32_t index, py::array_t<int> &buffer) {
137 session.set_output<int>(index, buffer);
138 },
139 py::arg("index"), py::arg("buffer"),
140 "Set output buffer\n"
141 "Parameters:\n"
142 "\tindex (int): Index of output to be set (0-indexed)\n"
143 "\tbuffer (numpy): Raw buffer for output")
144 .def(
145 "set_output",
146 [](NNFW_SESSION &session, uint32_t index, py::array_t<uint8_t> &buffer) {
147 session.set_output<uint8_t>(index, buffer);
148 },
149 py::arg("index"), py::arg("buffer"),
150 "Set output buffer\n"
151 "Parameters:\n"
152 "\tindex (int): Index of output to be set (0-indexed)\n"
153 "\tbuffer (numpy): Raw buffer for output")
154 .def(
155 "set_output",
156 [](NNFW_SESSION &session, uint32_t index, py::array_t<bool> &buffer) {
157 session.set_output<bool>(index, buffer);
158 },
159 py::arg("index"), py::arg("buffer"),
160 "Set output buffer\n"
161 "Parameters:\n"
162 "\tindex (int): Index of output to be set (0-indexed)\n"
163 "\tbuffer (numpy): Raw buffer for output")
164 .def(
165 "set_output",
166 [](NNFW_SESSION &session, uint32_t index, py::array_t<int64_t> &buffer) {
167 session.set_output<int64_t>(index, buffer);
168 },
169 py::arg("index"), py::arg("buffer"),
170 "Set output buffer\n"
171 "Parameters:\n"
172 "\tindex (int): Index of output to be set (0-indexed)\n"
173 "\tbuffer (numpy): Raw buffer for output")
174 .def(
175 "set_output",
176 [](NNFW_SESSION &session, uint32_t index, py::array_t<int8_t> &buffer) {
177 session.set_output<int8_t>(index, buffer);
178 },
179 py::arg("index"), py::arg("buffer"),
180 "Set output buffer\n"
181 "Parameters:\n"
182 "\tindex (int): Index of output to be set (0-indexed)\n"
183 "\tbuffer (numpy): Raw buffer for output")
184 .def(
185 "set_output",
186 [](NNFW_SESSION &session, uint32_t index, py::array_t<int16_t> &buffer) {
187 session.set_output<int16_t>(index, buffer);
188 },
189 py::arg("index"), py::arg("buffer"),
190 "Set output buffer\n"
191 "Parameters:\n"
192 "\tindex (int): Index of output to be set (0-indexed)\n"
193 "\tbuffer (numpy): Raw buffer for output")
194 .def("input_size", &NNFW_SESSION::input_size,
195 "Get the number of inputs defined in loaded model\n"
196 "Returns:\n"
197 "\tint: The number of inputs")
198 .def("output_size", &NNFW_SESSION::output_size,
199 "Get the number of outputs defined in loaded model\n"
200 "Returns:\n"
201 "\tint: The number of outputs")
202 .def("set_input_layout", &NNFW_SESSION::set_input_layout, py::arg("index"),
203 py::arg("layout") = "NONE",
204 "Set the layout of an input\n"
205 "Parameters:\n"
206 "\tindex (int): Index of input to be set (0-indexed)\n"
207 "\tlayout (str): Layout to set to target input")
208 .def("set_output_layout", &NNFW_SESSION::set_output_layout, py::arg("index"),
209 py::arg("layout") = "NONE",
210 "Set the layout of an output\n"
211 "Parameters:\n"
212 "\tindex (int): Index of output to be set (0-indexed)\n"
213 "\tlayout (str): Layout to set to target output")
214 .def("input_tensorinfo", &NNFW_SESSION::input_tensorinfo, py::arg("index"),
215 "Get i-th input tensor info\n"
216 "Parameters:\n"
217 "\tindex (int): Index of input\n"
218 "Returns:\n"
219 "\ttensorinfo: Tensor info (shape, type, etc)")
220 .def("output_tensorinfo", &NNFW_SESSION::output_tensorinfo, py::arg("index"),
221 "Get i-th output tensor info\n"
222 "Parameters:\n"
223 "\tindex (int): Index of output\n"
224 "Returns:\n"
225 "\ttensorinfo: Tensor info (shape, type, etc)");
226}
SessionID session(const coco::Module *m)
Definition Session.cpp:48
loco::GraphInputIndex index(const TFPlaceholder *node)
Definition TFNode.cpp:54

References onert::api::python::NNFW_SESSION::input_size(), onert::api::python::NNFW_SESSION::input_tensorinfo(), m, onert::api::python::NNFW_SESSION::output_size(), onert::api::python::NNFW_SESSION::output_tensorinfo(), onert::api::python::NNFW_SESSION::prepare(), onert::api::python::NNFW_SESSION::run(), onert::api::python::NNFW_SESSION::run_async(), onert::api::python::NNFW_SESSION::set_input_layout(), onert::api::python::NNFW_SESSION::set_input_tensorinfo(), onert::api::python::NNFW_SESSION::set_output_layout(), and onert::api::python::NNFW_SESSION::wait().

◆ bind_nnfw_session() [2/2]

void onert::api::python::bind_nnfw_session ( pybind11::module_ &  m)

Referenced by PYBIND11_MODULE().

◆ bind_tensorinfo() [1/2]

void onert::api::python::bind_tensorinfo ( py::module_ &  m)

Definition at line 31 of file nnfw_tensorinfo_bindings.cc.

32{
33 py::class_<tensorinfo>(m, "tensorinfo", "tensorinfo describes the type and shape of tensors",
34 py::module_local())
35 .def(py::init<>(), "The constructor of tensorinfo")
36 .def_readwrite("dtype", &tensorinfo::dtype, "The data type")
37 .def_readwrite("rank", &tensorinfo::rank, "The number of dimensions (rank)")
38 .def_property(
39 "dims", [](const tensorinfo &ti) { return get_dims(ti); },
40 [](tensorinfo &ti, const py::list &dims_list) { set_dims(ti, dims_list); },
41 "The dimension of tensor. Maximum rank is 6 (NNFW_MAX_RANK).");
42}
py::list get_dims(const tensorinfo &tensor_info)
Get nnfw_tensorinfo->dims.
tensor info describes the type and shape of tensors

References onert::api::python::tensorinfo::dtype, get_dims(), m, onert::api::python::tensorinfo::rank, and set_dims().

◆ bind_tensorinfo() [2/2]

void onert::api::python::bind_tensorinfo ( pybind11::module_ &  m)

Referenced by PYBIND11_MODULE().

◆ ensure_status()

void onert::api::python::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 30 of file nnfw_api_wrapper.cc.

31{
32 switch (status)
33 {
35 break;
37 std::cout << "[ERROR]\tNNFW_STATUS_ERROR\n";
38 exit(1);
40 std::cout << "[ERROR]\tNNFW_STATUS_UNEXPECTED_NULL\n";
41 exit(1);
43 std::cout << "[ERROR]\tNNFW_STATUS_INVALID_STATE\n";
44 exit(1);
46 std::cout << "[ERROR]\tNNFW_STATUS_OUT_OF_MEMORY\n";
47 exit(1);
49 std::cout << "[ERROR]\tNNFW_STATUS_INSUFFICIENT_OUTPUT_SIZE\n";
50 exit(1);
52 std::cout << "[ERROR]\tNNFW_STATUS_DEPRECATED_API\n";
53 exit(1);
54 }
55}
@ 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 onert::api::python::NNFW_SESSION::close_session(), onert::api::python::NNFW_SESSION::input_size(), onert::api::python::NNFW_SESSION::input_tensorinfo(), onert::api::python::NNFW_SESSION::NNFW_SESSION(), onert::api::python::NNFW_SESSION::output_size(), onert::api::python::NNFW_SESSION::output_tensorinfo(), onert::api::python::NNFW_SESSION::prepare(), onert::api::python::NNFW_SESSION::run(), onert::api::python::NNFW_SESSION::run_async(), onert::api::python::NNFW_SESSION::set_input(), onert::api::python::NNFW_SESSION::set_input_layout(), onert::api::python::NNFW_SESSION::set_input_tensorinfo(), onert::api::python::NNFW_SESSION::set_output(), onert::api::python::NNFW_SESSION::set_output_layout(), onert::api::python::NNFW_SESSION::train(), onert::api::python::NNFW_SESSION::train_export_checkpoint(), onert::api::python::NNFW_SESSION::train_export_circle(), onert::api::python::NNFW_SESSION::train_get_loss(), onert::api::python::NNFW_SESSION::train_get_traininfo(), onert::api::python::NNFW_SESSION::train_import_checkpoint(), onert::api::python::NNFW_SESSION::train_prepare(), onert::api::python::NNFW_SESSION::train_set_expected(), onert::api::python::NNFW_SESSION::train_set_input(), onert::api::python::NNFW_SESSION::train_set_output(), onert::api::python::NNFW_SESSION::train_set_traininfo(), and onert::api::python::NNFW_SESSION::wait().

◆ get_dims()

py::list onert::api::python::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 151 of file nnfw_api_wrapper.cc.

152{
153 py::list dims_list;
154 for (int32_t i = 0; i < tensor_info.rank; ++i)
155 {
156 dims_list.append(tensor_info.dims[i]);
157 }
158 return dims_list;
159}
int32_t dims[NNFW_MAX_RANK]

References onert::api::python::tensorinfo::dims, and onert::api::python::tensorinfo::rank.

Referenced by bind_tensorinfo().

◆ getLayout()

NNFW_LAYOUT onert::api::python::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 57 of file nnfw_api_wrapper.cc.

58{
59 if (!strcmp(layout, "NCHW"))
60 {
62 }
63 else if (!strcmp(layout, "NHWC"))
64 {
66 }
67 else if (!strcmp(layout, "NONE"))
68 {
70 }
71 else
72 {
73 std::cout << "[ERROR]\tLAYOUT_TYPE\n";
74 exit(1);
75 }
76}
@ 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 onert::api::python::NNFW_SESSION::set_input_layout(), and onert::api::python::NNFW_SESSION::set_output_layout().

◆ getStringType()

const char * onert::api::python::getStringType ( NNFW_TYPE  type)

Convert the type with NNFW_TYPE to string

Parameters
[in]typetype to be converted
Returns
proper type

Definition at line 116 of file nnfw_api_wrapper.cc.

117{
118 switch (type)
119 {
121 return "float32";
123 return "int32";
124 case NNFW_TYPE::NNFW_TYPE_TENSOR_QUANT8_ASYMM:
125 case NNFW_TYPE::NNFW_TYPE_TENSOR_UINT8:
126 return "uint8";
127 case NNFW_TYPE::NNFW_TYPE_TENSOR_BOOL:
128 return "bool";
129 case NNFW_TYPE::NNFW_TYPE_TENSOR_INT64:
130 return "int64";
131 case NNFW_TYPE::NNFW_TYPE_TENSOR_QUANT8_ASYMM_SIGNED:
132 return "int8";
133 case NNFW_TYPE::NNFW_TYPE_TENSOR_QUANT16_SYMM_SIGNED:
134 return "int16";
135 default:
136 std::cout << "[ERROR] NNFW_TYPE to String Failure\n";
137 exit(1);
138 }
139}
@ 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 onert::api::python::NNFW_SESSION::input_tensorinfo(), and onert::api::python::NNFW_SESSION::output_tensorinfo().

◆ getType()

NNFW_TYPE onert::api::python::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 78 of file nnfw_api_wrapper.cc.

79{
80 if (!strcmp(type, "float32"))
81 {
83 }
84 else if (!strcmp(type, "int32"))
85 {
87 }
88 else if (!strcmp(type, "uint8"))
89 {
90 return NNFW_TYPE::NNFW_TYPE_TENSOR_UINT8;
91 // return NNFW_TYPE::NNFW_TYPE_TENSOR_QUANT8_ASYMM;
92 }
93 else if (!strcmp(type, "bool"))
94 {
95 return NNFW_TYPE::NNFW_TYPE_TENSOR_BOOL;
96 }
97 else if (!strcmp(type, "int64"))
98 {
99 return NNFW_TYPE::NNFW_TYPE_TENSOR_INT64;
100 }
101 else if (!strcmp(type, "int8"))
102 {
103 return NNFW_TYPE::NNFW_TYPE_TENSOR_QUANT8_ASYMM_SIGNED;
104 }
105 else if (!strcmp(type, "int16"))
106 {
107 return NNFW_TYPE::NNFW_TYPE_TENSOR_QUANT16_SYMM_SIGNED;
108 }
109 else
110 {
111 std::cout << "[ERROR] String to NNFW_TYPE Failure\n";
112 exit(1);
113 }
114}

References NNFW_TYPE_TENSOR_FLOAT32, and NNFW_TYPE_TENSOR_INT32.

Referenced by onert::api::python::NNFW_SESSION::set_input_tensorinfo().

◆ num_elems()

uint64_t onert::api::python::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 141 of file nnfw_api_wrapper.cc.

142{
143 uint64_t n = 1;
144 for (int32_t i = 0; i < tensor_info->rank; ++i)
145 {
146 n *= tensor_info->dims[i];
147 }
148 return n;
149}
int32_t dims[NNFW_MAX_RANK]

References nnfw_tensorinfo::dims, and nnfw_tensorinfo::rank.

Referenced by onert::api::python::NNFW_SESSION::set_input(), onert::api::python::NNFW_SESSION::set_output(), and onert::api::python::NNFW_SESSION::train_set_output().

◆ set_dims()

void onert::api::python::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 161 of file nnfw_api_wrapper.cc.

162{
163 tensor_info.rank = py::len(array);
164 for (int32_t i = 0; i < tensor_info.rank; ++i)
165 {
166 tensor_info.dims[i] = py::cast<int32_t>(array[i]);
167 }
168}

References onert::api::python::tensorinfo::dims, and onert::api::python::tensorinfo::rank.

Referenced by bind_tensorinfo().