• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright 2019 The TensorFlow Authors. All Rights Reserved.
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7#     http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14# ==============================================================================
15
16load("@flatbuffers//:build_defs.bzl", "flatbuffer_android_library", "flatbuffer_cc_library", "flatbuffer_java_library")
17load("//tensorflow/core/platform:build_config_root.bzl", "tf_gpu_tests_tags")
18load("//tensorflow/lite:special_rules.bzl", "tflite_extra_gles_deps", "tflite_portable_test_suite")
19
20package(
21    default_visibility = [
22        "//visibility:public",
23    ],
24    licenses = ["notice"],
25)
26
27flatbuffer_cc_library(
28    name = "database_fbs",
29    srcs = ["database.fbs"],
30)
31
32exports_files(srcs = ["database.fbs"])
33
34flatbuffer_java_library(
35    name = "database_fbs_java",
36    srcs = ["database.fbs"],
37    package_prefix = "org.tensorflow",
38)
39
40flatbuffer_android_library(
41    name = "database_fbs_android",
42    srcs = ["database.fbs"],
43    package_prefix = "org.tensorflow",
44)
45
46cc_library(
47    name = "canonicalize_value",
48    srcs = ["canonicalize_value.cc"],
49    hdrs = ["canonicalize_value.h"],
50    deps = [
51        "@com_google_absl//absl/algorithm:container",
52        "@com_google_absl//absl/strings",
53    ],
54)
55
56cc_test(
57    name = "canonicalize_value_test",
58    srcs = ["canonicalize_value_test.cc"],
59    deps = [
60        ":canonicalize_value",
61        "@com_google_googletest//:gtest_main",
62    ],
63)
64
65cc_library(
66    name = "devicedb",
67    srcs = [
68        "devicedb.cc",
69    ],
70    hdrs = [
71        "devicedb.h",
72        "variables.h",
73    ],
74    deps = [
75        ":database_fbs",
76    ],
77)
78
79cc_binary(
80    name = "json_to_fb",
81    srcs = ["json_to_fb.cc"],
82    deps = [
83        "//tensorflow/lite/tools:command_line_flags",
84        "@flatbuffers",
85    ],
86)
87
88genrule(
89    name = "devicedb-sample_bin",
90    srcs = [
91        "database.fbs",
92        "devicedb-sample.json",
93    ],
94    outs = ["devicedb-sample.bin"],
95    cmd = """
96    $(location :json_to_fb) \
97        --fbs=$(location :database.fbs) \
98        --json_input=$(location :devicedb-sample.json) \
99        --fb_output=$(@)
100    """,
101    tools = [":json_to_fb"],
102)
103
104py_binary(
105    name = "convert_binary_to_cc_source",
106    srcs = ["convert_binary_to_cc_source.py"],
107    python_version = "PY3",
108    srcs_version = "PY3",
109    visibility = ["//visibility:public"],
110)
111
112genrule(
113    name = "devicedb-sample_cc",
114    srcs = ["devicedb-sample.bin"],
115    outs = [
116        "devicedb-sample.cc",
117        "devicedb-sample.h",
118    ],
119    # convert_file_to_c_source for some reason doesn't define the global with
120    # 'extern', which is needed for global const variables in C++.
121    cmd = """
122    $(location :convert_binary_to_cc_source) \
123        --input_binary_file $(location :devicedb-sample.bin) \
124        --output_header_file $(location :devicedb-sample.h) \
125        --output_source_file $(location :devicedb-sample.cc) \
126        --array_variable_name g_tflite_acceleration_devicedb_sample_binary
127    """,
128    tools = [":convert_binary_to_cc_source"],
129)
130
131cc_library(
132    name = "devicedb_sample",
133    srcs = ["devicedb-sample.cc"],
134    hdrs = ["devicedb-sample.h"],
135    deps = [":database_fbs"],
136)
137
138cc_test(
139    name = "devicedb_test",
140    srcs = [
141        "devicedb_test.cc",
142    ],
143    deps = [
144        ":database_fbs",
145        ":devicedb",
146        ":devicedb_sample",
147        "//tensorflow/lite/testing:util",
148        "@com_google_googletest//:gtest_main",
149        "@flatbuffers",
150    ],
151)
152
153exports_files([
154    "database.fbs",
155    "gpu_compatibility.bin",
156])
157
158genrule(
159    name = "gpu_compatibility_binary",
160    srcs = ["gpu_compatibility.bin"],
161    outs = [
162        "gpu_compatibility_binary.h",
163        "gpu_compatibility_binary.cc",
164    ],
165    # convert_file_to_c_source for some reason doesn't define the global with
166    # 'extern', which is needed for global const variables in C++.
167    cmd = """
168    $(location :convert_binary_to_cc_source) \
169        --input_binary_file $(location :gpu_compatibility.bin) \
170        --output_header_file $(location :gpu_compatibility_binary.h) \
171        --output_source_file $(location :gpu_compatibility_binary.cc) \
172        --array_variable_name g_tflite_acceleration_gpu_compatibility_binary
173    """,
174    tools = [":convert_binary_to_cc_source"],
175)
176
177cc_library(
178    name = "android_info",
179    srcs = ["android_info.cc"],
180    hdrs = ["android_info.h"],
181    deps = [
182        "@com_google_absl//absl/status",
183    ],
184)
185
186cc_library(
187    name = "gpu_compatibility_binary_embed",
188    srcs = [":gpu_compatibility_binary.cc"],
189    hdrs = [":gpu_compatibility_binary.h"],
190)
191
192cc_library(
193    name = "gpu_compatibility",
194    srcs = ["gpu_compatibility.cc"],
195    hdrs = ["gpu_compatibility.h"],
196    deps = [
197        ":canonicalize_value",
198        ":android_info",
199        ":database_fbs",
200        ":devicedb",
201        ":gpu_compatibility_binary_embed",
202        "@com_google_absl//absl/status",
203        "@com_google_absl//absl/strings",
204        "@flatbuffers",
205        "//tensorflow/lite/delegates/gpu:delegate_options",
206        "//tensorflow/lite/delegates/gpu/common:gpu_info",
207    ] + tflite_extra_gles_deps(),
208)
209
210cc_test(
211    name = "gpu_compatibility_test",
212    srcs = ["gpu_compatibility_test.cc"],
213    tags = tf_gpu_tests_tags() + [
214        "no_cuda_asan",  # TODO(b/181032551).
215    ],
216    deps = [
217        ":devicedb_sample",
218        ":gpu_compatibility",
219        "@com_google_googletest//:gtest_main",
220    ],
221)
222
223tflite_portable_test_suite()
224