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

Go to the source code of this file.

Functions

uint64_t num_elems (const nnfw_tensorinfo *ti)
 Get the total number of elements in nnfw_tensorinfo->dims.
 
int main (const int argc, char **argv)
 

Function Documentation

◆ main()

int main ( const int  argc,
char **  argv 
)

Definition at line 31 of file minimal.cc.

32{
33 nnfw_session *session = nullptr;
34 nnfw_create_session(&session);
35
36 // Loading nnpackage
37 nnfw_load_model_from_file(session, argv[1]);
38
39 // Use acl_neon backend for CONV_2D and acl_cl for otherwise.
40 // Note that defalut backend is acl_cl
41 nnfw_set_op_backend(session, "CONV_2D", "acl_neon");
42
43 // Compile model
44 nnfw_prepare(session);
45
46 // Prepare input. Here we just allocate dummy input arrays.
47 std::vector<float> input;
49 nnfw_input_tensorinfo(session, 0, &ti); // get first input's info
50 uint32_t input_elements = num_elems(&ti);
51 input.resize(input_elements);
52 // TODO: Please add initialization for your input.
53 nnfw_set_input(session, 0, ti.dtype, input.data(), sizeof(float) * input_elements);
54
55 // Prepare output
56 std::vector<float> output;
57 nnfw_output_tensorinfo(session, 0, &ti); // get first output's info
58 uint32_t output_elements = num_elems(&ti);
59 output.resize(output_elements);
60 nnfw_set_output(session, 0, ti.dtype, output.data(), sizeof(float) * output_elements);
61
62 // Do inference
63 nnfw_run(session);
64
65 // TODO: Please print or compare the output value in your way.
66
67 nnfw_close_session(session);
68
69 std::cout << "nnpackage " << argv[1] << " runs successfully." << std::endl;
70 return 0;
71}
uint64_t num_elems(const nnfw_tensorinfo *ti)
Get the total number of elements in nnfw_tensorinfo->dims.
Definition minimal.cc:21
SessionID session(const coco::Module *m)
Definition Session.cpp:48
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
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
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
NNFW_STATUS nnfw_run(nnfw_session *session)
Run inference.
Definition nnfw_api.cc:78
NNFW_STATUS nnfw_prepare(nnfw_session *session)
Prepare session to be ready for inference.
Definition nnfw_api.cc:72
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
NNFW_STATUS nnfw_set_op_backend(nnfw_session *session, const char *op, const char *backend)
Set the operation's backend.
Definition nnfw_api.cc:173
NNFW_STATUS nnfw_create_session(nnfw_session **session)
Create a new session instance.
NNFW_STATUS nnfw_close_session(nnfw_session *session)
Close a session instance.
Definition nnfw_api.cc:60
NNFW_STATUS nnfw_load_model_from_file(nnfw_session *session, const char *package_file_path)
Load model from nnpackage file or directory.
tensor info describes the type and shape of tensors
NNFW_TYPE dtype

References nnfw_tensorinfo::dtype, nnfw_close_session(), nnfw_create_session(), nnfw_input_tensorinfo(), nnfw_load_model_from_file(), nnfw_output_tensorinfo(), nnfw_prepare(), nnfw_run(), nnfw_set_input(), nnfw_set_op_backend(), nnfw_set_output(), and num_elems().

◆ 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 21 of file minimal.cc.

22{
23 uint64_t n = 1;
24 for (uint32_t i = 0; i < ti->rank; ++i)
25 {
26 n *= ti->dims[i];
27 }
28 return n;
29}
int32_t dims[NNFW_MAX_RANK]

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

Referenced by circle_eval_diff::MAEPrinter::init(), circle_eval_diff::MSEPrinter::init(), circle_eval_diff::MAPEPrinter::init(), circle_eval_diff::TopKMatchPrinter::init(), main(), dalgona::Dalgona::runAnalysisWithRandomInput(), NNFW_SESSION::set_input(), and NNFW_SESSION::set_output().