• 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_cc_library", "flatbuffer_java_library")
17load("//tensorflow/lite:special_rules.bzl", "tflite_extra_gles_deps", "tflite_portable_test_suite")
18
19package(
20    default_visibility = [
21        "//visibility:public",
22    ],
23    licenses = ["notice"],  # Apache 2.0
24)
25
26flatbuffer_cc_library(
27    name = "database_fbs",
28    srcs = ["database.fbs"],
29)
30
31exports_files(srcs = ["database.fbs"])
32
33flatbuffer_java_library(
34    name = "database_fbs_java",
35    srcs = ["database.fbs"],
36    package_prefix = "org.tensorflow",
37)
38
39cc_library(
40    name = "devicedb",
41    srcs = [
42        "devicedb.cc",
43    ],
44    hdrs = [
45        "devicedb.h",
46        "variables.h",
47    ],
48    deps = [
49        ":database_fbs",
50    ],
51)
52
53cc_binary(
54    name = "json_to_fb",
55    srcs = ["json_to_fb.cc"],
56    deps = [
57        "//tensorflow/lite/tools:command_line_flags",
58        "@flatbuffers",
59    ],
60)
61
62genrule(
63    name = "devicedb-sample_bin",
64    srcs = [
65        "database.fbs",
66        "devicedb-sample.json",
67    ],
68    outs = ["devicedb-sample.bin"],
69    cmd = """
70    $(location :json_to_fb) \
71        --fbs=$(location :database.fbs) \
72        --json_input=$(location :devicedb-sample.json) \
73        --fb_output=$(@)
74    """,
75    tools = [":json_to_fb"],
76)
77
78py_binary(
79    name = "convert_binary_to_cc_source",
80    srcs = ["convert_binary_to_cc_source.py"],
81    python_version = "PY3",
82    srcs_version = "PY3",
83    visibility = ["//visibility:public"],
84)
85
86genrule(
87    name = "devicedb-sample_cc",
88    srcs = ["devicedb-sample.bin"],
89    outs = [
90        "devicedb-sample.cc",
91        "devicedb-sample.h",
92    ],
93    # convert_file_to_c_source for some reason doesn't define the global with
94    # 'extern', which is needed for global const variables in C++.
95    cmd = """
96    $(location :convert_binary_to_cc_source) \
97        --input_binary_file $(location :devicedb-sample.bin) \
98        --output_header_file $(location :devicedb-sample.h) \
99        --output_source_file $(location :devicedb-sample.cc) \
100        --array_variable_name g_tflite_acceleration_devicedb_sample_binary
101    """,
102    tools = [":convert_binary_to_cc_source"],
103)
104
105cc_library(
106    name = "devicedb_sample",
107    srcs = ["devicedb-sample.cc"],
108    hdrs = ["devicedb-sample.h"],
109    deps = [":database_fbs"],
110)
111
112cc_test(
113    name = "devicedb_test",
114    srcs = [
115        "devicedb_test.cc",
116    ],
117    deps = [
118        ":database_fbs",
119        ":devicedb",
120        ":devicedb_sample",
121        "//tensorflow/lite/testing:util",
122        "@com_google_googletest//:gtest",
123        "@flatbuffers",
124    ],
125)
126
127exports_files(["gpu_compatibility.bin"])
128
129genrule(
130    name = "gpu_compatibility_binary",
131    srcs = ["gpu_compatibility.bin"],
132    outs = [
133        "gpu_compatibility_binary.h",
134        "gpu_compatibility_binary.cc",
135    ],
136    # convert_file_to_c_source for some reason doesn't define the global with
137    # 'extern', which is needed for global const variables in C++.
138    cmd = """
139    $(location :convert_binary_to_cc_source) \
140        --input_binary_file $(location :gpu_compatibility.bin) \
141        --output_header_file $(location :gpu_compatibility_binary.h) \
142        --output_source_file $(location :gpu_compatibility_binary.cc) \
143        --array_variable_name g_tflite_acceleration_gpu_compatibility_binary
144    """,
145    tools = [":convert_binary_to_cc_source"],
146)
147
148cc_library(
149    name = "android_info",
150    srcs = ["android_info.cc"],
151    hdrs = ["android_info.h"],
152    deps = [
153        "@com_google_absl//absl/status",
154    ],
155)
156
157cc_library(
158    name = "gpu_compatibility",
159    srcs = [
160        "gpu_compatibility.cc",
161        "gpu_compatibility_binary.cc",
162        "gpu_compatibility_binary.h",
163    ],
164    hdrs = [
165        "gpu_compatibility.h",
166    ],
167    deps = [
168        ":android_info",
169        ":database_fbs",
170        ":devicedb",
171        "@com_google_absl//absl/status",
172        "@com_google_absl//absl/strings",
173        "@flatbuffers",
174        "//tensorflow/lite/delegates/gpu:delegate",
175        "//tensorflow/lite/delegates/gpu/common:gpu_info",
176    ] + tflite_extra_gles_deps(),
177)
178
179cc_test(
180    name = "gpu_compatibility_test",
181    srcs = ["gpu_compatibility_test.cc"],
182    tags = ["no_mac"],  # b/163222453
183    deps = [
184        ":devicedb_sample",
185        ":gpu_compatibility",
186        "@com_google_googletest//:gtest_main",
187    ],
188)
189
190tflite_portable_test_suite()
191