xref: /aosp_15_r20/external/executorch/kernels/test/CMakeLists.txt (revision 523fa7a60841cd1ecfb9cc4201f1ca8b03ed023a)
1# Copyright (c) Meta Platforms, Inc. and affiliates.
2# All rights reserved.
3#
4# This source code is licensed under the BSD-style license found in the
5# LICENSE file in the root directory of this source tree.
6
7# This file should be formatted with
8# ~~~
9# cmake-format -i CMakeLists.txt
10# ~~~
11# It should also be cmake-lint clean.
12#
13
14cmake_minimum_required(VERSION 3.19)
15project(kernels_test)
16
17# Use C++17 for test.
18set(CMAKE_CXX_STANDARD 17)
19
20set(EXECUTORCH_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/../..)
21
22include(${EXECUTORCH_ROOT}/build/Test.cmake)
23
24set(_kernels portable optimized)
25
26foreach(kernel ${_kernels})
27  set(_wrapper_dir
28      "${CMAKE_CURRENT_BINARY_DIR}/include/${kernel}/executorch/kernels/test"
29  )
30  set(_wrapper_path "${_wrapper_dir}/FunctionHeaderWrapper.h")
31  add_custom_command(
32    OUTPUT "${_wrapper_path}"
33    COMMAND mkdir -p ${_wrapper_dir}
34    COMMAND echo "#include <executorch/kernels/${kernel}/Functions.h>" >
35            "${_wrapper_path}"
36    WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}"
37    COMMENT "Generating ${_wrapper_path}"
38    VERBATIM
39  )
40
41  add_custom_command(
42    OUTPUT "${_wrapper_dir}/supported_features.cpp"
43           "${_wrapper_dir}/supported_features.h"
44    COMMAND mkdir -p ${_wrapper_dir}
45    COMMAND
46      python kernels/test/gen_supported_features.py
47      kernels/${kernel}/test/supported_features_def.yaml >
48      ${_wrapper_dir}/supported_features.cpp
49    COMMAND
50      python kernels/test/gen_supported_features.py
51      kernels/test/supported_features.yaml >
52      ${_wrapper_dir}/supported_features.h
53    WORKING_DIRECTORY "${EXECUTORCH_ROOT}"
54    COMMENT "Generating ${_wrapper_dir}/supported_features.cpp and header"
55    VERBATIM
56  )
57endforeach()
58
59add_custom_target(
60  generate_wrapper
61  DEPENDS
62    "${CMAKE_CURRENT_BINARY_DIR}/include/portable/executorch/kernels/test/FunctionHeaderWrapper.h"
63    "${CMAKE_CURRENT_BINARY_DIR}/include/portable/executorch/kernels/test/supported_features.h"
64    "${CMAKE_CURRENT_BINARY_DIR}/include/portable/executorch/kernels/test/supported_features.cpp"
65    "${CMAKE_CURRENT_BINARY_DIR}/include/optimized/executorch/kernels/test/FunctionHeaderWrapper.h"
66    "${CMAKE_CURRENT_BINARY_DIR}/include/optimized/executorch/kernels/test/supported_features.h"
67    "${CMAKE_CURRENT_BINARY_DIR}/include/optimized/executorch/kernels/test/supported_features.cpp"
68)
69
70set(all_test_sources
71    "BinaryLogicalOpTest.cpp"
72    "op__to_dim_order_copy_test.cpp"
73    "op_abs_test.cpp"
74    "op_acos_test.cpp"
75    "op_acosh_test.cpp"
76    "op_add_test.cpp"
77    "op_addmm_test.cpp"
78    "op_alias_copy_test.cpp"
79    "op_amax_test.cpp"
80    "op_amin_test.cpp"
81    "op_any_test.cpp"
82    "op_arange_test.cpp"
83    "op_argmax_test.cpp"
84    "op_argmin_test.cpp"
85    "op_as_strided_copy_test.cpp"
86    "op_asin_test.cpp"
87    "op_asinh_test.cpp"
88    "op_atan_test.cpp"
89    "op_atan2_test.cpp"
90    "op_atanh_test.cpp"
91    "op_avg_pool2d_test.cpp"
92    "op_bitwise_and_test.cpp"
93    "op_bitwise_not_test.cpp"
94    "op_bitwise_or_test.cpp"
95    "op_bitwise_xor_test.cpp"
96    "op_bmm_test.cpp"
97    "op_cat_test.cpp"
98    "op_cdist_forward_test.cpp"
99    "op_ceil_test.cpp"
100    "op_clamp_test.cpp"
101    "op_clone_test.cpp"
102    "op_constant_pad_nd_test.cpp"
103    "op_convolution_test.cpp"
104    "op_copy_test.cpp"
105    "op_cos_test.cpp"
106    "op_cosh_test.cpp"
107    "op_cumsum_test.cpp"
108    "op_detach_copy_test.cpp"
109    "op_diagonal_copy_test.cpp"
110    "op_div_test.cpp"
111    "op_embedding_test.cpp"
112    "op_empty_test.cpp"
113    "op_eq_test.cpp"
114    "op_erf_test.cpp"
115    "op_exp_test.cpp"
116    "op_expand_copy_test.cpp"
117    "op_expm1_test.cpp"
118    "op_fill_test.cpp"
119    "op_flip_test.cpp"
120    "op_floor_divide_test.cpp"
121    "op_floor_test.cpp"
122    "op_fmod_test.cpp"
123    "op_full_like_test.cpp"
124    "op_full_test.cpp"
125    "op_ge_test.cpp"
126    "op_gelu_test.cpp"
127    "op_glu_test.cpp"
128    "op_gt_test.cpp"
129    "op_hardtanh_test.cpp"
130    "op_index_put_test.cpp"
131    "op_index_select_test.cpp"
132    "op_index_test.cpp"
133    "op_isinf_test.cpp"
134    "op_isnan_test.cpp"
135    "op_le_test.cpp"
136    "op_leaky_relu_test.cpp"
137    "op_lift_fresh_copy_test.cpp"
138    "op_log_softmax_test.cpp"
139    "op_log_test.cpp"
140    "op_log10_test.cpp"
141    "op_log1p_test.cpp"
142    "op_log2_test.cpp"
143    "op_logical_and_test.cpp"
144    "op_logical_not_test.cpp"
145    "op_logical_or_test.cpp"
146    "op_logical_xor_test.cpp"
147    "op_logit_test.cpp"
148    "op_lt_test.cpp"
149    "op_masked_fill_test.cpp"
150    "op_max_test.cpp"
151    "op_max_pool2d_with_indices_test.cpp"
152    "op_maximum_test.cpp"
153    "op_mean_test.cpp"
154    "op_min_test.cpp"
155    "op_minimum_test.cpp"
156    "op_mm_test.cpp"
157    "op_mul_test.cpp"
158    "op_pow_test.cpp"
159    "op_native_batch_norm_test.cpp"
160    "op_native_group_norm_test.cpp"
161    "op_native_layer_norm_test.cpp"
162    "op_ne_test.cpp"
163    "op_neg_test.cpp"
164    "op_nonzero_test.cpp"
165    "op_ones_test.cpp"
166    "op_pdist_forward_test.cpp"
167    "op_permute_copy_test.cpp"
168    "op_pixel_shuffle_test.cpp"
169    "op_prod_test.cpp"
170    "op_reciprocal_test.cpp"
171    "op_relu_test.cpp"
172    "op_remainder_test.cpp"
173    "op_repeat_test.cpp"
174    "op_reflection_pad1d_test.cpp"
175    "op_reflection_pad2d_test.cpp"
176    "op_reflection_pad3d_test.cpp"
177    "op_replication_pad1d_test.cpp"
178    "op_replication_pad2d_test.cpp"
179    "op_replication_pad3d_test.cpp"
180    "op_roll_test.cpp"
181    "op_round_test.cpp"
182    "op_rsqrt_test.cpp"
183    "op_rsub_test.cpp"
184    "op_scalar_tensor_test.cpp"
185    "op_scatter_add_test.cpp"
186    "op_select_scatter_test.cpp"
187    "op_select_copy_test.cpp"
188    "op_sigmoid_test.cpp"
189    "op_sign_test.cpp"
190    "op_sin_test.cpp"
191    "op_sinh_test.cpp"
192    "op_slice_scatter_test.cpp"
193    "op_slice_copy_test.cpp"
194    "op_softmax_test.cpp"
195    "op_split_copy_test.cpp"
196    "op_split_with_sizes_copy_test.cpp"
197    "op_sqrt_test.cpp"
198    "op_squeeze_copy_test.cpp"
199    "op_stack_test.cpp"
200    "op_sub_test.cpp"
201    "op_sum_test.cpp"
202    "op_t_copy_test.cpp"
203    "op_tan_test.cpp"
204    "op_tanh_test.cpp"
205    "op_to_copy_test.cpp"
206    "op_transpose_copy_test.cpp"
207    "op_tril_test.cpp"
208    "op_trunc_test.cpp"
209    "op_unbind_copy_test.cpp"
210    "op_unsqueeze_copy_test.cpp"
211    "op_var_test.cpp"
212    "op_view_copy_test.cpp"
213    "op_where_test.cpp"
214    "op_zeros_test.cpp"
215    "UnaryUfuncRealHBBF16ToFloatHBF16Test.cpp"
216  )
217
218set(_portable_kernels_test_sources
219    ${all_test_sources}
220    ${CMAKE_CURRENT_BINARY_DIR}/include/portable/executorch/kernels/test/supported_features.cpp
221)
222
223et_cxx_test(
224  portable_kernels_test SOURCES ${_portable_kernels_test_sources} EXTRA_LIBS
225  portable_kernels portable_ops_lib
226)
227add_dependencies(portable_kernels_test generate_wrapper)
228target_include_directories(
229  portable_kernels_test PRIVATE "${CMAKE_CURRENT_BINARY_DIR}/include/portable"
230                                "${CMAKE_INSTALL_PREFIX}/include"
231)
232
233set(_optimized_kernels_test_sources
234    "op_add_test.cpp"
235    "op_bmm_test.cpp"
236    "op_div_test.cpp"
237    "op_exp_test.cpp"
238    "op_gelu_test.cpp"
239    "op_le_test.cpp"
240    "op_log_softmax_test.cpp"
241    "op_mul_test.cpp"
242    "op_native_layer_norm_test.cpp"
243    "op_neg_test.cpp"
244    "op_sub_test.cpp"
245    "UnaryUfuncRealHBBF16ToFloatHBF16Test.cpp"
246    ${CMAKE_CURRENT_BINARY_DIR}/include/portable/executorch/kernels/test/supported_features.cpp
247)
248
249# We don't have sleef on OSS so we don't have gelu and log_softmax
250list(REMOVE_ITEM _optimized_kernels_test_sources "op_gelu_test.cpp"
251     "op_log_softmax_test.cpp"
252)
253
254et_cxx_test(
255  optimized_kernels_test
256  SOURCES
257  ${_optimized_kernels_test_sources}
258  EXTRA_LIBS
259  cpuinfo
260  extension_threadpool
261  optimized_kernels
262  optimized_ops_lib
263  portable_kernels
264  pthreadpool
265  eigen_blas
266)
267add_dependencies(optimized_kernels_test generate_wrapper)
268target_include_directories(
269  optimized_kernels_test PRIVATE "${CMAKE_CURRENT_BINARY_DIR}/include/optimized"
270                                 "${CMAKE_INSTALL_PREFIX}/include"
271)
272