-
Notifications
You must be signed in to change notification settings - Fork 169
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
tensor_filter TFLite subplugin - XNNPACK delegate @open sesame 11/29 12:40 #3577
tensor_filter TFLite subplugin - XNNPACK delegate @open sesame 11/29 12:40 #3577
Conversation
TFLite libray may be built to use default delegates when no delegate is explicitly bound to the interpreter. In case default delegates are not supported by TFLite filter, system may crash. Make sure that no default delegate is applied by using relevant interpreter builder API available from TFLite 2.4 onward. Signed-off-by: Julien Vuillaumier <julien.vuillaumier@nxp.com>
Signed-off-by: Julien Vuillaumier <julien.vuillaumier@nxp.com>
📝 TAOS-CI Version: 1.5.20200925. Thank you for submitting PR #3577. Please a submit 1commit/1PR (one commit per one PR) policy to get comments quickly from reviewers. Your PR must pass all verificiation processes of cibot before starting a review process from reviewers. If you are new member to join this project, please read manuals in documentation folder and wiki page. In order to monitor a progress status of your PR in more detail, visit http://nnstreamer.mooo.com/. |
cibot: @jvuillaumier, apptest could not be completed. To find out the reasons, please go to http://nnstreamer.mooo.com//nnstreamer/ci/repo-workers/pr-checker/3577-202111262031020.78351998329163-41063e94aa520cd331a3a90c0e7cded5725a3ac8 |
cibot: @jvuillaumier, A builder checker could not be completed because one of the checkers is not completed. In order to find out a reason, please go to http://nnstreamer.mooo.com/nnstreamer/ci/repo-workers/pr-checker/3577-202111262031020.78351998329163-41063e94aa520cd331a3a90c0e7cded5725a3ac8/. |
XNNPACK delegate requires fixed addresses for input and output tensors, for consecutive invoke(). Therefore input and output tensors data coming from GStreamer buffers has to copied into tensors buffer allocated by TFLite runtime. Signed-off-by: Julien Vuillaumier <julien.vuillaumier@nxp.com>
41063e9
to
65bc020
Compare
Patchset updated to fallback using (TfLiteTensor*)->data.raw (deprecated since TFLite 2.2) instead of more recent (TfLiteTensor*)->data.data as it is breaking some builds. |
cibot: @jvuillaumier, A builder checker could not be completed because one of the checkers is not completed. In order to find out a reason, please go to http://nnstreamer.mooo.com/nnstreamer/ci/repo-workers/pr-checker/3577-202111262336440.43698191642761-65bc0203b879a8e19b061eeb4491c96e46dca7be/. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jvuillaumier, 💯 All CI checkers are successfully verified. Thanks.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great thanks for this contribution. I've packaged tflite v2.6.0+ for android and tizen without default delegate feature to address this default delegate issue.
But using tflite::ops::builtin::BuiltinOpResolverWithoutDefaultDelegates resolver
seems more elegant considering those who manually build nnstreamer with their own tflite support.
LGTM✔
Changes proposed in this PR:
2 items related to XNNPACK delegate usage with TfLite framework (tested on TfLite 2.6):
Peculiarity of TfLite XNNPACK delegate usage in TfLite is that both input and output tensors buffer addresses are cached within XNNPACK runtime during first invoke(). NNStreamer tensor_filter input/output buffer memory addresses change from an inference to an other, therefore i/o buffer data has to be copied between Gst memory and TfLite allocated memory for tensors. Failure to do so typically leads to system crash as TfLite interpreter tries to access during subsequent invoke() to the GStreamer buffers populated during 1st invoke that have chances to have been deallocated and unmapped.
Currently only output tensors data copy is provisioned for XNNPACK case.
When TfLite library is built with XNNPACK delegate support, XNNPACK delegate is used as a default delegate for the graph, even though not explicitly applied via ModifyGraphWithDelegate().
Issue is that XNNPACK usage requires tensor data copies so for NNStreamer case, XNNPACK should only be used when explicitly selected by the user (custom=Delegate:XNNPACK) so that TfLite subplugin is aware about XNNPACK usage and handle input/output tensors accordingly.
API for OpResolver has been introduced in TfLite 2.4 for this:
tflite::ops::builtin::BuiltinOpResolverWithoutDefaultDelegates resolver;
https://github.com/tensorflow/tensorflow/blob/master/tensorflow/lite/kernels/register.h#L36
Self evaluation:
SSAT test suite passed
How to evaluate: