ONE - On-device Neural Engine
Loading...
Searching...
No Matches
nnfw_internal.cc File Reference
#include "nnfw_internal.h"
#include "nnfw_session.h"
#include <util/ConfigSource.h>

Go to the source code of this file.

Macros

#define NNFW_RETURN_ERROR_IF_NULL(p)
 

Functions

NNFW_STATUS nnfw_set_config (nnfw_session *session, const char *key, const char *value)
 
NNFW_STATUS nnfw_get_config (nnfw_session *session, const char *key, char *value, size_t value_size)
 
NNFW_STATUS nnfw_load_circle_from_buffer (nnfw_session *session, uint8_t *buffer, size_t size)
 Load a circle model from buffer.
 
NNFW_STATUS nnfw_train_export_circleplus (nnfw_session *session, const char *path)
 Export circle+ model.
 
NNFW_STATUS nnfw_get_output (nnfw_session *session, uint32_t index, nnfw_tensorinfo *out_info, const void **out_buffer)
 Python-binding-only API to retrieve a read-only output buffer and its tensor info.
 

Macro Definition Documentation

◆ NNFW_RETURN_ERROR_IF_NULL

#define NNFW_RETURN_ERROR_IF_NULL (   p)
Value:
do \
{ \
if ((p) == NULL) \
} while (0)
@ NNFW_STATUS_UNEXPECTED_NULL
Definition onert-micro.h:95
Configuration p

Definition at line 23 of file nnfw_internal.cc.

25 { \
26 if ((p) == NULL) \
28 } while (0)

Function Documentation

◆ nnfw_get_config()

NNFW_STATUS nnfw_get_config ( nnfw_session session,
const char *  key,
char *  value,
size_t  value_size 
)

Definition at line 36 of file nnfw_internal.cc.

37{
39 return session->get_config(key, value, value_size);
40}
SessionID session(const coco::Module *m)
Definition Session.cpp:48
#define NNFW_RETURN_ERROR_IF_NULL(p)

References NNFW_RETURN_ERROR_IF_NULL.

◆ nnfw_get_output()

NNFW_STATUS nnfw_get_output ( nnfw_session session,
uint32_t  index,
nnfw_tensorinfo out_info,
const void **  out_buffer 
)

Python-binding-only API to retrieve a read-only output buffer and its tensor info.

After nnfw_run has been called, the session has already resized or allocated the internal output buffer to match the latest output dimensions. This API simply retrieves that internal buffer pointer and the corresponding tensor info without performing any allocation itself.

Note: this function is intended for Python binding only. The buffer is managed internally by the session and must not be modified by the caller. In Python, wrap the pointer as a NumPy array and set array.flags.writeable = False to enforce read-only access.

Important: To use this API, you must call nnfw_set_prepare_config(session, NNFW_ENABLE_INTERNAL_OUTPUT_ALLOC, "true") before calling nnfw_prepare().

Parameters
[in]sessionThe session object
[in]indexOutput tensor index
[out]out_infonnfw_tensorinfo to be filled with the latest shape/type information
[out]out_bufferPointer to a const buffer managed by the session
Returns
NNFW_STATUS_NO_ERROR on success, otherwise an error code

Definition at line 54 of file nnfw_internal.cc.

56{
58 return session->get_output(index, out_info, out_buffer);
59}

References NNFW_RETURN_ERROR_IF_NULL.

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

◆ nnfw_load_circle_from_buffer()

NNFW_STATUS nnfw_load_circle_from_buffer ( nnfw_session session,
uint8_t *  buffer,
size_t  size 
)

Load a circle model from buffer.

The buffer must outlive the session.

Parameters
[in]sessionsession
[in]bufferPointer to the buffer
[in]sizeBuffer size
Returns
NNFW_STATUS

Definition at line 42 of file nnfw_internal.cc.

43{
45 return session->load_circle_from_buffer(buffer, size);
46}
int32_t size[5]
Definition Slice.cpp:35

References NNFW_RETURN_ERROR_IF_NULL, and size.

◆ nnfw_set_config()

NNFW_STATUS nnfw_set_config ( nnfw_session session,
const char *  key,
const char *  value 
)

Definition at line 30 of file nnfw_internal.cc.

31{
33 return session->set_config(key, value);
34}

References NNFW_RETURN_ERROR_IF_NULL.

◆ nnfw_train_export_circleplus()

NNFW_STATUS nnfw_train_export_circleplus ( nnfw_session session,
const char *  file_path 
)

Export circle+ model.

Note
This function should be called on training mode This function should be called before or after nnfw_train
Parameters
[in]sessionThe session to export training model
[in]file_pathThe path to export training model
Returns
NNFW_STATUS_NO_ERROR if successful

Definition at line 48 of file nnfw_internal.cc.

49{
51 return session->train_export_circleplus(path);
52}

References NNFW_RETURN_ERROR_IF_NULL.