Skip to content
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

Merged
merged 3 commits into from
Nov 30, 2021

Conversation

jvuillaumier
Copy link


Changes proposed in this PR:

2 items related to XNNPACK delegate usage with TfLite framework (tested on TfLite 2.6):

  1. 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.

  2. 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:

  1. Build test: [ ]Passed [ ]Failed [*]Skipped
  2. Run test: [*]Passed [ ]Failed []Skipped
    SSAT test suite passed

How to evaluate:

  1. need TFLite library built with XNNPACK support
  2. enable NNStreamer meson build option -Dtflite2-xnnpack-delegate-support=true
  3. use tensor_filter property custom=Delegate:XNNPACK

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
Copy link
Collaborator

taos-ci commented Nov 26, 2021

📝 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/.

@taos-ci
Copy link
Collaborator

taos-ci commented Nov 26, 2021

@taos-ci
Copy link
Collaborator

taos-ci commented Nov 26, 2021

:octocat: 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>
@jvuillaumier
Copy link
Author

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.

@taos-ci
Copy link
Collaborator

taos-ci commented Nov 26, 2021

:octocat: 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/.

@anyj0527 anyj0527 changed the title tensor_filter TFLite subplugin - XNNPACK delegate tensor_filter TFLite subplugin - XNNPACK delegate @open sesame 11/29 12:40 Nov 29, 2021
Copy link
Collaborator

@taos-ci taos-ci left a 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.

Copy link
Member

@anyj0527 anyj0527 left a 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✔

@myungjoo myungjoo merged commit 2bc41df into nnstreamer:main Nov 30, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants