3 This document explains about custom operator and how custom op is represented in nnpackage.
5 ## What is custom operator?
7 Custom operator(hereafter custom op) is used to provide a new operator implementation.
8 It can be anything that does not exist in current runtime implementation.
10 You can use custom operator for several use cases, possible use cases are:
12 - when an operator in tensorflow is not supported in nnfw runtime
13 - when an operator is supported, however, you would like to use your own implementation
14 - it may be for optimization, by grouping several operators into one super operator.
18 nnpackage will support several kinds of models.
19 Currently the only type is tflite.
23 If you're using `tflite` format, it is same format to tensorflow lite.
25 You can generate `tflite` model with custom op using `tflite_convert`.
26 Please find the documentation in tensorflow official site.
28 ## Custom op kernel implementation
30 You need to provide the kernel of custom op in the following form:
34 * Custom kernel evaluation function
36 * param[in] params custom operation parameters
37 * param[in] userdata pointer to user-specified buffer( kernel instance specific )
39 typedef void (*nnfw_custom_eval)(nnfw_custom_kernel_params *params, char *userdata,
40 size_t userdata_size);
44 The structures and relevant APIs are defined in nnfw APIs.
45 Please see `nnfw_experimental.h` for detail.
47 You can find example in `nnfw` repository.
49 Custom op kernel implementation is stored in nnpackage in form of prebuilt library.
51 It is example nnpackage structure for `FillFrom`:
57 │ ├── libFillFrom.armv7l-linux.debug.a
58 │ └── libFillFrom.armv7l-linux.release.a
63 All custom operator libraries are put under `{nnpackage_root}/custom_op/lib{customop_name}.{arch}-{os}.{buildtype}.a`.
65 ## How to use custom op in app
67 To use custom op, the app has to register the operators with `nnfw_register_custom_op_info`.
72 * custom operation registration info
76 nnfw_custom_eval eval_function;
77 } custom_kernel_registration_info;
79 NNFW_STATUS nnfw_register_custom_op_info(nnfw_session *session, const char *id,
80 custom_kernel_registration_info *info)
83 Please find sample app in `nnfw` repository
85 The `id` should be unique in an app.