Fix TF-Lite annoyances
1. Use release build by default, otherwise it is ~60x slower
2. Fix static build with TF-Lite
BUG=aomedia:2613
Change-Id: I3d5ef30cd63b8944944888f9d16dca87d99fab4d
diff --git a/build/cmake/tensorflow_lite.cmake b/build/cmake/tensorflow_lite.cmake
index 5db1aee..c76e343 100644
--- a/build/cmake/tensorflow_lite.cmake
+++ b/build/cmake/tensorflow_lite.cmake
@@ -71,7 +71,6 @@
# "experiment_requires_tf_lite" function.
function(target_link_tf_lite_libraries named_target)
target_link_libraries(${named_target} ${AOM_LIB_LINK_TYPE} Threads::Threads)
- target_link_libraries(${named_target} PRIVATE ${CMAKE_DL_LIBS})
target_link_tf_lite_dep_(${named_target} "" tensorflow-lite)
target_link_tf_lite_dep_(${named_target} _deps/abseil-cpp-build/absl/flags/
absl_flags)
@@ -147,6 +146,7 @@
target_link_tf_lite_dep_(${named_target} _deps/fft2d-build/ fft2d_fftsg2d)
target_link_tf_lite_dep_(${named_target} _deps/fft2d-build/ fft2d_fftsg)
target_link_tf_lite_dep_(${named_target} _deps/flatbuffers-build/ flatbuffers)
+ target_link_tf_lite_dep_(${named_target} _deps/xnnpack-build/ XNNPACK)
target_link_tf_lite_dep_(${named_target} _deps/ruy-build/ ruy)
endfunction()
@@ -195,6 +195,7 @@
PREFIX "${CMAKE_BINARY_DIR}/tensorflow_lite"
BINARY_DIR "${CMAKE_BINARY_DIR}/tensorflow_lite"
DOWNLOAD_DIR "${CMAKE_BINARY_DIR}/tensorflow_lite"
+ CMAKE_ARGS "-DCMAKE_BUILD_TYPE=Release"
LOG_BUILD 1)
# TF-Lite depends on this, and downloads it during compilation.
diff --git a/common/tf_lite_includes.h b/common/tf_lite_includes.h
index e28adbe..7ea2b1c 100644
--- a/common/tf_lite_includes.h
+++ b/common/tf_lite_includes.h
@@ -12,6 +12,8 @@
#ifndef AOM_COMMON_TF_LITE_INCLUDES_H_
#define AOM_COMMON_TF_LITE_INCLUDES_H_
+#include <assert.h>
+
// TensorFlow Lite has several unused parameters that are
// exposed as part of the API. In the AOM build process, this
// will cause failures when -Wunused-parameter is set.
@@ -28,4 +30,31 @@
#pragma GCC diagnostic pop
+// TensorFlow Lite uses dlsym and dlopen when using delegates,
+// e.g., GPU or TPU processing. Static builds of the AOM encoder
+// do not support linking with -ldl. Define dummy functions
+// to allow linking. Do not use delegation with TensorFlow Lite.
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+void *dlopen(const char *filename, int flags) {
+ (void)filename;
+ (void)flags;
+ assert(0);
+ return NULL;
+}
+
+void *dlsym(void *handle, const char *symbol) {
+ (void)handle;
+ (void)symbol;
+ assert(0);
+ return NULL;
+}
+
+#ifdef __cplusplus
+} // extern "C"
+#endif
+
#endif // AOM_COMMON_TF_LITE_INCLUDES_H_