Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
From 43667263bae2983f3a437ca8025f65d42b0fa5ea Mon Sep 17 00:00:00 2001
From: James Hilliard <james.hilliard1@gmail.com>
Date: Mon, 18 Sep 2023 10:34:56 -0600
Subject: [PATCH 1/8] lite: Add config option to enable benchmark_model

It's handy to have an option to enable the benchmark_model tool
so that it can be built and installed using the all target which
is preferable in some cases when packaging tensorflow-lite.

Upstream-Status: Backport [c9a1cecffceb96bc1a116c62039cb893f65120d4]
Signed-off-by: James Hilliard <james.hilliard1@gmail.com>
---
tensorflow/lite/CMakeLists.txt | 1 +
tensorflow/lite/tools/benchmark/CMakeLists.txt | 9 ++++++++-
2 files changed, 9 insertions(+), 1 deletion(-)

diff --git a/tensorflow/lite/CMakeLists.txt b/tensorflow/lite/CMakeLists.txt
index 3198ec61e0b..cdd38ff2086 100644
--- a/tensorflow/lite/CMakeLists.txt
+++ b/tensorflow/lite/CMakeLists.txt
@@ -64,6 +64,7 @@ include(GNUInstallDirs)
include(CMakeDependentOption)
option(TFLITE_ENABLE_INSTALL "Enable install rule" OFF)
option(TFLITE_ENABLE_LABEL_IMAGE "Enable label_image example" OFF)
+option(TFLITE_ENABLE_BENCHMARK_MODEL "Enable the benchmark_model tool" OFF)
option(TFLITE_ENABLE_RUY "Enable experimental RUY integration" OFF)
option(TFLITE_ENABLE_RESOURCE "Enable experimental support for resources" ON)
option(TFLITE_ENABLE_NNAPI "Enable NNAPI (Android only)." ON)
diff --git a/tensorflow/lite/tools/benchmark/CMakeLists.txt b/tensorflow/lite/tools/benchmark/CMakeLists.txt
index 79986f6c0ec..2b639475481 100644
--- a/tensorflow/lite/tools/benchmark/CMakeLists.txt
+++ b/tensorflow/lite/tools/benchmark/CMakeLists.txt
@@ -95,9 +95,16 @@ if(TFLITE_ENABLE_GPU)
endif() # TFLITE_ENABLE_GPU

add_executable(benchmark_model
- EXCLUDE_FROM_ALL
${TFLITE_BENCHMARK_SRCS}
)
+if(TFLITE_ENABLE_BENCHMARK_MODEL)
+ set_target_properties(benchmark_model PROPERTIES EXCLUDE_FROM_ALL FALSE)
+ if(TFLITE_ENABLE_INSTALL)
+ install(TARGETS benchmark_model)
+ endif() # TFLITE_ENABLE_INSTALL
+else()
+ set_target_properties(benchmark_model PROPERTIES EXCLUDE_FROM_ALL TRUE)
+endif() # TFLITE_ENABLE_BENCHMARK_MODEL
target_compile_options(benchmark_model
PRIVATE
${TFLITE_BENCHMARK_CC_OPTIONS}
--
2.34.1

Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
From 62a151b7d653fc781575d2eb28d8836124b88288 Mon Sep 17 00:00:00 2001
From: Koen Kooi <koen.kooi@oss.qualcomm.com>
Date: Thu, 9 Oct 2025 18:11:16 +0200
Subject: [PATCH 2/8] cmake: lite/tools/benchmark: require protobuf through
find-package

The tools needs headers for building and the library for linking, so
have cmake find the things it needs.

Upstream-Status: Submitted [https://github.com/tensorflow/tensorflow/pull/109375]
Signed-off-by: Koen Kooi <koen.kooi@oss.qualcomm.com>
---
tensorflow/lite/tools/benchmark/CMakeLists.txt | 2 ++
1 file changed, 2 insertions(+)

diff --git a/tensorflow/lite/tools/benchmark/CMakeLists.txt b/tensorflow/lite/tools/benchmark/CMakeLists.txt
index 2b639475481..4eb63985922 100644
--- a/tensorflow/lite/tools/benchmark/CMakeLists.txt
+++ b/tensorflow/lite/tools/benchmark/CMakeLists.txt
@@ -16,6 +16,8 @@

# The benchmark tool for Tensorflow Lite.

+find_package(Protobuf REQUIRED)
+
populate_source_vars("${TFLITE_SOURCE_DIR}/tools/benchmark"
TFLITE_BENCHMARK_SRCS
FILTER "(_test|_plus_flex_main|_performance_options.*)\\.cc$"
--
2.34.1

Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
From 2147ad715d6da173c22f3ece340fe684d4f4fbb5 Mon Sep 17 00:00:00 2001
From: Tushar Darote <quic_tdarote@quicinc.com>
Date: Thu, 9 Oct 2025 22:42:17 +0200
Subject: [PATCH 3/8] feat(tflite): Add dynamic OpenCL library loading support

Use pkg-config to detect OpenCL installation and set library name based on
OpenCL version. Pass library name as compile-time definition to OpenCL wrapper
and modify wrapper to use configured name instead of hardcoded defaults.
This fixes OpenCL library loading issues on systems with non-standard
installations and various Linux distributions.

Upstream-Status: Submitted [https://github.com/tensorflow/tensorflow/pull/109377]
Signed-off-by: Tushar Darote <quic_tdarote@quicinc.com>
---
tensorflow/lite/CMakeLists.txt | 14 ++++++++++++++
tensorflow/lite/delegates/gpu/cl/opencl_wrapper.cc | 2 +-
2 files changed, 15 insertions(+), 1 deletion(-)

diff --git a/tensorflow/lite/CMakeLists.txt b/tensorflow/lite/CMakeLists.txt
index cdd38ff2086..2971047b3fc 100644
--- a/tensorflow/lite/CMakeLists.txt
+++ b/tensorflow/lite/CMakeLists.txt
@@ -746,6 +746,20 @@ if (NOT BUILD_SHARED_LIBS)
list(APPEND TFLITE_TARGET_PUBLIC_OPTIONS "-DTFL_STATIC_LIBRARY_BUILD")
endif()

+find_package(PkgConfig)
+pkg_check_modules(OPENCL opencl)
+
+if(OPENCL_FOUND)
+ string(REGEX MATCH "^[0-9]+" OPENCL_VERSION_MAJOR ${OPENCL_VERSION})
+ set(CL_LIB_NAME "libOpenCL.so.${OPENCL_VERSION_MAJOR}")
+else()
+ set(CL_LIB_NAME "libOpenCL.so")
+endif()
+
+target_compile_definitions(tensorflow-lite
+ PRIVATE CL_LIB_NAME=\"${CL_LIB_NAME}\"
+)
+
target_compile_options(tensorflow-lite
PUBLIC ${TFLITE_TARGET_PUBLIC_OPTIONS}
PRIVATE ${TFLITE_TARGET_PRIVATE_OPTIONS}
diff --git a/tensorflow/lite/delegates/gpu/cl/opencl_wrapper.cc b/tensorflow/lite/delegates/gpu/cl/opencl_wrapper.cc
index 2eb95df35ae..b8229ec1f96 100644
--- a/tensorflow/lite/delegates/gpu/cl/opencl_wrapper.cc
+++ b/tensorflow/lite/delegates/gpu/cl/opencl_wrapper.cc
@@ -119,7 +119,7 @@ absl::Status LoadOpenCLOnce() {
static const char* kClLibName =
"/System/Library/Frameworks/OpenCL.framework/OpenCL";
#else
- static const char* kClLibName = "libOpenCL.so";
+ static const char* kClLibName = CL_LIB_NAME;
#endif
#ifdef __ANDROID__
libopencl = AndroidDlopenSphalLibrary(kClLibName, RTLD_NOW | RTLD_LOCAL);
--
2.34.1

Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
From cace63b517b282943a7bef9ea5020798b70ca5df Mon Sep 17 00:00:00 2001
From: Tushar Darote <quic_tdarote@quicinc.com>
Date: Thu, 29 Jan 2026 18:18:00 +0530
Subject: [PATCH 4/8] cmake: Exclude subdirectories from all builds

Add EXCLUDE_FROM_ALL to add_subdirectory() calls in multiple CMake
modules to prevent unnecessary compilation of third-party dependencies
during default builds. This reduces build time and resource usage.

- eigen.cmake
- farmhash.cmake
- fft2d.cmake
- flatbuffers.cmake
- gemmlowp.cmake
- neon2sse.cmake
- ruy.cmake

Upstream-Status: Submitted [https://github.com/tensorflow/tensorflow/pull/109378]
Signed-off-by: Tushar Darote <quic_tdarote@quicinc.com>
---
tensorflow/lite/tools/cmake/modules/cpuinfo.cmake | 1 +
tensorflow/lite/tools/cmake/modules/eigen.cmake | 2 +-
tensorflow/lite/tools/cmake/modules/farmhash.cmake | 1 +
tensorflow/lite/tools/cmake/modules/fft2d.cmake | 1 +
tensorflow/lite/tools/cmake/modules/flatbuffers.cmake | 1 +
tensorflow/lite/tools/cmake/modules/gemmlowp.cmake | 1 +
tensorflow/lite/tools/cmake/modules/neon2sse.cmake | 1 +
tensorflow/lite/tools/cmake/modules/ruy.cmake | 1 +
8 files changed, 8 insertions(+), 1 deletion(-)

diff --git a/tensorflow/lite/tools/cmake/modules/cpuinfo.cmake b/tensorflow/lite/tools/cmake/modules/cpuinfo.cmake
index 5556bec6448..8d1124ff261 100644
--- a/tensorflow/lite/tools/cmake/modules/cpuinfo.cmake
+++ b/tensorflow/lite/tools/cmake/modules/cpuinfo.cmake
@@ -41,4 +41,5 @@ set(CPUINFO_BUILD_BENCHMARKS OFF CACHE BOOL "Disable cpuinfo micro-benchmarks")
add_subdirectory(
"${cpuinfo_SOURCE_DIR}"
"${cpuinfo_BINARY_DIR}"
+ EXCLUDE_FROM_ALL
)
diff --git a/tensorflow/lite/tools/cmake/modules/eigen.cmake b/tensorflow/lite/tools/cmake/modules/eigen.cmake
index cf73d72fb32..c2ffd3f3d78 100644
--- a/tensorflow/lite/tools/cmake/modules/eigen.cmake
+++ b/tensorflow/lite/tools/cmake/modules/eigen.cmake
@@ -99,4 +99,4 @@ set(EIGEN_TEST_SYCL OFF CACHE BOOL "Disable Sycl test")
set(EIGEN_SYCL_TRISYCL OFF CACHE BOOL "Disable triSYCL test")
# Make sure only MPL2.0 or more permissively licensed code is included.
add_compile_definitions(EIGEN_MPL2_ONLY)
-add_subdirectory("${eigen_SOURCE_DIR}" "${eigen_BINARY_DIR}")
+add_subdirectory("${eigen_SOURCE_DIR}" "${eigen_BINARY_DIR}" EXCLUDE_FROM_ALL)
diff --git a/tensorflow/lite/tools/cmake/modules/farmhash.cmake b/tensorflow/lite/tools/cmake/modules/farmhash.cmake
index 9c8e039e6fe..7a5160fa7eb 100644
--- a/tensorflow/lite/tools/cmake/modules/farmhash.cmake
+++ b/tensorflow/lite/tools/cmake/modules/farmhash.cmake
@@ -44,4 +44,5 @@ set(FARMHASH_SOURCE_DIR "${farmhash_SOURCE_DIR}" CACHE PATH
add_subdirectory(
"${CMAKE_CURRENT_LIST_DIR}/farmhash"
"${farmhash_BINARY_DIR}"
+ EXCLUDE_FROM_ALL
)
diff --git a/tensorflow/lite/tools/cmake/modules/fft2d.cmake b/tensorflow/lite/tools/cmake/modules/fft2d.cmake
index b4169104fae..9d44a2c6865 100644
--- a/tensorflow/lite/tools/cmake/modules/fft2d.cmake
+++ b/tensorflow/lite/tools/cmake/modules/fft2d.cmake
@@ -37,4 +37,5 @@ set(FFT2D_SOURCE_DIR "${fft2d_SOURCE_DIR}" CACHE PATH "fft2d source")
add_subdirectory(
"${CMAKE_CURRENT_LIST_DIR}/fft2d"
"${fft2d_BINARY_DIR}"
+ EXCLUDE_FROM_ALL
)
diff --git a/tensorflow/lite/tools/cmake/modules/flatbuffers.cmake b/tensorflow/lite/tools/cmake/modules/flatbuffers.cmake
index 8febb1fbd1c..267031de68f 100644
--- a/tensorflow/lite/tools/cmake/modules/flatbuffers.cmake
+++ b/tensorflow/lite/tools/cmake/modules/flatbuffers.cmake
@@ -42,6 +42,7 @@ add_definitions(-DNOMINMAX=1)
add_subdirectory(
"${flatbuffers_SOURCE_DIR}"
"${flatbuffers_BINARY_DIR}"
+ EXCLUDE_FROM_ALL
)
remove_definitions(-DNOMINMAX)

diff --git a/tensorflow/lite/tools/cmake/modules/gemmlowp.cmake b/tensorflow/lite/tools/cmake/modules/gemmlowp.cmake
index 76d9705475b..9c8e2c90c7c 100644
--- a/tensorflow/lite/tools/cmake/modules/gemmlowp.cmake
+++ b/tensorflow/lite/tools/cmake/modules/gemmlowp.cmake
@@ -48,6 +48,7 @@ set(GEMMLOWP_SOURCE_DIR "${gemmlowp_SOURCE_DIR}" CACHE PATH "Source directory")
add_subdirectory(
"${gemmlowp_SOURCE_DIR}/contrib"
"${gemmlowp_BINARY_DIR}"
+ EXCLUDE_FROM_ALL
)

set(BUILD_TESTING ${BUILD_TESTING_TMP})
diff --git a/tensorflow/lite/tools/cmake/modules/neon2sse.cmake b/tensorflow/lite/tools/cmake/modules/neon2sse.cmake
index c2612e34bd2..77bcf1acba3 100644
--- a/tensorflow/lite/tools/cmake/modules/neon2sse.cmake
+++ b/tensorflow/lite/tools/cmake/modules/neon2sse.cmake
@@ -40,4 +40,5 @@ endif()
add_subdirectory(
"${neon2sse_SOURCE_DIR}"
"${neon2sse_BINARY_DIR}"
+ EXCLUDE_FROM_ALL
)
diff --git a/tensorflow/lite/tools/cmake/modules/ruy.cmake b/tensorflow/lite/tools/cmake/modules/ruy.cmake
index 1c5965f94f5..a6632d3247f 100644
--- a/tensorflow/lite/tools/cmake/modules/ruy.cmake
+++ b/tensorflow/lite/tools/cmake/modules/ruy.cmake
@@ -37,4 +37,5 @@ set(RUY_SOURCE_DIR "${ruy_SOURCE_DIR}" CACHE PATH "RUY source directory")
add_subdirectory(
"${ruy_SOURCE_DIR}"
"${ruy_BINARY_DIR}"
+ EXCLUDE_FROM_ALL
)
--
2.34.1

Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
From ff734642f6fd77553746c90347e04fc33a439525 Mon Sep 17 00:00:00 2001
From: Tushar Darote <quic_tdarote@quicinc.com>
Date: Thu, 29 Jan 2026 18:25:22 +0530
Subject: [PATCH 5/8] c: Force delegate symbols from shared library

Add linker options to ensure delegate create/delete functions are resolved
from shared libraries rather than statically linked. Handles XNNPACK, external
delegate, and GPU delegates with platform-specific flags for Windows, macOS,
and Linux.

Upstream-Status: Submitted [https://github.com/tensorflow/tensorflow/pull/109379]
Signed-off-by: Tushar Darote <quic_tdarote@quicinc.com>
---
tensorflow/lite/c/CMakeLists.txt | 42 ++++++++++++++++++++++++++++++++
1 file changed, 42 insertions(+)

diff --git a/tensorflow/lite/c/CMakeLists.txt b/tensorflow/lite/c/CMakeLists.txt
index 931f4372c5f..9fcafb14495 100644
--- a/tensorflow/lite/c/CMakeLists.txt
+++ b/tensorflow/lite/c/CMakeLists.txt
@@ -80,10 +80,52 @@ if (TFLITE_C_BUILD_SHARED_LIBS)
if (WIN32)
target_compile_definitions(tensorflowlite_c PRIVATE TFL_COMPILE_LIBRARY)
target_compile_definitions(tensorflow-lite PRIVATE TFL_COMPILE_LIBRARY)
+ # Force the linker to treat delegate create and delete as undefined
+ # to pull them from static to shared library
+ if (TFLITE_ENABLE_XNNPACK)
+ target_link_options(tensorflowlite_c PRIVATE "/INCLUDE:TfLiteXNNPackDelegateCreate")
+ target_link_options(tensorflowlite_c PRIVATE "/INCLUDE:TfLiteXNNPackDelegateDelete")
+ endif()
+ if (TFLITE_ENABLE_EXTERNAL_DELEGATE)
+ target_link_options(tensorflowlite_c PRIVATE "/INCLUDE:TfLiteExternalDelegateCreate")
+ target_link_options(tensorflowlite_c PRIVATE "/INCLUDE:TfLiteExternalDelegateDelete")
+ endif()
+ if (CMAKE_SYSTEM_NAME MATCHES "Android" OR TFLITE_ENABLE_GPU)
+ target_link_options(tensorflowlite_c PRIVATE "/INCLUDE:TfLiteGpuDelegateV2Create")
+ target_link_options(tensorflowlite_c PRIVATE "/INCLUDE:TfLiteGpuDelegateV2Delete")
+ endif()
elseif (APPLE)
target_link_options(tensorflowlite_c PRIVATE "-Wl,-exported_symbols_list,${TFLITE_SOURCE_DIR}/c/exported_symbols.lds")
+ # Force the linker to treat delegate create and delete as undefined
+ # to pull them from static to shared library
+ if (TFLITE_ENABLE_XNNPACK)
+ target_link_options(tensorflowlite_c PRIVATE "-Wl,-u,_TfLiteXNNPackDelegateCreate")
+ target_link_options(tensorflowlite_c PRIVATE "-Wl,-u,_TfLiteXNNPackDelegateDelete")
+ endif()
+ if (TFLITE_ENABLE_EXTERNAL_DELEGATE)
+ target_link_options(tensorflowlite_c PRIVATE "-Wl,-u,_TfLiteExternalDelegateCreate")
+ target_link_options(tensorflowlite_c PRIVATE "-Wl,-u,_TfLiteExternalDelegateDelete")
+ endif()
+ if (CMAKE_SYSTEM_NAME MATCHES "Android" OR TFLITE_ENABLE_GPU)
+ target_link_options(tensorflowlite_c PRIVATE "-Wl,-u,_TfLiteGpuDelegateV2Create")
+ target_link_options(tensorflowlite_c PRIVATE "-Wl,-u,_TfLiteGpuDelegateV2Delete")
+ endif()
else ()
target_link_options(tensorflowlite_c PRIVATE "-Wl,--version-script,${TFLITE_SOURCE_DIR}/c/version_script.lds")
+ # Force the linker to treat delegate create and delete as undefined
+ # to pull them from static to shared library
+ if (TFLITE_ENABLE_XNNPACK)
+ target_link_options(tensorflowlite_c PRIVATE "-Wl,-u,TfLiteXNNPackDelegateCreate")
+ target_link_options(tensorflowlite_c PRIVATE "-Wl,-u,TfLiteXNNPackDelegateDelete")
+ endif()
+ if (TFLITE_ENABLE_EXTERNAL_DELEGATE)
+ target_link_options(tensorflowlite_c PRIVATE "-Wl,-u,TfLiteExternalDelegateCreate")
+ target_link_options(tensorflowlite_c PRIVATE "-Wl,-u,TfLiteExternalDelegateDelete")
+ endif()
+ if (CMAKE_SYSTEM_NAME MATCHES "Android" OR TFLITE_ENABLE_GPU)
+ target_link_options(tensorflowlite_c PRIVATE "-Wl,-u,TfLiteGpuDelegateV2Create")
+ target_link_options(tensorflowlite_c PRIVATE "-Wl,-u,TfLiteGpuDelegateV2Delete")
+ endif()
endif()
endif()

--
2.34.1

Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
From 6cd1fa0fad9cb5d0933b8c46ff687f4d6c67ba26 Mon Sep 17 00:00:00 2001
From: Tushar Darote <quic_tdarote@quicinc.com>
Date: Thu, 29 Jan 2026 18:54:32 +0530
Subject: [PATCH 6/8] c: Add version support to C API

Set up version handling with compile definitions for major, minor, and patch
versions. Configure shared library properties with version and soversion
for proper C API versioning.

Upstream-Status: Submitted [https://github.com/tensorflow/tensorflow/pull/109380]
Signed-off-by: Tushar Darote <quic_tdarote@quicinc.com>
---
tensorflow/lite/c/CMakeLists.txt | 22 +++++++++++++++++++++-
1 file changed, 21 insertions(+), 1 deletion(-)

diff --git a/tensorflow/lite/c/CMakeLists.txt b/tensorflow/lite/c/CMakeLists.txt
index 9fcafb14495..7d9a5942cab 100644
--- a/tensorflow/lite/c/CMakeLists.txt
+++ b/tensorflow/lite/c/CMakeLists.txt
@@ -14,7 +14,22 @@
# limitations under the License.

cmake_minimum_required(VERSION 3.16)
-project(tensorflow-lite-c C CXX)
+
+set(TF_MAJOR_VERSION "" CACHE STRING "TensorFlow Lite major version")
+set(TF_MINOR_VERSION "" CACHE STRING "TensorFlow Lite minor version")
+set(TF_PATCH_VERSION "" CACHE STRING "TensorFlow Lite patch version")
+set(TF_VERSION_SUFFIX "" CACHE STRING "TensorFlow Lite version suffix")
+
+project(tensorflow-lite-c
+ VERSION "${TF_MAJOR_VERSION}.${TF_MINOR_VERSION}.${TF_PATCH_VERSION}${TF_VERSION_SUFFIX}"
+ LANGUAGES C CXX)
+
+add_compile_definitions(
+ TF_MAJOR_VERSION=${TF_MAJOR_VERSION}
+ TF_MINOR_VERSION=${TF_MINOR_VERSION}
+ TF_PATCH_VERSION=${TF_PATCH_VERSION}
+ TF_VERSION_SUFFIX="${TF_VERSION_SUFFIX}"
+)

option(TFLITE_C_BUILD_SHARED_LIBS "Build shared libraries" ON)

@@ -129,6 +144,11 @@ if (TFLITE_C_BUILD_SHARED_LIBS)
endif()
endif()

+set_target_properties(tensorflowlite_c PROPERTIES
+ VERSION "${TF_MAJOR_VERSION}.${TF_MINOR_VERSION}.${TF_PATCH_VERSION}${TF_VERSION_SUFFIX}"
+ SOVERSION ${TF_MAJOR_VERSION}
+)
+
target_link_libraries(tensorflowlite_c
tensorflow-lite
)
--
2.34.1

Loading
Loading