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

TF Lite kernel tests cross-compilation enablement using CMake #52110

Conversation

madaosik
Copy link
Contributor

@madaosik madaosik commented Sep 23, 2021

This PR implements the enablement of the TF Lite kernel tests CMake cross-compilation using the natively built flatc compiler (for details please see the updated build_cmake.md file).

As it currently stands in the master branch, the native CMake compilation produces malformed TF Lite kernel tests. Therefore, for testing purposes, this PR also encompasses changes implemented by the currently reviewed PR which fixes it.

@google-ml-butler google-ml-butler bot added the size:M CL Change Size: Medium label Sep 23, 2021
@google-cla google-cla bot added the cla: yes label Sep 23, 2021
@gbaned gbaned self-assigned this Sep 24, 2021
@gbaned gbaned added the comp:lite TF Lite related issues label Sep 24, 2021
@gbaned gbaned added this to Assigned Reviewer in PR Queue via automation Sep 24, 2021
@google-ml-butler google-ml-butler bot added the awaiting review Pull request awaiting review label Sep 24, 2021
@xunkai55 xunkai55 requested review from terryheo and removed request for xunkai55 September 27, 2021 15:15
Copy link
Member

@terryheo terryheo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your contribution

@@ -41,18 +41,37 @@ build_flatbuffers(
""
)

set(DELEGATE_PROVIDERS_SUPP
${TFLITE_SOURCE_DIR}/nnapi/sl/SupportLibrary.cc
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

plz alphabetize.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done


set(DELEGATE_PROVIDERS
${DELEGATE_PROVIDERS_SUPP}
${TFLITE_SOURCE_DIR}/tools/delegates/gpu_delegate_provider.cc
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@@ -29,6 +29,8 @@ constexpr char KernelTestDelegateProviders::kUseSimpleAllocator[];

KernelTestDelegateProviders::KernelTestDelegateProviders()
: delegate_list_util_(&params_) {
TFLITE_TOOLS_CHECK(delegate_list_util_.GetCount() > 0)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what's happening if we don't have this?

Copy link
Contributor Author

@madaosik madaosik Sep 29, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If there is no delegate available, calling delegate_list_util.AppendCmdlineFlags(&flags) (line 46) appends no command line flags. Since at least --help flag is expected to be available (line 49), the condition returns false and an error is reported (specifically: "help was not found", as implemented in tensorflow/lite/tools/tool_params.cc:53). So this check aims to provide the user with more instructive/helpful error message, should this happen again in the future.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It turns out this change breaks many tests. You'd better revert it.

bazel test tensorflow/lite/kernels:optional_tensor_test

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The check has been reverted in the latest commits.

to build the flatc compiler with CMake in advance using the host toolchain:

```sh
cmake ../tensorflow_src/tensorflow/lite/tools/cmake/native_tools/flatbuffers
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't we use a separate directory for native_tools and tflite build? I think we'd better mention it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The documentation has been updated to make this more obvious.


```sh
cmake -DCMAKE_INSTALL_PREFIX=<native_tools_dir> ../tensorflow_src/tensorflow/lite/tools/cmake/native_tools/flatbuffers
cmake --build .
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don't we need to run install command?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, running cmake --build . installs the flatc automatically.

Copy link
Member

@terryheo terryheo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@google-ml-butler google-ml-butler bot added kokoro:force-run Tests on submitted change ready to pull PR ready for merge process labels Sep 30, 2021
PR Queue automation moved this from Assigned Reviewer to Approved by Reviewer Sep 30, 2021
@kokoro-team kokoro-team removed the kokoro:force-run Tests on submitted change label Sep 30, 2021
@gbaned gbaned removed the awaiting review Pull request awaiting review label Sep 30, 2021
@google-ml-butler google-ml-butler bot removed the ready to pull PR ready for merge process label Oct 1, 2021
@gbaned gbaned requested a review from terryheo October 4, 2021 08:17
@google-ml-butler google-ml-butler bot added the awaiting review Pull request awaiting review label Oct 4, 2021
##### Specifics of kernel (unit) tests cross-compilation

Cross-compilation of the unit tests requires flatc compiler for the host architecture.
For this purpose, there is a CMakeLists located in _tensorflow/lite/tools/cmake/native_tools/flatbuffers_
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is "xxx" valid markdown format?
https://www.markdownguide.org/basic-syntax/
I think it's better to use xxx instead.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

True - updated in the latest commit.

@gbaned gbaned requested a review from terryheo October 6, 2021 14:37
@google-ml-butler google-ml-butler bot added the kokoro:force-run Tests on submitted change label Oct 7, 2021
@google-ml-butler google-ml-butler bot added the ready to pull PR ready for merge process label Oct 7, 2021
@kokoro-team kokoro-team removed the kokoro:force-run Tests on submitted change label Oct 7, 2021
Copy link
Member

@terryheo terryheo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Plz fix failing tests.

# purposes the FLATC_INSTALL_PREFIX is already in cache and is just used in this module.
# In case of standard flatbuffers build (as a dependency) the variable needs to be set.
if(NOT DEFINED FLATC_INSTALL_PREFIX)
set(FLATC_INSTALL_PREFIX <INSTALL_DIR> CACHE PATH "Flatc installation directory")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a space at the ending. Plz remove it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Space removed in the latest commit.

@@ -29,6 +29,8 @@ constexpr char KernelTestDelegateProviders::kUseSimpleAllocator[];

KernelTestDelegateProviders::KernelTestDelegateProviders()
: delegate_list_util_(&params_) {
TFLITE_TOOLS_CHECK(delegate_list_util_.GetCount() > 0)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It turns out this change breaks many tests. You'd better revert it.

bazel test tensorflow/lite/kernels:optional_tensor_test

PR Queue automation moved this from Approved by Reviewer to Reviewer Requested Changes Oct 7, 2021
@google-ml-butler google-ml-butler bot removed the ready to pull PR ready for merge process label Oct 8, 2021
Copy link
Member

@terryheo terryheo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@google-ml-butler google-ml-butler bot added kokoro:force-run Tests on submitted change ready to pull PR ready for merge process labels Oct 8, 2021
PR Queue automation moved this from Reviewer Requested Changes to Approved by Reviewer Oct 8, 2021
@kokoro-team kokoro-team removed the kokoro:force-run Tests on submitted change label Oct 8, 2021
@gbaned gbaned removed the awaiting review Pull request awaiting review label Oct 8, 2021
@copybara-service copybara-service bot merged commit 14e6cd1 into tensorflow:master Oct 9, 2021
@google-ml-butler google-ml-butler bot removed the ready to pull PR ready for merge process label Oct 9, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla: yes comp:lite TF Lite related issues size:M CL Change Size: Medium
Projects
PR Queue
  
Approved by Reviewer
Development

Successfully merging this pull request may close these issues.

None yet

4 participants