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