xref: /aosp_15_r20/external/executorch/kernels/test/targets.bzl (revision 523fa7a60841cd1ecfb9cc4201f1ca8b03ed023a)
1load("@fbsource//xplat/executorch/build:runtime_wrapper.bzl", "runtime")
2load("@fbsource//xplat/executorch/kernels/test:util.bzl", "codegen_function_header_wrapper", "generated_op_test", "op_test")
3
4def _common_op_test(name, kernels):
5    """
6    Defines test targets in format of <kernel>_op_<op-name>_test
7    For ATen kernel testing, let's use portable functions.yaml for tested ops.
8    """
9    for kernel in kernels:
10        deps = [":function_header_wrapper_{}".format(kernel)]
11        op_test(name, kernel_name = kernel, use_kernel_prefix = True, deps = deps)
12
13def make_example_generated_op_test_target():
14    """
15    Makes a test for kernels/test/util generated_op_test() helper
16    Here we use portable kernel. Try with `buck test xplat/executorch/kernels/test:op_<>_test`
17    """
18    op_test_cpp_files = native.glob(
19        ["op_*_test.cpp"],
20        # linear has no portable op.
21        exclude = ["op_linear_test.cpp"],
22    )
23
24    # The op name is from the beginning to the part without `_test.cpp` (:-9)
25    op_to_test = [f[:-9] for f in op_test_cpp_files]
26    for op_name in op_to_test:
27        generated_op_test(
28            op_name + "_test",
29            "//executorch/kernels/portable/cpu:{}".format(op_name),
30            "//executorch/kernels/portable:generated_lib_headers",
31            "//executorch/kernels/portable/test:supported_features",
32            "//executorch/kernels/test:function_header_wrapper_portable",
33        )
34
35def define_common_targets():
36    """Defines targets that should be shared between fbcode and xplat.
37
38    The directory containing this targets.bzl file should also contain both
39    TARGETS and BUCK files that call this function.
40    """
41
42    for aten_kernel in (True, False):
43        aten_suffix = "_aten" if aten_kernel else ""
44        runtime.cxx_library(
45            name = "test_util" + aten_suffix,
46            srcs = [
47                "BinaryLogicalOpTest.cpp",
48                "UnaryUfuncRealHBBF16ToFloatHBF16Test.cpp",
49            ],
50            exported_headers = [
51                "BinaryLogicalOpTest.h",
52                "TestUtil.h",
53                "UnaryUfuncRealHBBF16ToFloatHBF16Test.h",
54            ],
55            visibility = [
56                "//executorch/kernels/...",
57                "@EXECUTORCH_CLIENTS",
58            ],
59            preprocessor_flags = ["-DUSE_ATEN_LIB"] if aten_kernel else [],
60            exported_deps = [
61                ":supported_features_header",
62                "//executorch/runtime/core/exec_aten:lib" + aten_suffix,
63                "//executorch/runtime/core/exec_aten/testing_util:tensor_util" + aten_suffix,
64                "//executorch/runtime/kernel:kernel_includes",
65                "//executorch/test/utils:utils" + aten_suffix,
66            ],
67            fbcode_exported_deps = [
68                "//common/init:init",
69                "//common/gtest:gtest",
70            ],
71            xplat_exported_deps = [
72                "//xplat/folly:init_init",
73                "//third-party/googletest:gtest_main",
74            ],
75        )
76
77        runtime.cxx_test(
78            name = "kernel_runtime_context_test" + aten_suffix,
79            srcs = ["kernel_runtime_context_test.cpp"],
80            deps = [
81                "//executorch/runtime/kernel:kernel_runtime_context" + aten_suffix,
82            ],
83        )
84
85    runtime.python_binary(
86        name = "gen_supported_features",
87        main_module = "executorch.kernels.test.gen_supported_features",
88        deps = [
89            ":gen_supported_features_lib",
90        ],
91        visibility = [
92            "//executorch/kernels/...",
93        ],
94    )
95
96    runtime.python_library(
97        name = "gen_supported_features_lib",
98        srcs = ["gen_supported_features.py"],
99        resources = [
100            "supported_features_header.ini",
101            "supported_features_definition.ini",
102        ],
103        base_module = "executorch.kernels.test",
104        visibility = ["//executorch/kernels/test/..."],
105        deps = [
106            "fbsource//third-party/pkg_resources:pkg_resources",
107            "fbsource//third-party/pypi/pyyaml:pyyaml",
108        ],
109    )
110
111    runtime.genrule(
112        name = "supported_feature_header_gen",
113        cmd = "$(exe //executorch/kernels/test:gen_supported_features) ${SRCS} > $OUT/supported_features.h",
114        srcs = ["supported_features.yaml"],
115        outs = {"supported_features.h": ["supported_features.h"]},
116        default_outs = ["."],
117    )
118
119    runtime.cxx_library(
120        name = "supported_features_header",
121        srcs = [],
122        exported_headers = {"supported_features.h": ":supported_feature_header_gen[supported_features.h]"},
123        visibility = [
124            "//executorch/kernels/...",
125        ],
126    )
127
128    runtime.genrule(
129        name = "supported_feature_aten_gen",
130        cmd = "$(exe //executorch/kernels/test:gen_supported_features) ${SRCS} > $OUT/supported_features_aten.cpp",
131        srcs = ["supported_features_def_aten.yaml"],
132        outs = {"supported_features_aten.cpp": ["supported_features_aten.cpp"]},
133        default_outs = ["."],
134    )
135
136    runtime.cxx_library(
137        name = "supported_features_aten",
138        srcs = [":supported_feature_aten_gen[supported_features_aten.cpp]"],
139        visibility = [
140            "//executorch/kernels/...",
141        ],
142        exported_deps = [
143            "//executorch/kernels/test:supported_features_header",
144        ],
145    )
146
147    TEST_SRCS = native.glob(["op_*_test.cpp"])
148
149    runtime.filegroup(
150        name = "test_srcs",
151        srcs = TEST_SRCS,
152        visibility = [
153            "//executorch/kernels/...",
154            "@EXECUTORCH_CLIENTS",
155        ],
156    )
157
158    runtime.genrule(
159        name = "test_srcs_gen",
160        srcs = [":test_srcs"],
161        cmd = "cp $(location :test_srcs)/* $OUT",
162        outs = {f: [f] for f in TEST_SRCS},
163        default_outs = ["."],
164        visibility = [
165            "//executorch/kernels/...",
166            "@EXECUTORCH_CLIENTS",
167        ],
168    )
169
170    codegen_function_header_wrapper("executorch/kernels/aten", "aten")
171    codegen_function_header_wrapper("executorch/kernels/portable", "portable")
172    codegen_function_header_wrapper("executorch/kernels/optimized", "optimized")
173    codegen_function_header_wrapper("executorch/kernels/quantized", "quantized")
174    codegen_function_header_wrapper("executorch/kernels/test/custom_kernel_example", "custom_kernel_example")
175
176    _common_op_test("op__to_dim_order_copy_test", ["aten", "portable"])
177    _common_op_test("op_abs_test", ["aten", "portable"])
178    _common_op_test("op_acos_test", ["aten", "portable"])
179    _common_op_test("op_acosh_test", ["aten", "portable"])
180    _common_op_test("op_add_test", ["aten", "portable", "optimized"])
181    _common_op_test("op_addmm_test", ["aten", "portable"])
182    _common_op_test("op_alias_copy_test", ["aten", "portable"])
183    _common_op_test("op_amax_test", ["aten", "portable"])
184    _common_op_test("op_amin_test", ["aten", "portable"])
185    _common_op_test("op_any_test", ["aten", "portable"])
186    _common_op_test("op_arange_test", ["aten", "portable"])
187    _common_op_test("op_argmax_test", ["aten", "portable"])
188    _common_op_test("op_argmin_test", ["aten", "portable"])
189    _common_op_test("op_as_strided_copy_test", ["aten", "portable"])
190    _common_op_test("op_asin_test", ["aten", "portable"])
191    _common_op_test("op_asinh_test", ["aten", "portable"])
192    _common_op_test("op_atan_test", ["aten", "portable"])
193    _common_op_test("op_atan2_test", ["aten", "portable"])
194    _common_op_test("op_atanh_test", ["aten", "portable"])
195    _common_op_test("op_avg_pool2d_test", ["aten", "portable"])
196    _common_op_test("op_bitwise_and_test", ["aten", "portable"])
197    _common_op_test("op_bitwise_not_test", ["aten", "portable"])
198    _common_op_test("op_bitwise_or_test", ["aten", "portable"])
199    _common_op_test("op_bitwise_xor_test", ["aten", "portable"])
200    _common_op_test("op_bmm_test", ["aten", "portable", "optimized"])
201    _common_op_test("op_cat_test", ["aten", "portable"])
202    _common_op_test("op_cdist_forward_test", ["aten", "portable"])
203    _common_op_test("op_ceil_test", ["aten", "portable"])
204    _common_op_test("op_clamp_test", ["aten", "portable"])
205    _common_op_test("op_clone_test", ["aten", "portable"])
206    _common_op_test("op_constant_pad_nd_test", ["aten", "portable"])
207    _common_op_test("op_convolution_test", ["aten", "portable"])
208    _common_op_test("op_convolution_backward_test", ["aten", "portable"])
209    _common_op_test("op_copy_test", ["aten", "portable"])
210    _common_op_test("op_cos_test", ["aten", "portable"])
211    _common_op_test("op_cosh_test", ["aten", "portable"])
212    _common_op_test("op_cumsum_test", ["aten", "portable"])
213    _common_op_test("op_detach_copy_test", ["aten", "portable"])
214    _common_op_test("op_diagonal_copy_test", ["aten", "portable"])
215    _common_op_test("op_div_test", ["aten", "portable", "optimized"])
216    _common_op_test("op_embedding_test", ["aten", "portable"])
217    _common_op_test("op_empty_test", ["aten", "portable"])
218    _common_op_test("op_eq_test", ["aten", "portable"])
219    _common_op_test("op_erf_test", ["aten", "portable"])
220    _common_op_test("op_exp_test", ["aten", "portable", "optimized"])
221    _common_op_test("op_expand_copy_test", ["aten", "portable"])
222    _common_op_test("op_expm1_test", ["aten", "portable"])
223    _common_op_test("op_fill_test", ["aten", "portable"])
224    _common_op_test("op_flip_test", ["aten", "portable"])
225    _common_op_test("op_floor_divide_test", ["aten", "portable"])
226    _common_op_test("op_floor_test", ["aten", "portable"])
227    _common_op_test("op_fmod_test", ["aten", "portable"])
228    _common_op_test("op_full_like_test", ["aten", "portable"])
229    _common_op_test("op_full_test", ["aten", "portable"])
230    _common_op_test("op_gather_test", ["aten", "portable"])
231    _common_op_test("op_ge_test", ["aten", "portable"])
232    _common_op_test("op_gelu_test", ["aten", "portable", "optimized"])
233    _common_op_test("op_glu_test", ["aten", "portable"])
234    _common_op_test("op_gt_test", ["aten", "portable"])
235    _common_op_test("op_hardtanh_test", ["aten", "portable"])
236    _common_op_test("op_index_put_test", ["aten", "portable"])
237    _common_op_test("op_index_select_test", ["aten", "portable"])
238    _common_op_test("op_index_test", ["aten", "portable"])
239    _common_op_test("op_isinf_test", ["aten", "portable"])
240    _common_op_test("op_isnan_test", ["aten", "portable"])
241    _common_op_test("op_le_test", ["aten", "portable", "optimized"])
242    _common_op_test("op_leaky_relu_test", ["aten", "portable"])
243    _common_op_test("op_lift_fresh_copy_test", ["aten", "portable"])
244    _common_op_test("op_linear_test", ["aten", "optimized"])
245    _common_op_test("op_log_softmax_test", ["aten", "portable", "optimized"])
246    _common_op_test("op_log_test", ["aten", "portable"])
247    _common_op_test("op_log10_test", ["aten", "portable"])
248    _common_op_test("op_log1p_test", ["aten", "portable"])
249    _common_op_test("op_log2_test", ["aten", "portable"])
250    _common_op_test("op_logical_and_test", ["aten", "portable"])
251    _common_op_test("op_logical_not_test", ["aten", "portable"])
252    _common_op_test("op_logical_or_test", ["aten", "portable"])
253    _common_op_test("op_logical_xor_test", ["aten", "portable"])
254    _common_op_test("op_logit_test", ["aten", "portable"])
255    _common_op_test("op_lt_test", ["aten", "portable"])
256    _common_op_test("op_masked_fill_test", ["aten", "portable"])
257    _common_op_test("op_masked_scatter_test", ["aten", "portable"])
258    _common_op_test("op_masked_select_test", ["aten", "portable"])
259    _common_op_test("op_max_test", ["aten", "portable"])
260    _common_op_test("op_max_pool2d_with_indices_test", ["aten", "portable"])
261    _common_op_test("op_maximum_test", ["aten", "portable"])
262    _common_op_test("op_mean_test", ["aten", "portable"])
263    _common_op_test("op_min_test", ["aten", "portable"])
264    _common_op_test("op_minimum_test", ["aten", "portable"])
265    _common_op_test("op_mm_test", ["aten", "portable", "optimized"])
266    _common_op_test("op_mul_test", ["aten", "portable", "optimized"])
267    _common_op_test("op_narrow_copy_test", ["aten", "portable"])
268    _common_op_test("op_native_batch_norm_test", ["aten", "portable"])
269    _common_op_test("op_native_group_norm_test", ["aten", "portable"])
270    _common_op_test("op_native_layer_norm_test", ["aten", "portable", "optimized"])
271    _common_op_test("op_ne_test", ["aten", "portable"])
272    _common_op_test("op_neg_test", ["aten", "portable", "optimized"])
273    _common_op_test("op_nonzero_test", ["aten", "portable"])
274    _common_op_test("op_ones_test", ["aten", "portable"])
275    _common_op_test("op_pdist_forward_test", ["aten", "portable"])
276    _common_op_test("op_permute_copy_test", ["aten", "portable"])
277    _common_op_test("op_pixel_shuffle_test", ["aten", "portable"])
278    _common_op_test("op_pixel_unshuffle_test", ["aten", "portable"])
279    _common_op_test("op_pow_test", ["aten", "portable"])
280    _common_op_test("op_prod_test", ["aten", "portable"])
281    _common_op_test("op_reciprocal_test", ["aten", "portable"])
282    _common_op_test("op_relu_test", ["aten", "portable"])
283    _common_op_test("op_remainder_test", ["aten", "portable"])
284    _common_op_test("op_repeat_test", ["aten", "portable"])
285    _common_op_test("op_reflection_pad1d_test", ["aten", "portable"])
286    _common_op_test("op_reflection_pad2d_test", ["aten", "portable"])
287    _common_op_test("op_reflection_pad3d_test", ["aten", "portable"])
288    _common_op_test("op_replication_pad1d_test", ["aten", "portable"])
289    _common_op_test("op_replication_pad2d_test", ["aten", "portable"])
290    _common_op_test("op_replication_pad3d_test", ["aten", "portable"])
291    _common_op_test("op_roll_test", ["aten", "portable"])
292    _common_op_test("op_round_test", ["aten", "portable"])
293    _common_op_test("op_rsqrt_test", ["aten", "portable"])
294    _common_op_test("op_rsub_test", ["aten", "portable"])
295    _common_op_test("op_scalar_tensor_test", ["aten", "portable"])
296    _common_op_test("op_scatter_test", ["aten", "portable"])
297    _common_op_test("op_scatter_add_test", ["aten", "portable"])
298    _common_op_test("op_select_scatter_test", ["aten", "portable"])
299    _common_op_test("op_select_copy_test", ["aten", "portable"])
300    _common_op_test("op_sigmoid_test", ["aten", "portable", "optimized"])
301    _common_op_test("op_sign_test", ["aten", "portable"])
302    _common_op_test("op_sin_test", ["aten", "portable"])
303    _common_op_test("op_sinh_test", ["aten", "portable"])
304    _common_op_test("op_slice_scatter_test", ["aten", "portable"])
305    _common_op_test("op_slice_copy_test", ["aten", "portable"])
306    _common_op_test("op_softmax_test", ["aten", "portable"])
307    _common_op_test("op_split_copy_test", ["aten", "portable"])
308    _common_op_test("op_split_with_sizes_copy_test", ["aten", "portable"])
309    _common_op_test("op_sqrt_test", ["aten", "portable"])
310    _common_op_test("op_squeeze_copy_test", ["aten", "portable"])
311    _common_op_test("op_stack_test", ["aten", "portable"])
312    _common_op_test("op_sub_test", ["aten", "portable", "optimized"])
313    _common_op_test("op_sum_test", ["aten", "portable"])
314    _common_op_test("op_t_copy_test", ["aten", "portable"])
315    _common_op_test("op_tan_test", ["aten", "portable"])
316    _common_op_test("op_tanh_test", ["aten", "portable"])
317    _common_op_test("op_to_copy_test", ["aten", "portable"])
318    _common_op_test("op_topk_test", ["aten", "portable"])
319    _common_op_test("op_transpose_copy_test", ["aten", "portable"])
320    _common_op_test("op_tril_test", ["aten", "portable"])
321    _common_op_test("op_trunc_test", ["aten", "portable"])
322    _common_op_test("op_unbind_copy_test", ["aten", "portable"])
323    _common_op_test("op_unsqueeze_copy_test", ["aten", "portable"])
324    _common_op_test("op_var_test", ["aten", "portable"])
325    _common_op_test("op_view_copy_test", ["aten", "portable"])
326    _common_op_test("op_where_test", ["aten", "portable"])
327    _common_op_test("op_zeros_test", ["aten", "portable"])
328
329    make_example_generated_op_test_target()
330