-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Expand file tree
/
Copy pathBUILD
More file actions
326 lines (305 loc) · 9.26 KB
/
Copy pathBUILD
File metadata and controls
326 lines (305 loc) · 9.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
load("@bazel_skylib//rules:common_settings.bzl", "string_flag")
load("@pybind11_bazel//:build_defs.bzl", "pybind_extension")
load("@rules_python//python:defs.bzl", "py_library", "py_test")
load("@rules_python//python:packaging.bzl", "py_package", "py_wheel")
load("@rules_shell//shell:sh_test.bzl", "sh_test") # @unused
load("@tflm_pip_deps//:requirements.bzl", "requirement")
load("//python:py_namespace.bzl", "py_namespace")
load("//python:py_rules.bzl", "tflm_py_library")
load(
"//tensorflow:extra_rules.bzl",
"tflm_python_op_resolver_friends",
)
load(
"//tensorflow/lite/micro:build_def.bzl",
"INCOMPATIBLE_WITH_WINDOWS",
"tflm_cc_library",
)
load("//tools:expand_stamp_vars.bzl", "expand_stamp_vars")
package(
features = ["-layering_check"],
licenses = ["notice"],
)
package_group(
name = "op_resolver_friends",
packages = tflm_python_op_resolver_friends(),
)
tflm_cc_library(
name = "python_ops_resolver",
srcs = [
"python_ops_resolver.cc",
],
hdrs = [
"python_ops_resolver.h",
],
visibility = [
":op_resolver_friends",
"//tensorflow/lite/micro/integration_tests:__subpackages__",
"//tensorflow/lite/micro/python/interpreter/src:__subpackages__",
],
deps = [
"//tensorflow/lite/micro:micro_compatibility",
"//tensorflow/lite/micro:op_resolvers",
"//tensorflow/lite/micro/kernels:micro_ops",
],
)
pybind_extension(
name = "_runtime",
# target = _runtime.so because pybind_extension() appends suffix
srcs = [
"_runtime.cc",
"compression_utils.h",
"interpreter_wrapper.cc",
"interpreter_wrapper.h",
"numpy_utils.cc",
"numpy_utils.h",
"pybind11_lib.h",
"python_utils.cc",
"python_utils.h",
"shared_library.h",
],
target_compatible_with = INCOMPATIBLE_WITH_WINDOWS,
deps = [
":python_ops_resolver",
"//tensorflow/lite/micro:micro_framework",
"//tensorflow/lite/micro:op_resolvers",
"//tensorflow/lite/micro:recording_allocators",
"@tflm_pip_deps//numpy:cc_headers",
],
)
tflm_py_library(
name = "runtime",
srcs = [
"runtime.py",
],
data = [
":_runtime.so",
],
target_compatible_with = INCOMPATIBLE_WITH_WINDOWS,
visibility = ["//visibility:public"],
deps = [
requirement("numpy"),
"//tensorflow/lite/micro/tools:generate_test_for_model",
"//tensorflow/lite/python:schema_py",
],
)
py_test(
name = "runtime_test",
srcs = ["runtime_test.py"],
tags = [
"noasan",
"nomsan", # Python doesn't like these symbols in _runtime.so
"noubsan",
],
target_compatible_with = INCOMPATIBLE_WITH_WINDOWS,
deps = [
":runtime",
requirement("numpy"),
requirement("tensorflow"),
"//tensorflow/lite/micro/examples/recipes:add_four_numbers",
"//tensorflow/lite/micro/testing:generate_test_models_lib",
],
)
py_test(
name = "test_compression_unsupported",
srcs = ["test_compression_unsupported.py"],
tags = [
"noasan",
"nomsan", # Python doesn't like these symbols in _runtime.so
"noubsan",
],
# Only compatible when compression is NOT enabled
target_compatible_with = select({
"@platforms//os:windows": ["@platforms//:incompatible"],
"//:with_compression_enabled": ["@platforms//:incompatible"],
"//conditions:default": [],
}),
deps = [
":runtime",
requirement("numpy"),
requirement("tensorflow"),
"//tensorflow/lite/micro/compression:model_editor",
],
)
py_library(
name = "postinstall_check",
srcs = [
"postinstall_check.py",
],
data = [
"sine_float.tflite",
],
)
# Generate a version attribute, imported as tflite_micro.__version__, using
# stamp (a.k.a. workspace status) variables.
expand_stamp_vars(
name = "version",
out = "_version.py",
template = "_version.py.in",
)
# Collect the `deps` and their transitive dependences together into a set of
# files to package. The files retain their full path relative to the workspace
# root, which determines the subpackage path at which they're located within
# the Python distribution package.
py_package(
name = "files_to_package",
# Only Python subpackage paths matching the following prefixes are included
# in the files to package. This avoids packaging, e.g., numpy, which is a
# transitive dependency of the tflm runtime target. This list may require
# modification when adding, directly or indirectly, `deps` from other paths
# in the tflm tree.
packages = [
"python.tflite_micro",
"tensorflow.lite.micro.compression",
"tensorflow.lite.micro.tools",
"tensorflow.lite.micro.tools.generate_test_for_model",
"tensorflow.lite.python",
],
deps = [
":postinstall_check",
":runtime",
":version",
"//tensorflow/lite/micro/compression",
"//tensorflow/lite/micro/tools:tflite_flatbuffer_align",
],
)
# Relocate `deps` underneath the given Python package namespace, otherwise
# maintaining their full paths relative to the workspace root.
#
# For example:
# ${workspace_root}/example/hello.py
# becomes:
# namespace.example.hello
#
# Place `init` at the root of the namespace, regardless of `init`'s path in the
# source tree.
py_namespace(
name = "namespace",
init = "__init__.py",
namespace = "tflite_micro",
deps = [
":files_to_package",
],
)
expand_stamp_vars(
name = "description_file",
out = "README.pypi.md",
template = "README.pypi.md.in",
)
# Building the :whl or its descendants requires the following build setting to
# supply the Python compatibility tags for the wheel metadata.
string_flag(
name = "compatibility_tag",
build_setting_default = "local",
values = [
"cp310_cp310_manylinux_2_28_x86_64",
"cp311_cp311_manylinux_2_28_x86_64",
"cp312_cp312_manylinux_2_28_x86_64",
"cp313_cp313_manylinux_2_28_x86_64",
"local",
],
)
config_setting(
name = "cp310_cp310_manylinux_2_28_x86_64",
flag_values = {
":compatibility_tag": "cp310_cp310_manylinux_2_28_x86_64",
},
)
config_setting(
name = "cp311_cp311_manylinux_2_28_x86_64",
flag_values = {
":compatibility_tag": "cp311_cp311_manylinux_2_28_x86_64",
},
)
config_setting(
name = "cp312_cp312_manylinux_2_28_x86_64",
flag_values = {
":compatibility_tag": "cp312_cp312_manylinux_2_28_x86_64",
},
)
config_setting(
name = "cp313_cp313_manylinux_2_28_x86_64",
flag_values = {
":compatibility_tag": "cp313_cp313_manylinux_2_28_x86_64",
},
)
config_setting(
name = "local",
flag_values = {
":compatibility_tag": "local",
},
)
py_wheel(
name = "whl",
# This macro yields additional targets:
#
# - whl.dist: build a properly named file under whl_dist/
#
abi = select({
":cp310_cp310_manylinux_2_28_x86_64": "cp310",
":cp311_cp311_manylinux_2_28_x86_64": "cp311",
":cp312_cp312_manylinux_2_28_x86_64": "cp312",
":cp313_cp313_manylinux_2_28_x86_64": "cp313",
":local": "none",
}),
description_file = ":description_file",
distribution = "tflite_micro",
platform = select({
":cp310_cp310_manylinux_2_28_x86_64": "manylinux_2_28_x86_64",
":cp311_cp311_manylinux_2_28_x86_64": "manylinux_2_28_x86_64",
":cp312_cp312_manylinux_2_28_x86_64": "manylinux_2_28_x86_64",
":cp313_cp313_manylinux_2_28_x86_64": "manylinux_2_28_x86_64",
":local": "any",
}),
python_tag = select({
":cp310_cp310_manylinux_2_28_x86_64": "cp310",
":cp311_cp311_manylinux_2_28_x86_64": "cp311",
":cp312_cp312_manylinux_2_28_x86_64": "cp312",
":cp313_cp313_manylinux_2_28_x86_64": "cp313",
":local": "py3",
}),
requires = [
"bitarray",
"flatbuffers",
"numpy",
"pyyaml",
"tensorflow",
],
stamp = 1, # 1 == always stamp
strip_path_prefixes = [package_name()],
summary = "TensorFlow Lite for Microcontrollers",
twine = "@tflm_pip_deps_twine//:pkg",
version = "{BUILD_EMBED_LABEL}.dev{STABLE_GIT_COMMIT_TIME}",
deps = [
":namespace",
],
)
sh_test(
name = "whl_test",
size = "large",
srcs = [
"whl_test.sh",
],
args = [
"$(location :whl)",
] + select({
"@rules_python//python/config_settings:is_python_3.10": ["$(location @python_3_10//:bin/python3)"],
"@rules_python//python/config_settings:is_python_3.11": ["$(location @python_3_11//:bin/python3)"],
"@rules_python//python/config_settings:is_python_3.12": ["$(location @python_3_12//:bin/python3)"],
"@rules_python//python/config_settings:is_python_3.13": ["$(location @python_3_13//:bin/python3)"],
}),
data = [
":whl",
"@python_3_10//:bin/python3",
"@python_3_11//:bin/python3",
"@python_3_12//:bin/python3",
"@python_3_13//:bin/python3",
],
tags = [
"noasan",
"nomsan",
"notap", # See http://b/294278650#comment4 for more details.
"noubsan",
],
target_compatible_with = INCOMPATIBLE_WITH_WINDOWS,
)