1# Description: 2# BenchmarkModel Android harness for TensorFlow Lite benchmarks. 3 4load("//tensorflow/lite:build_def.bzl", "tflite_jni_binary") 5load("//tensorflow/lite:special_rules.bzl", "tflite_hexagon_nn_skel_libraries") 6load("@build_bazel_rules_android//android:rules.bzl", "android_binary") 7 8package( 9 default_visibility = ["//visibility:private"], 10 licenses = ["notice"], 11) 12 13# See README.md for details about building and executing the benchmark in APK 14# format. 15 16APK_VARIANTS = [ 17 # (suffix, extra deps) 18 ("", []), 19 ( 20 "_plus_flex", 21 ["//tensorflow/lite/delegates/flex:delegate"], 22 ), 23] 24 25[android_binary( 26 name = "benchmark_model%s" % suffix, 27 srcs = glob([ 28 "src/**/*.java", 29 ]), 30 custom_package = "org.tensorflow.lite.benchmark", 31 manifest = "AndroidManifest.xml", 32 multidex = "native", 33 # In some platforms we don't have an Android SDK/NDK and this target 34 # can't be built. We need to prevent the build system from trying to 35 # use the target in that case. 36 tags = ["manual"], 37 deps = [ 38 ":hexagon_libs", 39 ":tensorflowlite_benchmark_native%s" % suffix, 40 ], 41) for suffix, _ in APK_VARIANTS] 42 43[tflite_jni_binary( 44 name = "libtensorflowlite_benchmark%s.so" % suffix, 45 srcs = glob([ 46 "jni/**/*.cc", 47 "jni/**/*.h", 48 ]), 49 deps = [ 50 "//tensorflow/lite/java/jni", 51 "//tensorflow/lite/tools/benchmark:benchmark_tflite_model_lib", 52 ] + extra_deps, 53) for suffix, extra_deps in APK_VARIANTS] 54 55[cc_library( 56 name = "tensorflowlite_benchmark_native%s" % suffix, 57 srcs = ["libtensorflowlite_benchmark%s.so" % suffix], 58 visibility = ["//visibility:private"], 59) for suffix, _ in APK_VARIANTS] 60 61cc_library( 62 name = "hexagon_libs", 63 srcs = select({ 64 "//tensorflow:android_arm64": [ 65 "//tensorflow/lite/delegates/hexagon/hexagon_nn:libhexagon_interface.so", 66 ] + tflite_hexagon_nn_skel_libraries(), 67 "//tensorflow:android_arm": [ 68 "//tensorflow/lite/delegates/hexagon/hexagon_nn:libhexagon_interface.so", 69 ] + tflite_hexagon_nn_skel_libraries(), 70 "//conditions:default": [], 71 }), 72 visibility = ["//visibility:private"], 73) 74