xref: /aosp_15_r20/external/tensorflow/tensorflow/compiler/mlir/tosa/BUILD (revision b6fb3261f9314811a0f4371741dbb8839866f948)
1# TensorFlow -> TOSA Compiler Bridge.
2# See:
3#   https://developer.mlplatform.org/w/tosa/
4#   https://github.com/llvm/llvm-project/blob/main/mlir/docs/Dialects/TOSA.md
5
6load("//tensorflow:tensorflow.bzl", "get_compatible_with_cloud")
7load("@llvm-project//mlir:tblgen.bzl", "gentbl_cc_library")
8
9# TODO: Tighten visibility once targets are at the right granularity.
10package(
11    default_visibility = [":internal"],
12    licenses = ["notice"],
13)
14
15package_group(
16    name = "internal",
17    packages = [
18        "//tensorflow/compiler/mlir/...",
19    ],
20)
21
22package_group(
23    name = "friends",
24    includes = [
25        ":internal",
26    ],
27    packages = [
28        "//third_party/iree/...",
29    ],
30)
31
32filegroup(
33    name = "tosa_ops_td_files",
34    srcs = [
35        "@llvm-project//mlir:TosaDialectTdFiles",
36    ],
37    compatible_with = get_compatible_with_cloud(),
38)
39
40gentbl_cc_library(
41    name = "tosa_passes_inc_gen",
42    compatible_with = get_compatible_with_cloud(),
43    tbl_outs = [
44        (
45            [
46                "-gen-pass-decls",
47                "-name=LegalizeTosa",
48            ],
49            "transforms/passes.h.inc",
50        ),
51    ],
52    tblgen = "@llvm-project//mlir:mlir-tblgen",
53    td_file = "transforms/passes.td",
54    deps = [
55        "@llvm-project//mlir:PassBaseTdFiles",
56    ],
57)
58
59cc_library(
60    name = "passes_header",
61    hdrs = [
62        "transforms/passes.h",
63        "transforms/passes.h.inc",
64    ],
65    compatible_with = get_compatible_with_cloud(),
66    deps = [
67        "//tensorflow/compiler/mlir/lite:tensorflow_lite",
68        "@llvm-project//mlir:FuncDialect",
69        "@llvm-project//mlir:Pass",
70    ],
71)
72
73cc_library(
74    name = "legalize_common",
75    srcs = [
76        "transforms/legalize_common.cc",
77        "transforms/legalize_utils.cc",
78    ],
79    hdrs = [
80        "transforms/legalize_common.h",
81        "transforms/legalize_utils.h",
82    ],
83    compatible_with = get_compatible_with_cloud(),
84    deps = [
85        "//tensorflow/compiler/mlir/lite:tensorflow_lite",
86        "//tensorflow/compiler/mlir/lite/quantization/ir:QuantOps",
87        "//tensorflow/core:framework",
88        "//tensorflow/core/kernels:conv_grad_shape_utils",
89        "@llvm-project//llvm:Support",
90        "@llvm-project//mlir:FuncDialect",
91        "@llvm-project//mlir:IR",
92        "@llvm-project//mlir:InferTypeOpInterface",
93        "@llvm-project//mlir:QuantOps",
94        "@llvm-project//mlir:Rewrite",
95        "@llvm-project//mlir:Support",
96        "@llvm-project//mlir:TensorDialect",
97        "@llvm-project//mlir:TosaDialect",
98        "@llvm-project//mlir:Transforms",
99    ],
100)
101
102gentbl_cc_library(
103    name = "tosa_legalize_tf_inc_gen",
104    compatible_with = get_compatible_with_cloud(),
105    tbl_outs = [
106        (
107            ["-gen-rewriters"],
108            "transforms/tf_legalize_patterns.inc",
109        ),
110    ],
111    tblgen = "@llvm-project//mlir:mlir-tblgen",
112    td_file = "transforms/tf_legalize_patterns.td",
113    deps = [
114        ":tosa_ops_td_files",
115        "//tensorflow/compiler/mlir/lite/quantization/ir:QuantizationOpsTdFiles",
116        "//tensorflow/compiler/mlir/tensorflow:tensorflow_ops_td_files",
117        "@llvm-project//mlir:FuncTdFiles",
118    ],
119)
120
121cc_library(
122    name = "tf_passes",
123    srcs = [
124        "tf_passes.cc",
125        "transforms/dequantize_tfl_softmax.cc",
126        "transforms/fuse_bias_tf.cc",
127        "transforms/legalize_tf.cc",
128        "transforms/tf_legalize_patterns.inc",
129    ],
130    hdrs = [
131        "tf_passes.h",
132        "transforms/passes.h",
133    ],
134    compatible_with = get_compatible_with_cloud(),
135    visibility = [":friends"],
136    deps = [
137        ":legalize_common",
138        ":passes_header",
139        "//tensorflow/compiler/mlir/lite:tensorflow_lite",
140        "//tensorflow/compiler/mlir/lite/quantization/ir:QuantOps",
141        "//tensorflow/compiler/mlir/tensorflow",
142        "@llvm-project//llvm:Support",
143        "@llvm-project//mlir:AffineTransforms",
144        "@llvm-project//mlir:FuncDialect",
145        "@llvm-project//mlir:IR",
146        "@llvm-project//mlir:Pass",
147        "@llvm-project//mlir:QuantOps",
148        "@llvm-project//mlir:Support",
149        "@llvm-project//mlir:TosaDialect",
150        "@llvm-project//mlir:Transforms",
151    ],
152)
153
154gentbl_cc_library(
155    name = "tosa_legalize_tfl_inc_gen",
156    compatible_with = get_compatible_with_cloud(),
157    tbl_outs = [
158        (
159            ["-gen-rewriters"],
160            "transforms/tfl_legalize_patterns.inc",
161        ),
162    ],
163    tblgen = "@llvm-project//mlir:mlir-tblgen",
164    td_file = "transforms/tfl_legalize_patterns.td",
165    deps = [
166        ":tosa_ops_td_files",
167        "//tensorflow/compiler/mlir/lite:tensorflow_lite_ops_td_files",
168        "//tensorflow/compiler/mlir/lite/quantization/ir:QuantizationOpsTdFiles",
169        "@llvm-project//mlir:FuncTdFiles",
170    ],
171)
172
173cc_library(
174    name = "tfl_passes",
175    srcs = [
176        "tfl_passes.cc",
177        "transforms/convert_tfl_uint8.cc",
178        "transforms/legalize_tfl.cc",
179        "transforms/strip_quant_types.cc",
180        "transforms/tfl_legalize_patterns.inc",
181    ],
182    hdrs = [
183        "tfl_passes.h",
184        "transforms/passes.h",
185    ],
186    compatible_with = get_compatible_with_cloud(),
187    visibility = [":friends"],
188    deps = [
189        ":legalize_common",
190        ":passes_header",
191        "//tensorflow/compiler/mlir/lite:tensorflow_lite",
192        "//tensorflow/compiler/mlir/lite:tensorflow_lite_quantize",
193        "//tensorflow/compiler/mlir/lite/quantization/ir:QuantOps",
194        "@llvm-project//llvm:Support",
195        "@llvm-project//mlir:AffineTransforms",
196        "@llvm-project//mlir:Dialect",
197        "@llvm-project//mlir:FuncDialect",
198        "@llvm-project//mlir:IR",
199        "@llvm-project//mlir:Pass",
200        "@llvm-project//mlir:QuantOps",
201        "@llvm-project//mlir:Support",
202        "@llvm-project//mlir:TosaDialect",
203        "@llvm-project//mlir:Transforms",
204    ],
205)
206
207cc_library(
208    name = "tf_tfl_passes",
209    srcs = [
210        "tf_tfl_passes.cc",
211        "transforms/legalize_tf_tfl.cc",
212    ],
213    hdrs = [
214        "tf_tfl_passes.h",
215        "transforms/passes.h",
216    ],
217    compatible_with = get_compatible_with_cloud(),
218    visibility = [":friends"],
219    deps = [
220        ":legalize_common",
221        ":passes_header",
222        ":tf_passes",
223        ":tfl_passes",
224        "//tensorflow/compiler/mlir/lite:lift_tflite_flex_ops",
225        "//tensorflow/compiler/mlir/lite:tensorflow_lite",
226        "@llvm-project//mlir:AffineTransforms",
227        "@llvm-project//mlir:FuncDialect",
228        "@llvm-project//mlir:IR",
229        "@llvm-project//mlir:Pass",
230        "@llvm-project//mlir:Support",
231        "@llvm-project//mlir:TosaDialect",
232        "@llvm-project//mlir:Transforms",
233    ],
234)
235