1load("//tensorflow:tensorflow.bzl", "tf_cc_binary") 2load("//tensorflow/lite:special_rules.bzl", "tflite_portable_test_suite") 3load("//tensorflow/lite:build_def.bzl", "tflite_copts", "tflite_copts_warnings", "tflite_linkopts") 4 5package( 6 default_visibility = [ 7 "//visibility:public", 8 ], 9 licenses = ["notice"], # Apache 2.0 10) 11 12common_copts = tflite_copts() + tflite_copts_warnings() 13 14# We create a library for benchmark_main.cc to faciliate the creation of a 15# customized benchmark model binary that only needs linking with extra 16# dependency, e.g., enabling creating of benchmark binaries with a custom 17# delegate provider. 18cc_library( 19 name = "benchmark_model_main", 20 srcs = [ 21 "benchmark_main.cc", 22 ], 23 copts = common_copts, 24 deps = [ 25 ":benchmark_tflite_model_lib", 26 "//tensorflow/lite/tools:logging", 27 ], 28) 29 30cc_binary( 31 name = "benchmark_model", 32 copts = common_copts, 33 linkopts = tflite_linkopts() + select({ 34 "//tensorflow:android": [ 35 "-pie", # Android 5.0 and later supports only PIE 36 "-lm", # some builtin ops, e.g., tanh, need -lm 37 "-Wl,--rpath=/data/local/tmp/", # Hexagon delegate libraries should be in /data/local/tmp 38 ], 39 "//conditions:default": [], 40 }), 41 tags = ["builder_default_android_arm64"], 42 deps = [ 43 ":benchmark_model_main", 44 ], 45) 46 47cc_binary( 48 name = "benchmark_model_performance_options", 49 srcs = [ 50 "benchmark_tflite_performance_options_main.cc", 51 ], 52 copts = common_copts, 53 linkopts = tflite_linkopts() + select({ 54 "//tensorflow:android": [ 55 "-pie", # Android 5.0 and later supports only PIE 56 "-lm", # some builtin ops, e.g., tanh, need -lm 57 "-Wl,--rpath=/data/local/tmp/", # Hexagon delegate libraries should be in /data/local/tmp 58 ], 59 "//conditions:default": [], 60 }), 61 tags = ["builder_default_android_arm64"], 62 deps = [ 63 ":benchmark_performance_options", 64 ":benchmark_tflite_model_lib", 65 "//tensorflow/lite/tools:logging", 66 ], 67) 68 69# As with most target binaries that use flex, this should be built with the 70# `--config=monolithic` build flag, e.g., 71# bazel build --config=monolithic --config=android_arm64 \ 72# -c opt --cxxopt='--std=c++14' :benchmark_model_plus_flex 73tf_cc_binary( 74 name = "benchmark_model_plus_flex", 75 srcs = [ 76 "benchmark_plus_flex_main.cc", 77 ], 78 copts = common_copts, 79 linkopts = tflite_linkopts() + select({ 80 "//tensorflow:android": [ 81 "-pie", # Android 5.0 and later supports only PIE 82 "-lm", # some builtin ops, e.g., tanh, need -lm 83 ], 84 "//conditions:default": [], 85 }), 86 deps = [ 87 ":benchmark_tflite_model_lib", 88 "//tensorflow/lite/delegates/flex:delegate", 89 "//tensorflow/lite/testing:init_tensorflow", 90 "//tensorflow/lite/tools:logging", 91 ], 92) 93 94cc_test( 95 name = "benchmark_test", 96 srcs = ["benchmark_test.cc"], 97 args = [ 98 "--fp32_graph=$(location //tensorflow/lite:testdata/multi_add.bin)", 99 "--int8_graph=$(location //tensorflow/lite:testdata/add_quantized_int8.bin)", 100 "--string_graph=$(location //tensorflow/lite:testdata/string_input_model.bin)", 101 ], 102 data = [ 103 "//tensorflow/lite:testdata/add_quantized_int8.bin", 104 "//tensorflow/lite:testdata/multi_add.bin", 105 "//tensorflow/lite:testdata/string_input_model.bin", 106 ], 107 tags = [ 108 "tflite_not_portable_android", 109 "tflite_not_portable_ios", 110 ], 111 deps = [ 112 ":benchmark_performance_options", 113 ":benchmark_tflite_model_lib", 114 "//tensorflow/lite:framework", 115 "//tensorflow/lite:string_util", 116 "//tensorflow/lite/c:common", 117 "//tensorflow/lite/testing:util", 118 "//tensorflow/lite/tools:command_line_flags", 119 "//tensorflow/lite/tools:logging", 120 "//tensorflow/lite/tools/delegates:delegate_provider_hdr", 121 "@com_google_absl//absl/algorithm", 122 "@com_google_absl//absl/memory", 123 "@com_google_absl//absl/strings:str_format", 124 "@com_google_googletest//:gtest", 125 ], 126) 127 128cc_library( 129 name = "profiling_listener", 130 srcs = ["profiling_listener.cc"], 131 hdrs = ["profiling_listener.h"], 132 copts = common_copts, 133 deps = [ 134 ":benchmark_model_lib", 135 "//tensorflow/lite/profiling:profile_summarizer", 136 "//tensorflow/lite/profiling:profile_summary_formatter", 137 "//tensorflow/lite/profiling:profiler", 138 "//tensorflow/lite/tools:logging", 139 ], 140) 141 142cc_library( 143 name = "benchmark_tflite_model_lib", 144 srcs = ["benchmark_tflite_model.cc"], 145 hdrs = ["benchmark_tflite_model.h"], 146 copts = common_copts + select({ 147 "//tensorflow:ios": [ 148 "-xobjective-c++", 149 ], 150 "//conditions:default": [], 151 }), 152 deps = [ 153 ":benchmark_model_lib", 154 ":benchmark_utils", 155 ":profiling_listener", 156 "//tensorflow/lite:framework", 157 "//tensorflow/lite:string_util", 158 "//tensorflow/lite/c:common", 159 "//tensorflow/lite/kernels:builtin_ops", 160 "//tensorflow/lite/kernels:cpu_backend_context", 161 "//tensorflow/lite/profiling:profile_summary_formatter", 162 "//tensorflow/lite/profiling:profiler", 163 "//tensorflow/lite/tools:logging", 164 "//tensorflow/lite/tools/delegates:delegate_provider_hdr", 165 "//tensorflow/lite/tools/delegates:tflite_execution_providers", 166 "@com_google_absl//absl/base:core_headers", 167 "@com_google_absl//absl/strings", 168 "@ruy//ruy/profiler", 169 ], 170) 171 172cc_library( 173 name = "benchmark_performance_options", 174 srcs = [ 175 "benchmark_performance_options.cc", 176 ], 177 hdrs = ["benchmark_performance_options.h"], 178 copts = common_copts, 179 deps = [ 180 ":benchmark_model_lib", 181 ":benchmark_params", 182 ":benchmark_utils", 183 "//tensorflow/lite/tools:logging", 184 "@com_google_absl//absl/memory", 185 "//tensorflow/core/util:stats_calculator_portable", 186 "//tensorflow/lite/c:common", 187 "//tensorflow/lite/nnapi:nnapi_util", 188 "//tensorflow/lite/profiling:time", 189 "//tensorflow/lite/tools:command_line_flags", 190 ] + select({ 191 "//tensorflow:android": [ 192 "//tensorflow/lite/delegates/gpu:delegate", 193 ], 194 "//conditions:default": [], 195 }), 196) 197 198cc_library( 199 name = "benchmark_params", 200 hdrs = ["benchmark_params.h"], 201 copts = common_copts, 202 deps = ["//tensorflow/lite/tools:tool_params"], 203) 204 205cc_library( 206 name = "benchmark_model_lib", 207 srcs = [ 208 "benchmark_model.cc", 209 ], 210 hdrs = ["benchmark_model.h"], 211 copts = common_copts, 212 deps = [ 213 ":benchmark_params", 214 ":benchmark_utils", 215 "//tensorflow/core/util:stats_calculator_portable", 216 "//tensorflow/lite:framework", 217 "//tensorflow/lite/c:common", 218 "//tensorflow/lite/profiling:memory_info", 219 "//tensorflow/lite/profiling:time", 220 "//tensorflow/lite/tools:command_line_flags", 221 "//tensorflow/lite/tools:logging", 222 ], 223) 224 225cc_library( 226 name = "benchmark_utils", 227 srcs = [ 228 "benchmark_utils.cc", 229 ], 230 hdrs = ["benchmark_utils.h"], 231 copts = common_copts, 232 deps = ["//tensorflow/lite/profiling:time"], 233) 234 235cc_test( 236 name = "benchmark_utils_test", 237 srcs = [ 238 "benchmark_utils_test.cc", 239 ], 240 deps = [ 241 ":benchmark_utils", 242 "//tensorflow/lite/profiling:time", 243 "@com_google_googletest//:gtest_main", 244 ], 245) 246 247tflite_portable_test_suite() 248