@@ -13,6 +13,104 @@ set(MLIR_CMAKE_DIR
1313# Passed to lit.site.cfg.py.in to set up the path where to find libraries.
1414set (MLIR_LIB_DIR ${CMAKE_LIBRARY_OUTPUT_DIRECTORY} )
1515
16+ # Checks whether the specified hardware capability is supported by the host
17+ # Linux system. This is implemented by checking auxiliary vector feature
18+ # provided by the Linux kernel.
19+ #
20+ # check_hwcap(
21+ # hwcap_spec
22+ # output_var
23+ # )
24+ #
25+ # hwcap_spec - HWCAP value to check - these are defined in hwcap.h in the Linux
26+ # kernel.
27+ #
28+ # output_var - Output variable to use to save the results (TRUE for supported,
29+ # FALSE for not supported).
30+ #
31+ # EXAMPLES:
32+ #
33+ # check_hwcap("HWCAP2_SME" SME_EMULATOR_REQUIRED)
34+ #
35+ function (check_hwcap hwcap_spec output )
36+ set (hwcap_test_src
37+ [====[
38+ #include <asm/hwcap.h>
39+ #include <sys/auxv.h>
40+
41+ int main(void)
42+ {
43+ long hwcaps = getauxval(AT_<HWCAP_VEC>);
44+ return (hwcaps & <HWCAP_SPEC>) != 0;
45+ }
46+ ]====]
47+ )
48+
49+ # Extract from $hwcap_spec whether this is AT_HWCAP or AT_HWCAP2
50+ string (FIND ${hwcap_spec} "_" wsloc)
51+ string (SUBSTRING ${hwcap_spec} 0 ${wsloc} hwcap_vec)
52+
53+ string (REPLACE "<HWCAP_VEC>" ${hwcap_vec} hwcap_test_src "${hwcap_test_src} " )
54+ string (REPLACE "<HWCAP_SPEC>" ${hwcap_spec} hwcap_test_src "${hwcap_test_src} " )
55+
56+ set (hwcap_test_file ${CMAKE_BINARY_DIR} /${CMAKE_FILES_DIRECTORY} /hwcap_check.c)
57+ file (WRITE ${hwcap_test_file} "${hwcap_test_src} " )
58+
59+ # Compile _and_ run
60+ try_run (
61+ test_run_result test_compile_result
62+ ${CMAKE_BINARY_DIR}
63+ ${hwcap_test_file}
64+ )
65+ # Compilation will fail if hwcap_spec is not defined - this usually means
66+ # that your Linux kernel is too old.
67+ if (${test_compile_result} AND (DEFINED test_run_result))
68+ message (${test_run_result} )
69+ message (STATUS "Checking whether ${hwcap_spec} is suported by the host system: ${test_run_result} " )
70+ set (${output} ${test_run_result} PARENT_SCOPE)
71+ else ()
72+ message (STATUS "Checking whether ${hwcap_spec} is suppported by the host system: FALSE" )
73+ endif ()
74+ endfunction (check_hwcap)
75+
76+ # For the given group of e2e tests (defined by the `mlir_e2e_tests` flag),
77+ # checks whether an emulator is required. If yes, verifies that the
78+ # corresponding CMake var pointing to an emulator (`emulator_exec`) has been
79+ # set.
80+ #
81+ # check_emulator(
82+ # mlir_e2e_tests
83+ # hwcap_spec
84+ # emulator_exec
85+ # )
86+ #
87+ # EXAMPLES:
88+ # mlir_e2e_tests - MLIR CMake variables corresponding to the group of e2e tests
89+ # to check
90+ # hwcap_spec - HWCAP value to check. This should correspond to the hardware
91+ # capabilities required by the tests to be checked. Possible
92+ # values are defined in hwcap.h in the Linux kernel.
93+ # emulator_exec - variable the defines the emulator (ought to be set if
94+ # required, can be empty otherwise).
95+ #
96+ # check_emulator(MLIR_RUN_ARM_SVE_TESTS "HWCAP_SVE" ARM_EMULATOR_EXECUTABLE)
97+ #
98+ function (check_emulator mlir_e2e_tests hwcap_spec emulator_exec)
99+ if (NOT ${mlir_e2e_tests} )
100+ return ()
101+ endif ()
102+
103+ check_hwcap(${hwcap_spec} emulator_not_required)
104+ if (${emulator_not_required} )
105+ return ()
106+ endif ()
107+
108+ if (${emulator_exec} STREQUAL "" )
109+ message (FATAL_ERROR "${mlir_e2e_tests} requires an emulator, but ${emulator_exec} is not set" )
110+ endif ()
111+
112+ endfunction ()
113+
16114if (MLIR_INCLUDE_INTEGRATION_TESTS)
17115 set (INTEL_SDE_EXECUTABLE "" CACHE STRING
18116 "If set, arch-specific integration tests are run with Intel SDE." )
@@ -39,11 +137,10 @@ if (MLIR_INCLUDE_INTEGRATION_TESTS)
39137 option (MLIR_RUN_ARM_SVE_TESTS "Run Arm SVE tests." )
40138 option (MLIR_RUN_ARM_SME_TESTS "Run Arm SME tests." )
41139
42- # With no ArmSME hardware available today, we need to make sure that ArmSME
43- # e2e are only run when an emulator has been set.
44- if (MLIR_RUN_ARM_SME_TESTS AND ARM_EMULATOR_EXECUTABLE STREQUAL "" )
45- message (FATAL_ERROR "MLIR_RUN_ARM_SME_TESTS requires an emulator, but ARM_EMULATOR_EXECUTABLE is not set" )
46- endif ()
140+ # Check whether an emulator is required - if yes then make sure that it's
141+ # been set.
142+ check_emulator(MLIR_RUN_ARM_SVE_TESTS "HWCAP_SVE" ARM_EMULATOR_EXECUTABLE)
143+ check_emulator(MLIR_RUN_ARM_SME_TESTS "HWCAP2_SME" ARM_EMULATOR_EXECUTABLE)
47144
48145 # The native target may not be enabled when cross compiling, raise an error.
49146 if (NOT MLIR_ENABLE_EXECUTION_ENGINE)
0 commit comments