tensorflow / flutter-tflite

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Unable to find `TfLiteXNNPackDelegateCreate` Symbol on Windows Flutter Project

robinduerhager opened this issue · comments

Hi there,

I was following the build instructions in the README to create a tflite .dll file for my windows realtime image classification project.
The project works but very stuttery, so I tried to use the XNNPackDelegate since this should be supported according to the build instructions and the README. Though, when trying to initialize the according InterpreterOptions, I get the following error:

flutter: Error: Invalid argument(s): Failed to lookup symbol 'TfLiteXNNPackDelegateCreate': error code 127

Here is the code, that leads to the error:

// This already fails with the error code above.
interpreterOptions.addDelegate(XNNPackDelegate());

// Adding explicit options are not helping, so i guess the XNNPackDelegate() constructor is the problem here.
interpreterOptions.addDelegate(XNNPackDelegate(options: XNNPackDelegateOptions(numThreads: 4)));

I compiled the Tflite Library with windows symbols export enabled, debug build and XNNPACK enabled, although this should be enabled by default:

cmake -DCMAKE_WINDOWS_EXPORT_ALL_SYMBOLS=TRUE -DCMAKE_BUILD_TYPE=Debug -DTFLITE_ENABLE_XNNPACK=ON ../tensorflow_src/tensorflow/lite/c

Maybe I'm missing something here, but I am unable to find a solution, so I thought this might be a bug. Hope this helps :)

Thanks for the issue, I am not sure about the building process with delegates on Windows. But it seems like it is missing the required symbols from the .dll.

Here are two things you could try

  1. Try this pre-built .dll
  2. Try building with bazel

Maybe @st-duymai knows more about building with delegates on Windows.

Hi, thanks for the quick reply :).
I managed to test both of your suggestions.

The pre-built .dll didn't work for me which resulted in the Failed to lookup symbol 'TfLiteXNNPackDelegateCreate' Error mentioned above. However, building with Bazel did the trick! XNNPack now works in my project with the bazel build C Library .dll :).

The following steps / commands were used for the solution:

1. git clone https://github.com/tensorflow/tensorflow.git tensorflow_src
2. cd tensorflow_src
3. bazel build -c opt //tensorflow/lite/c:tensorflowlite_c
4. cp tensorflow_src/bazel-bin/tensorflow/lite/c/tensorflowlite_c.dll <flutter_project>/blobs/libtensorflowlite_c-win.dll

I leave this issue open for now since i think the CMAKE build process should be able to include XNNPack Symbols as well but you can close it if you want :). Thanks for the help!

Happy to read that it is working for you know. Yes, I think this needs to be sorted out. Either we need to update the readme or ask the TF engineers what is going on. I think PaulTR will do this once he is back.

Maybe its worth noting that TfLiteXNNPackDelegateCreate is not a symbol from the XNNPACK library but comes from xnnpack_delegate.cc from tensorflow\lite\delegates\xnnpack\xnnpack_delegate.cc

I encountered the issue by just compiling tflite c api. Looking at the tensorflow-lite.lib file with dumpbin /Symbols I see that the symbols that are the problem occur twice in the library:

1BE3 00000000 SECTDCC notype () External | _TfLiteXNNPackDelegateCreate
022 00000000 UNDEF notype () External | _TfLiteXNNPackDelegateCreate

I am not sure how to go from here. I checked that in code the function is only defined once. And all the build files look okay too.