ONE - On-device Neural Engine
Loading...
Searching...
No Matches
NNFW_SESSION Class Reference

#include <nnfw_api_wrapper.h>

Public Member Functions

 NNFW_SESSION (const char *package_file_path, const char *backends)
 
 ~NNFW_SESSION ()
 
void close_session ()
 
void set_input_tensorinfo (uint32_t index, const tensorinfo *tensor_info)
 
void run ()
 
void run_async ()
 
void wait ()
 
template<typename T >
void set_input (uint32_t index, py::array_t< T > &buffer)
 process input array according to data type of numpy array sent by Python (int, float, uint8_t, bool, int64_t, int8_t, int16_t)
 
template<typename T >
void set_output (uint32_t index, py::array_t< T > &buffer)
 process output array according to data type of numpy array sent by Python (int, float, uint8_t, bool, int64_t, int8_t, int16_t)
 
uint32_t input_size ()
 
uint32_t output_size ()
 
void set_input_layout (uint32_t index, const char *layout)
 
void set_output_layout (uint32_t index, const char *layout)
 
tensorinfo input_tensorinfo (uint32_t index)
 
tensorinfo output_tensorinfo (uint32_t index)
 

Detailed Description

Definition at line 112 of file nnfw_api_wrapper.h.

Constructor & Destructor Documentation

◆ NNFW_SESSION()

NNFW_SESSION::NNFW_SESSION ( const char *  package_file_path,
const char *  backends 
)

Definition at line 161 of file nnfw_api_wrapper.cc.

162{
163 this->session = nullptr;
164 ensure_status(nnfw_create_session(&(this->session)));
165 ensure_status(nnfw_load_model_from_file(this->session, package_file_path));
167 ensure_status(nnfw_prepare(this->session));
168}
NNFW_STATUS nnfw_set_available_backends(nnfw_session *session, const char *backends)
Set available backends.
Definition nnfw_api.cc:167
NNFW_STATUS nnfw_prepare(nnfw_session *session)
Prepare session to be ready for inference.
Definition nnfw_api.cc:72
void ensure_status(NNFW_STATUS status)
Handle errors with NNFW_STATUS in API functions.
NNFW_STATUS nnfw_create_session(nnfw_session **session)
Create a new session instance.
NNFW_STATUS nnfw_load_model_from_file(nnfw_session *session, const char *package_file_path)
Load model from nnpackage file or directory.

References ensure_status(), nnfw_create_session(), nnfw_load_model_from_file(), nnfw_prepare(), and nnfw_set_available_backends().

◆ ~NNFW_SESSION()

NNFW_SESSION::~NNFW_SESSION ( )

Definition at line 169 of file nnfw_api_wrapper.cc.

170{
171 if (session)
172 {
174 }
175}

References close_session().

Member Function Documentation

◆ close_session()

void NNFW_SESSION::close_session ( )

Definition at line 177 of file nnfw_api_wrapper.cc.

178{
179 ensure_status(nnfw_close_session(this->session));
180 this->session = nullptr;
181}
NNFW_STATUS nnfw_close_session(nnfw_session *session)
Close a session instance.
Definition nnfw_api.cc:60

References ensure_status(), and nnfw_close_session().

Referenced by ~NNFW_SESSION().

◆ input_size()

uint32_t NNFW_SESSION::input_size ( )

Definition at line 196 of file nnfw_api_wrapper.cc.

197{
198 uint32_t number;
199 NNFW_STATUS status = nnfw_input_size(session, &number);
200 ensure_status(status);
201 return number;
202}
int number
Definition jpeg2hdf5.py:87
NNFW_STATUS nnfw_input_size(nnfw_session *session, uint32_t *number)
Get the number of inputs.
Definition nnfw_api.cc:110
NNFW_STATUS
Result values returned from a call to an API function.
Definition onert-micro.h:86

References ensure_status(), and nnfw_input_size().

Referenced by PYBIND11_MODULE().

◆ input_tensorinfo()

tensorinfo NNFW_SESSION::input_tensorinfo ( uint32_t  index)

Definition at line 220 of file nnfw_api_wrapper.cc.

221{
222 nnfw_tensorinfo tensor_info = nnfw_tensorinfo();
223 ensure_status(nnfw_input_tensorinfo(session, index, &tensor_info));
224 tensorinfo ti;
225 ti.dtype = getStringType(tensor_info.dtype);
226 ti.rank = tensor_info.rank;
227 for (int i = 0; i < NNFW_MAX_RANK; i++)
228 {
229 ti.dims[i] = tensor_info.dims[i];
230 }
231 return ti;
232}
NNFW_STATUS nnfw_input_tensorinfo(nnfw_session *session, uint32_t index, nnfw_tensorinfo *tensor_info)
Get i-th input tensor info.
Definition nnfw_api.cc:134
const char * getStringType(NNFW_TYPE type)
#define NNFW_MAX_RANK
Maximum rank expressible with nnfw.
tensor info describes the type and shape of tensors
NNFW_TYPE dtype
int32_t dims[NNFW_MAX_RANK]
tensor info describes the type and shape of tensors
int32_t dims[NNFW_MAX_RANK]
const char * dtype

References nnfw_tensorinfo::dims, tensorinfo::dims, nnfw_tensorinfo::dtype, tensorinfo::dtype, ensure_status(), getStringType(), nnfw_input_tensorinfo(), NNFW_MAX_RANK, nnfw_tensorinfo::rank, and tensorinfo::rank.

Referenced by PYBIND11_MODULE(), and package.infer.session::set_inputs().

◆ output_size()

uint32_t NNFW_SESSION::output_size ( )

Definition at line 203 of file nnfw_api_wrapper.cc.

204{
205 uint32_t number;
206 NNFW_STATUS status = nnfw_output_size(session, &number);
207 ensure_status(status);
208 return number;
209}
NNFW_STATUS nnfw_output_size(nnfw_session *session, uint32_t *number)
Get the number of outputs.
Definition nnfw_api.cc:116

References ensure_status(), and nnfw_output_size().

Referenced by PYBIND11_MODULE().

◆ output_tensorinfo()

tensorinfo NNFW_SESSION::output_tensorinfo ( uint32_t  index)

Definition at line 233 of file nnfw_api_wrapper.cc.

234{
235 nnfw_tensorinfo tensor_info = nnfw_tensorinfo();
236 ensure_status(nnfw_output_tensorinfo(session, index, &tensor_info));
237 tensorinfo ti;
238 ti.dtype = getStringType(tensor_info.dtype);
239 ti.rank = tensor_info.rank;
240 for (int i = 0; i < NNFW_MAX_RANK; i++)
241 {
242 ti.dims[i] = tensor_info.dims[i];
243 }
244 return ti;
245}
NNFW_STATUS nnfw_output_tensorinfo(nnfw_session *session, uint32_t index, nnfw_tensorinfo *tensor_info)
Get i-th output tensor info.
Definition nnfw_api.cc:141

References nnfw_tensorinfo::dims, tensorinfo::dims, nnfw_tensorinfo::dtype, tensorinfo::dtype, ensure_status(), getStringType(), NNFW_MAX_RANK, nnfw_output_tensorinfo(), nnfw_tensorinfo::rank, and tensorinfo::rank.

Referenced by PYBIND11_MODULE(), and package.infer.session::set_outputs().

◆ run()

void NNFW_SESSION::run ( )

Definition at line 193 of file nnfw_api_wrapper.cc.

193{ ensure_status(nnfw_run(session)); }
NNFW_STATUS nnfw_run(nnfw_session *session)
Run inference.
Definition nnfw_api.cc:78

References ensure_status(), and nnfw_run().

Referenced by package.infer.session::inference(), and PYBIND11_MODULE().

◆ run_async()

void NNFW_SESSION::run_async ( )

Definition at line 194 of file nnfw_api_wrapper.cc.

194{ ensure_status(nnfw_run_async(session)); }
NNFW_STATUS nnfw_run_async(nnfw_session *session)
Run inference asynchronously.
Definition nnfw_api.cc:84

References ensure_status(), and nnfw_run_async().

Referenced by PYBIND11_MODULE().

◆ set_input()

template<typename T >
void NNFW_SESSION::set_input ( uint32_t  index,
py::array_t< T > &  buffer 
)
inline

process input array according to data type of numpy array sent by Python (int, float, uint8_t, bool, int64_t, int8_t, int16_t)

Definition at line 130 of file nnfw_api_wrapper.h.

131 {
132 nnfw_tensorinfo tensor_info;
133 nnfw_input_tensorinfo(this->session, index, &tensor_info);
134 NNFW_TYPE type = tensor_info.dtype;
135 uint32_t input_elements = num_elems(&tensor_info);
136 size_t length = sizeof(T) * input_elements;
137
138 ensure_status(nnfw_set_input(session, index, type, buffer.request().ptr, length));
139 }
type
Definition infer.py:18
NNFW_STATUS nnfw_set_input(nnfw_session *session, uint32_t index, NNFW_TYPE type, const void *buffer, size_t length)
Set input buffer.
Definition nnfw_api.cc:96
uint64_t num_elems(const nnfw_tensorinfo *tensor_info)
Get the total number of elements in nnfw_tensorinfo->dims.
NNFW_TYPE
Definition onert-micro.h:75

References nnfw_tensorinfo::dtype, ensure_status(), nnfw_input_tensorinfo(), nnfw_set_input(), and num_elems().

Referenced by package.infer.session::set_inputs().

◆ set_input_layout()

void NNFW_SESSION::set_input_layout ( uint32_t  index,
const char *  layout 
)

Definition at line 210 of file nnfw_api_wrapper.cc.

211{
212 NNFW_LAYOUT nnfw_layout = getLayout(layout);
213 ensure_status(nnfw_set_input_layout(session, index, nnfw_layout));
214}
NNFW_LAYOUT
Data format of a tensor.
Definition nnfw.h:134
NNFW_STATUS nnfw_set_input_layout(nnfw_session *session, uint32_t index, NNFW_LAYOUT layout)
Set the layout of an input.
Definition nnfw_api.cc:122
NNFW_LAYOUT getLayout(const char *layout="")

References ensure_status(), getLayout(), and nnfw_set_input_layout().

Referenced by PYBIND11_MODULE().

◆ set_input_tensorinfo()

void NNFW_SESSION::set_input_tensorinfo ( uint32_t  index,
const tensorinfo tensor_info 
)

Definition at line 182 of file nnfw_api_wrapper.cc.

183{
185 ti.dtype = getType(tensor_info->dtype);
186 ti.rank = tensor_info->rank;
187 for (int i = 0; i < NNFW_MAX_RANK; i++)
188 {
189 ti.dims[i] = tensor_info->dims[i];
190 }
191 ensure_status(nnfw_set_input_tensorinfo(session, index, &ti));
192}
NNFW_STATUS nnfw_set_input_tensorinfo(nnfw_session *session, uint32_t index, const nnfw_tensorinfo *tensor_info)
Set input model's tensor info for resizing.
Definition nnfw_api.cc:160
NNFW_TYPE getType(const char *type="")

References nnfw_tensorinfo::dims, tensorinfo::dims, nnfw_tensorinfo::dtype, tensorinfo::dtype, ensure_status(), getType(), NNFW_MAX_RANK, nnfw_set_input_tensorinfo(), nnfw_tensorinfo::rank, and tensorinfo::rank.

Referenced by PYBIND11_MODULE().

◆ set_output()

template<typename T >
void NNFW_SESSION::set_output ( uint32_t  index,
py::array_t< T > &  buffer 
)
inline

process output array according to data type of numpy array sent by Python (int, float, uint8_t, bool, int64_t, int8_t, int16_t)

Definition at line 144 of file nnfw_api_wrapper.h.

145 {
146 nnfw_tensorinfo tensor_info;
147 nnfw_output_tensorinfo(this->session, index, &tensor_info);
148 NNFW_TYPE type = tensor_info.dtype;
149 uint32_t output_elements = num_elems(&tensor_info);
150 size_t length = sizeof(T) * output_elements;
151
152 ensure_status(nnfw_set_output(session, index, type, buffer.request().ptr, length));
153 }
NNFW_STATUS nnfw_set_output(nnfw_session *session, uint32_t index, NNFW_TYPE type, void *buffer, size_t length)
Set output buffer.
Definition nnfw_api.cc:103

References nnfw_tensorinfo::dtype, ensure_status(), nnfw_output_tensorinfo(), nnfw_set_output(), and num_elems().

Referenced by package.infer.session::set_outputs().

◆ set_output_layout()

void NNFW_SESSION::set_output_layout ( uint32_t  index,
const char *  layout 
)

Definition at line 215 of file nnfw_api_wrapper.cc.

216{
217 NNFW_LAYOUT nnfw_layout = getLayout(layout);
218 ensure_status(nnfw_set_output_layout(session, index, nnfw_layout));
219}
NNFW_STATUS nnfw_set_output_layout(nnfw_session *session, uint32_t index, NNFW_LAYOUT layout)
Set the layout of an output.
Definition nnfw_api.cc:128

References ensure_status(), getLayout(), and nnfw_set_output_layout().

Referenced by PYBIND11_MODULE().

◆ wait()

void NNFW_SESSION::wait ( )

Definition at line 195 of file nnfw_api_wrapper.cc.

195{ ensure_status(nnfw_await(session)); }
NNFW_STATUS nnfw_await(nnfw_session *session)
Wait for asynchronous run to finish.
Definition nnfw_api.cc:90

References ensure_status(), and nnfw_await().

Referenced by PYBIND11_MODULE().


The documentation for this class was generated from the following files: