Elffuss BraidHub

kikocis/kleidiai public

655592420abd · 7.0 KiBRawPermalink
1#
2# SPDX-FileCopyrightText: Copyright 2026 Arm Limited and/or its affiliates <open-source-office@arm.com>
3#
4# SPDX-License-Identifier: Apache-2.0
5#
6
7include(FetchGTest)
8enable_testing()
9include(GoogleTest)
10
11add_library(kleidiai_test_framework
12 test/common/bfloat16.cpp
13 test/common/bfloat16_asm.S
14 test/common/buffer.cpp
15 test/common/compare.cpp
16 test/common/cpu_info.cpp
17 test/common/data_format.cpp
18 test/common/data_type.cpp
19 test/common/float16.cpp
20 test/common/float16_asm.S
21 test/common/int2.cpp
22 test/common/int4.cpp
23 test/common/matmul_test_common.cpp
24 test/common/matrix_portion.cpp
25 test/common/memory.cpp
26 test/common/printer.cpp
27 test/common/rect.cpp
28 test/common/round.cpp
29 test/common/round_asm.S
30 test/common/seed.cpp
31 $<$<NOT:$<BOOL:${MSVC}>>:test/common/sme.cpp>
32 test/common/sve.cpp
33
34 test/reference/binary_elementwise.cpp
35 test/reference/cast.cpp
36 test/reference/clamp.cpp
37 test/reference/dwconv.cpp
38 test/reference/fill.cpp
39 test/reference/matmul.cpp
40 test/reference/matmul_pack.cpp
41 test/reference/pack.cpp
42 test/reference/pad.cpp
43 test/reference/quantize.cpp
44 test/reference/reduce.cpp
45 test/reference/reorder.cpp
46 test/reference/transpose.cpp
47
48 test/nextgen/common/test_config.cpp
49 test/nextgen/common/test_registry.cpp
50 test/nextgen/reference/unary_elementwise.cpp
51 test/nextgen/reference/binary_elementwise.cpp
52 test/nextgen/reference/reduce.cpp
53 test/nextgen/reference/quantize.cpp
54 test/nextgen/reference/dequantize.cpp
55 test/nextgen/reference/clamp.cpp
56 test/nextgen/reference/matmul.cpp
57 test/nextgen/reference/print.cpp
58 test/nextgen/reference/pack.cpp
59 test/nextgen/reference/compare.cpp
60 test/nextgen/format/plain_format.cpp
61 test/nextgen/format/block2d_row_format.cpp
62 test/nextgen/quantization/asymm_linear_quantizer.cpp
63 test/nextgen/quantization/symm_linear_quantizer.cpp
64 test/nextgen/operators/matmul/pack_lhs/matmul_pack_lhs_wrapper_registry.cpp
65 test/nextgen/operators/matmul/pack_lhs/matmul_pack_lhs_dq_wrapper.cpp
66 test/nextgen/operators/matmul/pack_lhs/matmul_pack_lhs_fp_wrapper.cpp
67 test/nextgen/operators/matmul/pack_lhs/matmul_pack_lhs_ukerapi_wrapper.cpp
68 test/nextgen/operators/matmul/pack_rhs/matmul_pack_rhs_wrapper_registry.cpp
69 test/nextgen/operators/matmul/pack_rhs/matmul_pack_rhs_quant_wrapper.cpp
70 test/nextgen/operators/matmul/pack_rhs/matmul_pack_rhs_fp_nt_wrapper.cpp
71 test/nextgen/operators/matmul/matmul/matmul_wrapper_registry.cpp
72 test/nextgen/operators/matmul/matmul/matmul_dq_wrapper.cpp
73 test/nextgen/operators/matmul/matmul/matmul_fp_wrapper.cpp
74 test/nextgen/operators/matmul/matmul/matmul_ukerapi_wrapper.cpp
75 test/nextgen/operators/matmul/matmul_bias_mode.cpp
76 test/nextgen/operators/matmul/matmul_operator.cpp
77 test/nextgen/operators/matmul/matmul_tb.cpp
78)
79
80target_compile_options(kleidiai_test_framework
81 PUBLIC ${KLEIDIAI_WARNING_FLAGS}
82 PUBLIC $<$<NOT:$<BOOL:${MSVC}>>:-march=armv8-a${KLEIDIAI_INTERNAL_EXTRA_ARCH}>
83 PUBLIC $<$<COMPILE_LANG_AND_ID:CXX,MSVC>:/EHsc>
84)
85
86if(MSVC)
87 set_source_files_properties(
88 test/common/bfloat16_asm.S
89 test/common/float16_asm.S
90 test/common/round_asm.S
91 PROPERTIES LANGUAGE ASM_MARMASM)
92else()
93 set_source_files_properties(test/common/float16_asm.S PROPERTIES COMPILE_OPTIONS "-march=armv8.2-a+fp16${KLEIDIAI_INTERNAL_EXTRA_ARCH}")
94 set_source_files_properties(test/common/bfloat16_asm.S PROPERTIES COMPILE_OPTIONS "-march=armv8.2-a+fp16+bf16${KLEIDIAI_INTERNAL_EXTRA_ARCH}")
95 set_source_files_properties(test/common/sme.cpp PROPERTIES COMPILE_OPTIONS "-fno-tree-vectorize;-march=armv8.2-a+sve${KLEIDIAI_INTERNAL_EXTRA_ARCH}")
96endif()
97
98target_link_libraries(kleidiai_test_framework
99 PUBLIC kleidiai
100 PRIVATE GTest::gtest
101)
102
103if(MSVC)
104 set(KLEIDIAI_FILES_TESTS
105 test/tests/bfloat16_test.cpp
106 test/tests/float16_test.cpp
107 test/tests/matmul_clamp_f32_qai8dxp_qsu2cxp_test.cpp
108 test/tests/matmul_clamp_f32_qsi8d32p_qai4c32p_test.cpp
109 test/tests/matmul_clamp_bf16_qai8dxp_qsi4cxp_test.cpp
110 test/tests/matmul_clamp_qai8dxp_qsi4c32p_test.cpp
111 )
112else()
113 set(KLEIDIAI_FILES_TESTS
114 test/tests/bfloat16_test.cpp
115 test/tests/buffer_test.cpp
116 test/tests/float16_test.cpp
117 test/tests/imatmul_test.cpp
118 test/tests/dwconv_test.cpp
119 test/tests/matmul_clamp_bf16_qai8dxp_qsi4cxp_test.cpp
120 test/tests/matmul_clamp_f16_bf16p_bf16p_test.cpp
121 test/tests/matmul_clamp_f32_bf16p_bf16p_test.cpp
122 test/tests/matmul_clamp_f32_qai8dxp_qsu2cxp_test.cpp
123 test/tests/matmul_clamp_f32_f16p_qsi4c32p_test.cpp
124 test/tests/matmul_clamp_f32_qai8dxp_qsi4cxp_test.cpp
125 test/tests/matmul_clamp_f32_qai8dxp_qsi8cxp_test.cpp
126 test/tests/matmul_clamp_f32_qsi8d32p_qsi4c32p_test.cpp
127 test/tests/matmul_clamp_f32_qsi8d32p_qai4c32p_test.cpp
128 test/tests/matmul_clamp_f16_qsi8d32p_qai4c32p_test.cpp
129 test/tests/matmul_clamp_f16_qai8dxp_qsi4cxp_test.cpp
130 test/tests/matmul_clamp_f16_qai8dxp_qsi8cxp_test.cpp
131 test/tests/matmul_clamp_qai8_qai8p_qsi8cxp_test.cpp
132 test/tests/matmul_clamp_qai8dxp_qsi4c32p_test.cpp
133 test/tests/matmul_test.cpp
134
135 test/nextgen/tests/matmul_test_next.cpp
136 test/nextgen/tests/poly_test.cpp
137 )
138
139 set_source_files_properties(
140 test/tests/imatmul_test.cpp
141 test/tests/matmul_clamp_f16_bf16p_bf16p_test.cpp
142 test/tests/matmul_clamp_f32_bf16p_bf16p_test.cpp
143 test/tests/matmul_clamp_f32_qai8dxp_qsi4cxp_test.cpp
144 test/tests/matmul_clamp_qai8_qai8p_qsi8cxp_test.cpp
145 test/tests/matmul_test.cpp
146 PROPERTIES COMPILE_FLAGS "-Wpedantic")
147endif()
148
149# Build individual test binaries one per source file
150message(STATUS "Building individual test executables:")
151foreach(KLEIDIAI_TEST_FILE IN LISTS KLEIDIAI_FILES_TESTS)
152 get_filename_component(KLEIDIAI_TEST_NAME ${KLEIDIAI_TEST_FILE} NAME_WE)
153 add_executable(${KLEIDIAI_TEST_NAME}
154 ${KLEIDIAI_TEST_FILE}
155 test/nextgen/main.cpp
156 )
157 target_link_libraries(${KLEIDIAI_TEST_NAME}
158 PRIVATE kleidiai_test_framework
159 PRIVATE GTest::gtest
160 )
161 gtest_discover_tests(${KLEIDIAI_TEST_NAME} DISCOVERY_MODE PRE_TEST)
162 message(STATUS " ${KLEIDIAI_TEST_NAME}")
163endforeach()
164
165# Build monolithic test binary containing all tests
166message(STATUS "Building monolithic test executable: kleidiai_test")
167add_executable(kleidiai_test
168 ${KLEIDIAI_FILES_TESTS}
169 test/nextgen/main.cpp
170)
171target_link_libraries(kleidiai_test
172 PRIVATE kleidiai_test_framework
173 PRIVATE GTest::gtest
174)
175
176# Cross-compiling is a common use case which creates a conflict if DISCOVERY_MODE is set to POST_BUILD (by default)
177# since the host platform does not match the target. Setting the mode to PRE_TEST avoids this conflict. This feature
178# was added in CMake 3.18
179if(CMAKE_CROSSCOMPILING)
180 cmake_minimum_required(VERSION 3.18)
181endif()
182gtest_discover_tests(kleidiai_test DISCOVERY_MODE PRE_TEST)