1*89c4ff92SAndroid Build Coastguard Worker# 2*89c4ff92SAndroid Build Coastguard Worker# Copyright © 2020, 2023 Arm Ltd and Contributors. All rights reserved. 3*89c4ff92SAndroid Build Coastguard Worker# SPDX-License-Identifier: MIT 4*89c4ff92SAndroid Build Coastguard Worker# 5*89c4ff92SAndroid Build Coastguard Worker 6*89c4ff92SAndroid Build Coastguard Workerinclude(FindPackageHandleStandardArgs) 7*89c4ff92SAndroid Build Coastguard Workerunset(TFLITE_FOUND) 8*89c4ff92SAndroid Build Coastguard Worker 9*89c4ff92SAndroid Build Coastguard Worker# 10*89c4ff92SAndroid Build Coastguard Worker# NOTE: this module is used to find the tensorflow lite binary libraries only 11*89c4ff92SAndroid Build Coastguard Worker# the FindTfLiteSrc.cmake module is used to find the tensorflow lite include directory. 12*89c4ff92SAndroid Build Coastguard Worker# This is to allow components like the Tensorflow lite parser that have a source dependency 13*89c4ff92SAndroid Build Coastguard Worker# on tensorflow lite headers but no need to link to the binary libraries to use only the sources 14*89c4ff92SAndroid Build Coastguard Worker# and not have an artificial dependency on the libraries. 15*89c4ff92SAndroid Build Coastguard Worker# 16*89c4ff92SAndroid Build Coastguard Worker 17*89c4ff92SAndroid Build Coastguard Worker# First look for the static version of tensorflow lite 18*89c4ff92SAndroid Build Coastguard Workerfind_library(TfLite_LIB NAMES "libtensorflow-lite.a" HINTS ${TFLITE_LIB_ROOT} ${TFLITE_LIB_ROOT}/tensorflow/lite) 19*89c4ff92SAndroid Build Coastguard Worker# If not found then, look for the dynamic library of tensorflow lite 20*89c4ff92SAndroid Build Coastguard Workerfind_library(TfLite_LIB NAMES "libtensorflow_lite_all.so" "libtensorflowlite.so" HINTS ${TFLITE_LIB_ROOT} ${TFLITE_LIB_ROOT}/tensorflow/lite) 21*89c4ff92SAndroid Build Coastguard Worker 22*89c4ff92SAndroid Build Coastguard Worker# If the static library was found, gather all of its dependencies 23*89c4ff92SAndroid Build Coastguard Workerif (TfLite_LIB MATCHES .a$) 24*89c4ff92SAndroid Build Coastguard Worker message("-- Static tensorflow lite library found, using for ArmNN build") 25*89c4ff92SAndroid Build Coastguard Worker find_library(TfLite_abseilstrings_LIB "libabsl_strings.a" 26*89c4ff92SAndroid Build Coastguard Worker PATH ${TFLITE_LIB_ROOT}/_deps/abseil-cpp-build/absl/strings) 27*89c4ff92SAndroid Build Coastguard Worker find_library(TfLite_abseil_synchronization_LIB "libabsl_synchronization.a" 28*89c4ff92SAndroid Build Coastguard Worker PATH ${TFLITE_LIB_ROOT}/_deps/abseil-cpp-build/absl/synchronization) 29*89c4ff92SAndroid Build Coastguard Worker 30*89c4ff92SAndroid Build Coastguard Worker 31*89c4ff92SAndroid Build Coastguard Worker find_library(TfLite_farmhash_LIB "libfarmhash.a" 32*89c4ff92SAndroid Build Coastguard Worker PATH ${TFLITE_LIB_ROOT}/_deps/farmhash-build) 33*89c4ff92SAndroid Build Coastguard Worker find_library(TfLite_fftsg_LIB "libfft2d_fftsg.a" 34*89c4ff92SAndroid Build Coastguard Worker PATH ${TFLITE_LIB_ROOT}/_deps/fft2d-build) 35*89c4ff92SAndroid Build Coastguard Worker find_library(TfLite_fftsg2d_LIB "libfft2d_fftsg2d.a" 36*89c4ff92SAndroid Build Coastguard Worker PATH ${TFLITE_LIB_ROOT}/_deps/fft2d-build) 37*89c4ff92SAndroid Build Coastguard Worker find_library(TfLite_flatbuffers_LIB "libflatbuffers.a" 38*89c4ff92SAndroid Build Coastguard Worker PATH ${TFLITE_LIB_ROOT}/_deps/flatbuffers-build) 39*89c4ff92SAndroid Build Coastguard Worker find_library(TfLite_cpuinfo_LIB "libcpuinfo.a" PATH 40*89c4ff92SAndroid Build Coastguard Worker ${TFLITE_LIB_ROOT}/_deps/cpuinfo-build) 41*89c4ff92SAndroid Build Coastguard Worker 42*89c4ff92SAndroid Build Coastguard Worker # All remaining libraries are part of libruy. 43*89c4ff92SAndroid Build Coastguard Worker find_library(TfLite_ruy_allocator_LIB "libruy_allocator.a" PATH 44*89c4ff92SAndroid Build Coastguard Worker ${TFLITE_LIB_ROOT}/_deps/ruy-build/ruy) 45*89c4ff92SAndroid Build Coastguard Worker find_library(TfLite_ruy_apply_multiplier_LIB "libruy_apply_multiplier.a" PATH 46*89c4ff92SAndroid Build Coastguard Worker ${TFLITE_LIB_ROOT}/_deps/ruy-build/ruy) 47*89c4ff92SAndroid Build Coastguard Worker find_library(TfLite_ruy_blocking_counter_LIB "libruy_blocking_counter.a" PATH 48*89c4ff92SAndroid Build Coastguard Worker ${TFLITE_LIB_ROOT}/_deps/ruy-build/ruy) 49*89c4ff92SAndroid Build Coastguard Worker find_library(TfLite_ruy_block_map_LIB "libruy_block_map.a" PATH 50*89c4ff92SAndroid Build Coastguard Worker ${TFLITE_LIB_ROOT}/_deps/ruy-build/ruy) 51*89c4ff92SAndroid Build Coastguard Worker find_library(TfLite_ruy_context_LIB "libruy_context.a" PATH 52*89c4ff92SAndroid Build Coastguard Worker ${TFLITE_LIB_ROOT}/_deps/ruy-build/ruy) 53*89c4ff92SAndroid Build Coastguard Worker find_library(TfLite_ruy_context_get_ctx_LIB "libruy_context_get_ctx.a" PATH 54*89c4ff92SAndroid Build Coastguard Worker ${TFLITE_LIB_ROOT}/_deps/ruy-build/ruy) 55*89c4ff92SAndroid Build Coastguard Worker find_library(TfLite_ruy_cpuinfo_LIB "libruy_cpuinfo.a" PATH 56*89c4ff92SAndroid Build Coastguard Worker ${TFLITE_LIB_ROOT}/_deps/ruy-build/ruy) 57*89c4ff92SAndroid Build Coastguard Worker find_library(TfLite_ruy_ctx_LIB "libruy_ctx.a" PATH 58*89c4ff92SAndroid Build Coastguard Worker ${TFLITE_LIB_ROOT}/_deps/ruy-build/ruy) 59*89c4ff92SAndroid Build Coastguard Worker find_library(TfLite_ruy_denormal_LIB "libruy_denormal.a" PATH 60*89c4ff92SAndroid Build Coastguard Worker ${TFLITE_LIB_ROOT}/_deps/ruy-build/ruy) 61*89c4ff92SAndroid Build Coastguard Worker find_library(TfLite_ruy_frontend_LIB "libruy_frontend.a" PATH 62*89c4ff92SAndroid Build Coastguard Worker ${TFLITE_LIB_ROOT}/_deps/ruy-build/ruy) 63*89c4ff92SAndroid Build Coastguard Worker find_library(TfLite_ruy_have_built_path_for_avx2_fma_LIB "libruy_have_built_path_for_avx2_fma.a" PATH 64*89c4ff92SAndroid Build Coastguard Worker ${TFLITE_LIB_ROOT}/_deps/ruy-build/ruy) 65*89c4ff92SAndroid Build Coastguard Worker find_library(TfLite_ruy_have_built_path_for_avx512_LIB "libruy_have_built_path_for_avx512.a" PATH 66*89c4ff92SAndroid Build Coastguard Worker ${TFLITE_LIB_ROOT}/_deps/ruy-build/ruy) 67*89c4ff92SAndroid Build Coastguard Worker find_library(TfLite_ruy_have_built_path_for_avx_LIB "libruy_have_built_path_for_avx.a" PATH 68*89c4ff92SAndroid Build Coastguard Worker ${TFLITE_LIB_ROOT}/_deps/ruy-build/ruy) 69*89c4ff92SAndroid Build Coastguard Worker find_library(TfLite_ruy_kernel_arm_LIB "libruy_kernel_arm.a" PATH 70*89c4ff92SAndroid Build Coastguard Worker ${TFLITE_LIB_ROOT}/_deps/ruy-build/ruy) 71*89c4ff92SAndroid Build Coastguard Worker find_library(TfLite_ruy_kernel_avx2_fma_LIB "libruy_kernel_avx2_fma.a" PATH 72*89c4ff92SAndroid Build Coastguard Worker ${TFLITE_LIB_ROOT}/_deps/ruy-build/ruy) 73*89c4ff92SAndroid Build Coastguard Worker find_library(TfLite_ruy_kernel_avx512_LIB "libruy_kernel_avx512.a" PATH 74*89c4ff92SAndroid Build Coastguard Worker ${TFLITE_LIB_ROOT}/_deps/ruy-build/ruy) 75*89c4ff92SAndroid Build Coastguard Worker find_library(TfLite_ruy_kernel_avx_LIB "libruy_kernel_avx.a" PATH 76*89c4ff92SAndroid Build Coastguard Worker ${TFLITE_LIB_ROOT}/_deps/ruy-build/ruy) 77*89c4ff92SAndroid Build Coastguard Worker find_library(TfLite_ruy_pack_arm_LIB "libruy_pack_arm.a" PATH 78*89c4ff92SAndroid Build Coastguard Worker ${TFLITE_LIB_ROOT}/_deps/ruy-build/ruy) 79*89c4ff92SAndroid Build Coastguard Worker find_library(TfLite_ruy_pack_avx2_fma_LIB "libruy_pack_avx2_fma.a" PATH 80*89c4ff92SAndroid Build Coastguard Worker ${TFLITE_LIB_ROOT}/_deps/ruy-build/ruy) 81*89c4ff92SAndroid Build Coastguard Worker find_library(TfLite_ruy_pack_avx512_LIB "libruy_pack_avx512.a" PATH 82*89c4ff92SAndroid Build Coastguard Worker ${TFLITE_LIB_ROOT}/_deps/ruy-build/ruy) 83*89c4ff92SAndroid Build Coastguard Worker find_library(TfLite_ruy_pack_avx_LIB "libruy_pack_avx.a" PATH 84*89c4ff92SAndroid Build Coastguard Worker ${TFLITE_LIB_ROOT}/_deps/ruy-build/ruy) 85*89c4ff92SAndroid Build Coastguard Worker find_library(TfLite_ruy_prepacked_cache_LIB "libruy_prepacked_cache.a" PATH 86*89c4ff92SAndroid Build Coastguard Worker ${TFLITE_LIB_ROOT}/_deps/ruy-build/ruy) 87*89c4ff92SAndroid Build Coastguard Worker find_library(TfLite_ruy_prepare_packed_matrices_LIB "libruy_prepare_packed_matrices.a" PATH 88*89c4ff92SAndroid Build Coastguard Worker ${TFLITE_LIB_ROOT}/_deps/ruy-build/ruy) 89*89c4ff92SAndroid Build Coastguard Worker find_library(TfLite_ruy_system_aligned_alloc_LIB "libruy_system_aligned_alloc.a" PATH 90*89c4ff92SAndroid Build Coastguard Worker ${TFLITE_LIB_ROOT}/_deps/ruy-build/ruy) 91*89c4ff92SAndroid Build Coastguard Worker find_library(TfLite_ruy_threadpool_LIB "libruy_thread_pool.a" PATH 92*89c4ff92SAndroid Build Coastguard Worker ${TFLITE_LIB_ROOT}/_deps/ruy-build/ruy) 93*89c4ff92SAndroid Build Coastguard Worker find_library(TfLite_ruy_trmul_LIB "libruy_trmul.a" PATH 94*89c4ff92SAndroid Build Coastguard Worker ${TFLITE_LIB_ROOT}/_deps/ruy-build/ruy) 95*89c4ff92SAndroid Build Coastguard Worker find_library(TfLite_ruy_tune_LIB "libruy_tune.a" PATH 96*89c4ff92SAndroid Build Coastguard Worker ${TFLITE_LIB_ROOT}/_deps/ruy-build/ruy) 97*89c4ff92SAndroid Build Coastguard Worker find_library(TfLite_ruy_wait_LIB "libruy_wait.a" PATH 98*89c4ff92SAndroid Build Coastguard Worker ${TFLITE_LIB_ROOT}/_deps/ruy-build/ruy) 99*89c4ff92SAndroid Build Coastguard Worker find_library(TfLite_ruy_profiler_LIB "libruy_profiler_instrumentation.a" PATH 100*89c4ff92SAndroid Build Coastguard Worker ${TFLITE_LIB_ROOT}/_deps/ruy-build/ruy/profiler) 101*89c4ff92SAndroid Build Coastguard Worker find_library(TfLite_pthread_pool_LIB "libpthreadpool.a" PATH 102*89c4ff92SAndroid Build Coastguard Worker ${TFLITE_LIB_ROOT}/pthreadpool) 103*89c4ff92SAndroid Build Coastguard Worker 104*89c4ff92SAndroid Build Coastguard Worker ## Set TFLITE_FOUND if all libraries are satisfied for static lib 105*89c4ff92SAndroid Build Coastguard Worker find_package_handle_standard_args(TfLite DEFAULT_MSG TfLite_LIB TfLite_abseilstrings_LIB TfLite_farmhash_LIB TfLite_fftsg_LIB TfLite_fftsg2d_LIB 106*89c4ff92SAndroid Build Coastguard Worker TfLite_flatbuffers_LIB TfLite_ruy_allocator_LIB TfLite_ruy_apply_multiplier_LIB TfLite_ruy_blocking_counter_LIB 107*89c4ff92SAndroid Build Coastguard Worker TfLite_ruy_block_map_LIB TfLite_ruy_context_LIB TfLite_ruy_context_get_ctx_LIB TfLite_ruy_cpuinfo_LIB 108*89c4ff92SAndroid Build Coastguard Worker TfLite_ruy_ctx_LIB TfLite_ruy_denormal_LIB TfLite_ruy_frontend_LIB TfLite_ruy_have_built_path_for_avx2_fma_LIB 109*89c4ff92SAndroid Build Coastguard Worker TfLite_ruy_have_built_path_for_avx512_LIB TfLite_ruy_have_built_path_for_avx_LIB TfLite_ruy_kernel_arm_LIB 110*89c4ff92SAndroid Build Coastguard Worker TfLite_ruy_kernel_avx2_fma_LIB TfLite_ruy_kernel_avx512_LIB TfLite_ruy_kernel_avx_LIB TfLite_ruy_pack_arm_LIB 111*89c4ff92SAndroid Build Coastguard Worker TfLite_ruy_pack_avx2_fma_LIB TfLite_ruy_pack_avx512_LIB TfLite_ruy_pack_avx_LIB TfLite_ruy_prepacked_cache_LIB 112*89c4ff92SAndroid Build Coastguard Worker TfLite_ruy_prepare_packed_matrices_LIB TfLite_ruy_system_aligned_alloc_LIB TfLite_ruy_threadpool_LIB 113*89c4ff92SAndroid Build Coastguard Worker TfLite_ruy_trmul_LIB TfLite_ruy_tune_LIB TfLite_ruy_wait_LIB TfLite_ruy_profiler_LIB TfLite_cpuinfo_LIB 114*89c4ff92SAndroid Build Coastguard Worker TfLite_abseil_synchronization_LIB TfLite_pthread_pool_LIB) 115*89c4ff92SAndroid Build Coastguard Worker # Set external variables for usage in CMakeLists.txt 116*89c4ff92SAndroid Build Coastguard Worker if (TFLITE_FOUND) 117*89c4ff92SAndroid Build Coastguard Worker # WARNING! The order of these libraries is critical. Moving them 118*89c4ff92SAndroid Build Coastguard Worker # around will result in linker errors in DelegateUnitTests. 119*89c4ff92SAndroid Build Coastguard Worker set(TfLite_LIB ${TfLite_LIB} ${TfLite_abseilstrings_LIB} ${TfLite_farmhash_LIB} ${TfLite_fftsg_LIB} ${TfLite_fftsg2d_LIB} ${TfLite_flatbuffers_LIB} 120*89c4ff92SAndroid Build Coastguard Worker ${TfLite_ruy_allocator_LIB} ${TfLite_ruy_apply_multiplier_LIB} ${TfLite_ruy_frontend_LIB} ${TfLite_ruy_trmul_LIB} 121*89c4ff92SAndroid Build Coastguard Worker ${TfLite_ruy_threadpool_LIB} ${TfLite_ruy_blocking_counter_LIB} ${TfLite_ruy_block_map_LIB} ${TfLite_ruy_context_LIB} 122*89c4ff92SAndroid Build Coastguard Worker ${TfLite_ruy_context_get_ctx_LIB} ${TfLite_ruy_cpuinfo_LIB} ${TfLite_ruy_ctx_LIB} ${TfLite_ruy_denormal_LIB} 123*89c4ff92SAndroid Build Coastguard Worker ${TfLite_ruy_have_built_path_for_avx2_fma_LIB} ${TfLite_ruy_have_built_path_for_avx512_LIB} 124*89c4ff92SAndroid Build Coastguard Worker ${TfLite_ruy_have_built_path_for_avx_LIB} ${TfLite_ruy_kernel_arm_LIB} ${TfLite_ruy_kernel_avx2_fma_LIB} 125*89c4ff92SAndroid Build Coastguard Worker ${TfLite_ruy_kernel_avx512_LIB} ${TfLite_ruy_kernel_avx_LIB} ${TfLite_ruy_pack_arm_LIB} 126*89c4ff92SAndroid Build Coastguard Worker ${TfLite_ruy_pack_avx2_fma_LIB} ${TfLite_ruy_pack_avx512_LIB} ${TfLite_ruy_pack_avx_LIB} ${TfLite_ruy_prepacked_cache_LIB} 127*89c4ff92SAndroid Build Coastguard Worker ${TfLite_ruy_prepare_packed_matrices_LIB} ${TfLite_ruy_system_aligned_alloc_LIB} 128*89c4ff92SAndroid Build Coastguard Worker ${TfLite_ruy_tune_LIB} ${TfLite_ruy_wait_LIB} ${TfLite_ruy_profiler_LIB} 129*89c4ff92SAndroid Build Coastguard Worker ${TfLite_cpuinfo_LIB} ${TfLite_abseil_synchronization_LIB} ${TfLite_pthread_pool_LIB}) 130*89c4ff92SAndroid Build Coastguard Worker endif () 131*89c4ff92SAndroid Build Coastguard Workerelseif (TfLite_LIB MATCHES .so$) 132*89c4ff92SAndroid Build Coastguard Worker message("-- Dynamic tensorflow lite library found, using for ArmNN build") 133*89c4ff92SAndroid Build Coastguard Worker find_package_handle_standard_args(TfLite DEFAULT_MSG TfLite_LIB) 134*89c4ff92SAndroid Build Coastguard Worker ## Set external variables for usage in CMakeLists.txt 135*89c4ff92SAndroid Build Coastguard Worker if (TFLITE_FOUND) 136*89c4ff92SAndroid Build Coastguard Worker set(TfLite_LIB ${TfLite_LIB}) 137*89c4ff92SAndroid Build Coastguard Worker endif () 138*89c4ff92SAndroid Build Coastguard Workerelse() 139*89c4ff92SAndroid Build Coastguard Worker message(FATAL_ERROR "Could not find a tensorflow lite library to use") 140*89c4ff92SAndroid Build Coastguard Workerendif() 141