From 82c9e09d2002d429870aa87013f7969b828ffcdd Mon Sep 17 00:00:00 2001 From: Terry Heo Date: Thu, 14 Jan 2021 16:30:58 -0800 Subject: [PATCH] tflite: Add fp16 headers to cmake rule This is needed to build GPU delegate without XNNPACK enabled. It fixes the issue #46386. PiperOrigin-RevId: 351901574 Change-Id: Ib0dff4c51627dfcd72fbb23d688ab2ae37505056 --- tensorflow/lite/CMakeLists.txt | 1 + .../cmake/modules/Findfp16_headers.cmake | 16 ++++++++ .../tools/cmake/modules/fp16_headers.cmake | 41 +++++++++++++++++++ 3 files changed, 58 insertions(+) create mode 100644 tensorflow/lite/tools/cmake/modules/Findfp16_headers.cmake create mode 100644 tensorflow/lite/tools/cmake/modules/fp16_headers.cmake diff --git a/tensorflow/lite/CMakeLists.txt b/tensorflow/lite/CMakeLists.txt index 24d405a47ff..494992a523f 100644 --- a/tensorflow/lite/CMakeLists.txt +++ b/tensorflow/lite/CMakeLists.txt @@ -206,6 +206,7 @@ endif() if(TFLITE_ENABLE_GPU) find_package(opencl_headers REQUIRED) find_package(vulkan_headers REQUIRED) + find_package(fp16_headers REQUIRED) # Android NDK already has OpenGL, EGL headers. if(NOT "${CMAKE_SYSTEM_NAME}" STREQUAL "Android") find_package(opengl_headers REQUIRED) diff --git a/tensorflow/lite/tools/cmake/modules/Findfp16_headers.cmake b/tensorflow/lite/tools/cmake/modules/Findfp16_headers.cmake new file mode 100644 index 00000000000..269276558ad --- /dev/null +++ b/tensorflow/lite/tools/cmake/modules/Findfp16_headers.cmake @@ -0,0 +1,16 @@ +# +# Copyright 2021 The TensorFlow Authors. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +include(fp16_headers) diff --git a/tensorflow/lite/tools/cmake/modules/fp16_headers.cmake b/tensorflow/lite/tools/cmake/modules/fp16_headers.cmake new file mode 100644 index 00000000000..bc144cd27a2 --- /dev/null +++ b/tensorflow/lite/tools/cmake/modules/fp16_headers.cmake @@ -0,0 +1,41 @@ +# +# Copyright 2021 The TensorFlow Authors. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# Skip installation when xnnpack is used since it also has fp16 headers. +if(TARGET fp16_headers OR fp16_headers_POPULATED OR TFLITE_ENABLE_XNNPACK) + return() +endif() + +include(FetchContent) + +OverridableFetchContent_Declare( + fp16_headers + GIT_REPOSITORY https://github.com/Maratyszcza/FP16 + # GIT_TAG must keep in sync with https://github.com/google/XNNPACK/blob/master/cmake/DownloadFP16.cmake + GIT_TAG 3c54eacb74f6f5e39077300c5564156c424d77ba + GIT_PROGRESS TRUE + PREFIX "${CMAKE_BINARY_DIR}" + SOURCE_DIR "${CMAKE_BINARY_DIR}/fp16_headers" +) + +OverridableFetchContent_GetProperties(fp16_headers) +if(NOT fp16_headers) + OverridableFetchContent_Populate(fp16_headers) +endif() + +include_directories( + AFTER + "${fp16_headers_SOURCE_DIR}/include" +)