From 199a5b5bda9b511ed8714dbc789cd2807be2e140 Mon Sep 17 00:00:00 2001 From: Andrzej Warzynski Date: Mon, 25 Mar 2024 11:10:00 +0000 Subject: [PATCH 1/5] [mlir][test] Make SME e2e tests require an emulator Integration tests for ArmSME require an emulator (there's no hardware available). Disable the tests when an emulator is not available. I'm also adding a note in the docs for future reference. --- mlir/docs/Dialects/ArmSME.md | 8 ++++++++ .../Integration/Dialect/Linalg/CPU/ArmSME/lit.local.cfg | 4 ++++ .../Integration/Dialect/Vector/CPU/ArmSME/lit.local.cfg | 4 ++++ 3 files changed, 16 insertions(+) diff --git a/mlir/docs/Dialects/ArmSME.md b/mlir/docs/Dialects/ArmSME.md index 7326150bcd115..66f62d07a7854 100644 --- a/mlir/docs/Dialects/ArmSME.md +++ b/mlir/docs/Dialects/ArmSME.md @@ -14,6 +14,14 @@ integration tests for reference: * [Linalg/CPU/ArmSME/matmul.mlir](https://github.com/llvm/llvm-project/blob/main/mlir/test/Integration/Dialect/Linalg/CPU/ArmSME/matmul.mlir) * [Vector/CPU/ArmSME/test-outerproduct-f64.mlir](https://github.com/llvm/llvm-project/blob/main/mlir/test/Integration/Dialect/Vector/CPU/ArmSME/test-outerproduct-f64.mlir) +In order to run ArmSME integration tests, include these flags in the CMake +invokation when configuring LLVM and MLIR: +```bash + -DMLIR_INCLUDE_INTEGRATION_TESTS=On + -DMLIR_RUN_ARM_SME_TESTS=On + -DARM_EMULATOR_EXECUTABLE= +``` + These tests are run "post-commit" by the [clang-aarch64-sve-vla](https://lab.llvm.org/buildbot/#/builders/197) LLVM BuildBot worker. diff --git a/mlir/test/Integration/Dialect/Linalg/CPU/ArmSME/lit.local.cfg b/mlir/test/Integration/Dialect/Linalg/CPU/ArmSME/lit.local.cfg index 296b4419438e8..083574b1af74d 100644 --- a/mlir/test/Integration/Dialect/Linalg/CPU/ArmSME/lit.local.cfg +++ b/mlir/test/Integration/Dialect/Linalg/CPU/ArmSME/lit.local.cfg @@ -4,6 +4,10 @@ import sys if not config.mlir_run_arm_sme_tests: config.unsupported = True +# With no hardware available, ArmSME tests require emulation. +if not config.arm_emulator_executable: + config.unsupported = True + # No JIT on win32. if sys.platform == "win32": config.unsupported = True diff --git a/mlir/test/Integration/Dialect/Vector/CPU/ArmSME/lit.local.cfg b/mlir/test/Integration/Dialect/Vector/CPU/ArmSME/lit.local.cfg index 296b4419438e8..083574b1af74d 100644 --- a/mlir/test/Integration/Dialect/Vector/CPU/ArmSME/lit.local.cfg +++ b/mlir/test/Integration/Dialect/Vector/CPU/ArmSME/lit.local.cfg @@ -4,6 +4,10 @@ import sys if not config.mlir_run_arm_sme_tests: config.unsupported = True +# With no hardware available, ArmSME tests require emulation. +if not config.arm_emulator_executable: + config.unsupported = True + # No JIT on win32. if sys.platform == "win32": config.unsupported = True From 891e2fc0a047ef5448ff9dac7e5e03740738edbe Mon Sep 17 00:00:00 2001 From: Andrzej Warzynski Date: Tue, 26 Mar 2024 11:37:22 +0000 Subject: [PATCH 2/5] fixup! [mlir][test] Make SME e2e tests require an emulator Switch to using CMake instead --- mlir/test/CMakeLists.txt | 5 +++++ .../test/Integration/Dialect/Linalg/CPU/ArmSME/lit.local.cfg | 4 ---- .../test/Integration/Dialect/Vector/CPU/ArmSME/lit.local.cfg | 4 ---- 3 files changed, 5 insertions(+), 8 deletions(-) diff --git a/mlir/test/CMakeLists.txt b/mlir/test/CMakeLists.txt index baf07ea1f010a..88b88116def6e 100644 --- a/mlir/test/CMakeLists.txt +++ b/mlir/test/CMakeLists.txt @@ -39,6 +39,11 @@ if (MLIR_INCLUDE_INTEGRATION_TESTS) option(MLIR_RUN_ARM_SVE_TESTS "Run Arm SVE tests.") option(MLIR_RUN_ARM_SME_TESTS "Run Arm SME tests.") + # With no ArmSME hardware available today, we need to make sure that ArmSME + # e2e are only run when an emulator has been set. + if (MLIR_RUN_ARM_SME_TESTS AND ARM_EMULATOR_EXECUTABLE STREQUAL "") + message(FATAL_ERROR "MLIR_RUN_SME_TESTS requires an emuator, but ARM_EMULATOR_EXECUTABLE is not set") + endif() # The native target may not be enabled when cross compiling, raise an error. if(NOT MLIR_ENABLE_EXECUTION_ENGINE) diff --git a/mlir/test/Integration/Dialect/Linalg/CPU/ArmSME/lit.local.cfg b/mlir/test/Integration/Dialect/Linalg/CPU/ArmSME/lit.local.cfg index 083574b1af74d..296b4419438e8 100644 --- a/mlir/test/Integration/Dialect/Linalg/CPU/ArmSME/lit.local.cfg +++ b/mlir/test/Integration/Dialect/Linalg/CPU/ArmSME/lit.local.cfg @@ -4,10 +4,6 @@ import sys if not config.mlir_run_arm_sme_tests: config.unsupported = True -# With no hardware available, ArmSME tests require emulation. -if not config.arm_emulator_executable: - config.unsupported = True - # No JIT on win32. if sys.platform == "win32": config.unsupported = True diff --git a/mlir/test/Integration/Dialect/Vector/CPU/ArmSME/lit.local.cfg b/mlir/test/Integration/Dialect/Vector/CPU/ArmSME/lit.local.cfg index 083574b1af74d..296b4419438e8 100644 --- a/mlir/test/Integration/Dialect/Vector/CPU/ArmSME/lit.local.cfg +++ b/mlir/test/Integration/Dialect/Vector/CPU/ArmSME/lit.local.cfg @@ -4,10 +4,6 @@ import sys if not config.mlir_run_arm_sme_tests: config.unsupported = True -# With no hardware available, ArmSME tests require emulation. -if not config.arm_emulator_executable: - config.unsupported = True - # No JIT on win32. if sys.platform == "win32": config.unsupported = True From 85b819b174a218481efa7214c88f0fdb6ded7fbe Mon Sep 17 00:00:00 2001 From: Andrzej Warzynski Date: Tue, 26 Mar 2024 13:01:24 +0000 Subject: [PATCH 3/5] fixup! fixup! [mlir][test] Make SME e2e tests require an emulator Fix typos --- mlir/test/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mlir/test/CMakeLists.txt b/mlir/test/CMakeLists.txt index 88b88116def6e..711cd98928b80 100644 --- a/mlir/test/CMakeLists.txt +++ b/mlir/test/CMakeLists.txt @@ -42,7 +42,7 @@ if (MLIR_INCLUDE_INTEGRATION_TESTS) # With no ArmSME hardware available today, we need to make sure that ArmSME # e2e are only run when an emulator has been set. if (MLIR_RUN_ARM_SME_TESTS AND ARM_EMULATOR_EXECUTABLE STREQUAL "") - message(FATAL_ERROR "MLIR_RUN_SME_TESTS requires an emuator, but ARM_EMULATOR_EXECUTABLE is not set") + message(FATAL_ERROR "MLIR_RUN_ARM_SME_TESTS requires an emulator, but ARM_EMULATOR_EXECUTABLE is not set") endif() # The native target may not be enabled when cross compiling, raise an error. From af5a2cc7977b7d60ac91199e4b748fbeb04b9973 Mon Sep 17 00:00:00 2001 From: Andrzej Warzynski Date: Sun, 31 Mar 2024 17:11:35 +0000 Subject: [PATCH 4/5] [mlir][test] Extend CMake logic for e2e tests Adds two new CMake functions to query the host system: * `check_hwcap`, * `check_emulator`. Together, these functions are used to check whether a given set of MLIR integration tests require an emulator. If yes, then the corresponding CMake var that defies the required emulator executable is also checked. `check_hwcap` relies on ELF_HWCAP for discovering CPU features from userspace on Linux systems. This is the recommended approach for Arm CPUs running on Linux as outlined in this blog post: * https://community.arm.com/arm-community-blogs/b/operating-systems-blog/posts/runtime-detection-of-cpu-features-on-an-armv8-a-cpu Other operating systems (e.g. Android) and CPU architectures will most likely require some other approach. Right now these new hooks are only used for SVE and SME integration tests. --- mlir/test/CMakeLists.txt | 107 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 102 insertions(+), 5 deletions(-) diff --git a/mlir/test/CMakeLists.txt b/mlir/test/CMakeLists.txt index 711cd98928b80..ba3fc74c78a3e 100644 --- a/mlir/test/CMakeLists.txt +++ b/mlir/test/CMakeLists.txt @@ -13,6 +13,104 @@ set(MLIR_CMAKE_DIR # Passed to lit.site.cfg.py.in to set up the path where to find libraries. set(MLIR_LIB_DIR ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}) +# Checks whether the specified hardware capability is supported by the host +# Linux system. This is implemented by checking auxiliary vector feature +# provided by the Linux kernel. +# +# check_hwcap( +# hwcap_spec +# output_var +# ) +# +# hwcap_spec - HWCAP value to check - these are defined in hwcap.h in the Linux +# kernel. +# +# output_var - Output variable to use to save the results (TRUE for supported, +# FALSE for not supported). +# +# EXAMPLES: +# +# check_hwcap("HWCAP2_SME" SME_EMULATOR_REQUIRED) +# +function(check_hwcap hwcap_spec output) + set(hwcap_test_src + [====[ + #include + #include + + int main(void) + { + long hwcaps = getauxval(AT_); + return (hwcaps & ) != 0; + } + ]====] + ) + + # Extract from $hwcap_spec whether this is AT_HWCAP or AT_HWCAP2 + string(FIND ${hwcap_spec} "_" wsloc) + string(SUBSTRING ${hwcap_spec} 0 ${wsloc} hwcap_vec) + + string(REPLACE "" ${hwcap_vec} hwcap_test_src "${hwcap_test_src}") + string(REPLACE "" ${hwcap_spec} hwcap_test_src "${hwcap_test_src}") + + set(hwcap_test_file ${CMAKE_BINARY_DIR}/${CMAKE_FILES_DIRECTORY}/hwcap_check.c) + file(WRITE ${hwcap_test_file} "${hwcap_test_src}") + + # Compile _and_ run + try_run( + test_run_result test_compile_result + ${CMAKE_BINARY_DIR} + ${hwcap_test_file} + ) + # Compilation will fail if hwcap_spec is not defined - this usually means + # that your Linux kernel is too old. + if(${test_compile_result} AND (DEFINED test_run_result)) + message(${test_run_result}) + message(STATUS "Checking whether ${hwcap_spec} is suported by the host system: ${test_run_result}") + set(${output} ${test_run_result} PARENT_SCOPE) + else() + message(STATUS "Checking whether ${hwcap_spec} is suppported by the host system: FALSE") + endif() +endfunction(check_hwcap) + +# For the given group of e2e tests (defined by the `mlir_e2e_tests` flag), +# checks whether an emulator is required. If yes, verifies that the +# corresponding CMake var pointing to an emulator (`emulator_exec`) has been +# set. +# +# check_emulator( +# mlir_e2e_tests +# hwcap_spec +# emulator_exec +# ) +# +# EXAMPLES: +# mlir_e2e_tests - MLIR CMake variables corresponding to the group of e2e tests +# to check +# hwcap_spec - HWCAP value to check. This should correspond to the hardware +# capabilities required by the tests to be checked. Possible +# values are defined in hwcap.h in the Linux kernel. +# emulator_exec - variable the defines the emulator (ought to be set if +# required, can be empty otherwise). +# +# check_emulator(MLIR_RUN_ARM_SVE_TESTS "HWCAP_SVE" ARM_EMULATOR_EXECUTABLE) +# +function(check_emulator mlir_e2e_tests hwcap_spec emulator_exec) + if (NOT ${mlir_e2e_tests}) + return() + endif() + + check_hwcap(${hwcap_spec} emulator_not_required) + if (${emulator_not_required}) + return() + endif() + + if (${emulator_exec} STREQUAL "") + message(FATAL_ERROR "${mlir_e2e_tests} requires an emulator, but ${emulator_exec} is not set") + endif() + +endfunction() + if (MLIR_INCLUDE_INTEGRATION_TESTS) set(INTEL_SDE_EXECUTABLE "" CACHE STRING "If set, arch-specific integration tests are run with Intel SDE.") @@ -39,11 +137,10 @@ if (MLIR_INCLUDE_INTEGRATION_TESTS) option(MLIR_RUN_ARM_SVE_TESTS "Run Arm SVE tests.") option(MLIR_RUN_ARM_SME_TESTS "Run Arm SME tests.") - # With no ArmSME hardware available today, we need to make sure that ArmSME - # e2e are only run when an emulator has been set. - if (MLIR_RUN_ARM_SME_TESTS AND ARM_EMULATOR_EXECUTABLE STREQUAL "") - message(FATAL_ERROR "MLIR_RUN_ARM_SME_TESTS requires an emulator, but ARM_EMULATOR_EXECUTABLE is not set") - endif() + # Check whether an emulator is required - if yes then make sure that it's + # been set. + check_emulator(MLIR_RUN_ARM_SVE_TESTS "HWCAP_SVE" ARM_EMULATOR_EXECUTABLE) + check_emulator(MLIR_RUN_ARM_SME_TESTS "HWCAP2_SME" ARM_EMULATOR_EXECUTABLE) # The native target may not be enabled when cross compiling, raise an error. if(NOT MLIR_ENABLE_EXECUTION_ENGINE) From 7531c0e29c8a28d11fee55f53c8f6142e90a22d6 Mon Sep 17 00:00:00 2001 From: Andrzej Warzynski Date: Thu, 4 Apr 2024 07:39:06 +0000 Subject: [PATCH 5/5] fixup! [mlir][test] Extend CMake logic for e2e tests Move new CMake logic to a seperate file, fix typos --- .../modules/MLIRCheckHardwareFeatures.cmake | 101 ++++++++++++++++++ mlir/docs/Dialects/ArmSME.md | 4 +- mlir/test/CMakeLists.txt | 100 +---------------- 3 files changed, 105 insertions(+), 100 deletions(-) create mode 100644 mlir/cmake/modules/MLIRCheckHardwareFeatures.cmake diff --git a/mlir/cmake/modules/MLIRCheckHardwareFeatures.cmake b/mlir/cmake/modules/MLIRCheckHardwareFeatures.cmake new file mode 100644 index 0000000000000..fff0424593fb9 --- /dev/null +++ b/mlir/cmake/modules/MLIRCheckHardwareFeatures.cmake @@ -0,0 +1,101 @@ +# A collection of helper CMake functions to detect hardware capabilities. At +# the moment these are used when configuring MLIR integration tests. + +# Checks whether the specified hardware capability is supported by the host +# Linux system. This is implemented by checking auxiliary vector feature +# provided by the Linux kernel. +# +# check_hwcap( +# hwcap_spec +# output_var +# ) +# +# hwcap_spec - HWCAP value to check - these are defined in hwcap.h in the Linux +# kernel. +# +# output_var - Output variable to use to save the results (TRUE for supported, +# FALSE for not supported). +# +# EXAMPLES: +# +# check_hwcap("HWCAP2_SME" SME_EMULATOR_REQUIRED) +# +function(check_hwcap hwcap_spec output) + set(hwcap_test_src + [====[ + #include + #include + + int main(void) + { + long hwcaps = getauxval(AT_); + return (hwcaps & ) != 0; + } + ]====] + ) + + # Extract from $hwcap_spec whether this is AT_HWCAP or AT_HWCAP2 + string(FIND ${hwcap_spec} "_" wsloc) + string(SUBSTRING ${hwcap_spec} 0 ${wsloc} hwcap_vec) + + string(REPLACE "" ${hwcap_vec} hwcap_test_src "${hwcap_test_src}") + string(REPLACE "" ${hwcap_spec} hwcap_test_src "${hwcap_test_src}") + + set(hwcap_test_file ${CMAKE_BINARY_DIR}/${CMAKE_FILES_DIRECTORY}/hwcap_check.c) + file(WRITE ${hwcap_test_file} "${hwcap_test_src}") + + # Compile _and_ run + try_run( + test_run_result test_compile_result + ${CMAKE_BINARY_DIR} + ${hwcap_test_file} + ) + # Compilation will fail if hwcap_spec is not defined - this usually means + # that your Linux kernel is too old. + if(${test_compile_result} AND (DEFINED test_run_result)) + message(${test_run_result}) + message(STATUS "Checking whether ${hwcap_spec} is supported by the host system: ${test_run_result}") + set(${output} ${test_run_result} PARENT_SCOPE) + else() + message(STATUS "Checking whether ${hwcap_spec} is supported by the host system: FALSE") + endif() +endfunction(check_hwcap) + +# For the given group of e2e tests (defined by the `mlir_e2e_tests` flag), +# checks whether an emulator is required. If yes, verifies that the +# corresponding CMake var pointing to an emulator (`emulator_exec`) has been +# set. +# +# check_emulator( +# mlir_e2e_tests +# hwcap_spec +# emulator_exec +# ) +# +# mlir_e2e_tests - MLIR CMake variables corresponding to the group of e2e tests +# to check +# hwcap_spec - HWCAP value to check. This should correspond to the hardware +# capabilities required by the tests to be checked. Possible +# values are defined in hwcap.h in the Linux kernel. +# emulator_exec - variable the defines the emulator (ought to be set if +# required, can be empty otherwise). +# +# EXAMPLES: +# +# check_emulator(MLIR_RUN_ARM_SVE_TESTS "HWCAP_SVE" ARM_EMULATOR_EXECUTABLE) +# +function(check_emulator mlir_e2e_tests hwcap_spec emulator_exec) + if (NOT ${mlir_e2e_tests}) + return() + endif() + + check_hwcap(${hwcap_spec} emulator_not_required) + if (${emulator_not_required}) + return() + endif() + + if (${emulator_exec} STREQUAL "") + message(FATAL_ERROR "${mlir_e2e_tests} requires an emulator, but ${emulator_exec} is not set") + endif() + +endfunction() diff --git a/mlir/docs/Dialects/ArmSME.md b/mlir/docs/Dialects/ArmSME.md index 66f62d07a7854..ce0a76ed60f19 100644 --- a/mlir/docs/Dialects/ArmSME.md +++ b/mlir/docs/Dialects/ArmSME.md @@ -6,7 +6,7 @@ This dialect defines custom and LLVM IR intrinsic operations that are used to target Arm Scalable Matrix Extension. Through the available conversion and ArmSME passes you can, for example, lower a [linalg.matmul](https://mlir.llvm.org/docs/Dialects/Linalg/#linalgmatmul-linalgmatmulop) -opereation to Arm SME +operation to Arm SME [FMOPA](https://developer.arm.com/documentation/ddi0602/2023-03/SME-Instructions/FMOPA--widening---Half-precision-floating-point-sum-of-outer-products-and-accumulate-) (floating-point outer product) operations. See one of the in-tree end-to-end integration tests for reference: @@ -15,7 +15,7 @@ integration tests for reference: * [Vector/CPU/ArmSME/test-outerproduct-f64.mlir](https://github.com/llvm/llvm-project/blob/main/mlir/test/Integration/Dialect/Vector/CPU/ArmSME/test-outerproduct-f64.mlir) In order to run ArmSME integration tests, include these flags in the CMake -invokation when configuring LLVM and MLIR: +invocation when configuring LLVM and MLIR: ```bash -DMLIR_INCLUDE_INTEGRATION_TESTS=On -DMLIR_RUN_ARM_SME_TESTS=On diff --git a/mlir/test/CMakeLists.txt b/mlir/test/CMakeLists.txt index ba3fc74c78a3e..5319a9cb33e00 100644 --- a/mlir/test/CMakeLists.txt +++ b/mlir/test/CMakeLists.txt @@ -1,3 +1,5 @@ +include(MLIRCheckHardwareFeatures) + add_subdirectory(CAPI) add_subdirectory(lib) @@ -13,104 +15,6 @@ set(MLIR_CMAKE_DIR # Passed to lit.site.cfg.py.in to set up the path where to find libraries. set(MLIR_LIB_DIR ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}) -# Checks whether the specified hardware capability is supported by the host -# Linux system. This is implemented by checking auxiliary vector feature -# provided by the Linux kernel. -# -# check_hwcap( -# hwcap_spec -# output_var -# ) -# -# hwcap_spec - HWCAP value to check - these are defined in hwcap.h in the Linux -# kernel. -# -# output_var - Output variable to use to save the results (TRUE for supported, -# FALSE for not supported). -# -# EXAMPLES: -# -# check_hwcap("HWCAP2_SME" SME_EMULATOR_REQUIRED) -# -function(check_hwcap hwcap_spec output) - set(hwcap_test_src - [====[ - #include - #include - - int main(void) - { - long hwcaps = getauxval(AT_); - return (hwcaps & ) != 0; - } - ]====] - ) - - # Extract from $hwcap_spec whether this is AT_HWCAP or AT_HWCAP2 - string(FIND ${hwcap_spec} "_" wsloc) - string(SUBSTRING ${hwcap_spec} 0 ${wsloc} hwcap_vec) - - string(REPLACE "" ${hwcap_vec} hwcap_test_src "${hwcap_test_src}") - string(REPLACE "" ${hwcap_spec} hwcap_test_src "${hwcap_test_src}") - - set(hwcap_test_file ${CMAKE_BINARY_DIR}/${CMAKE_FILES_DIRECTORY}/hwcap_check.c) - file(WRITE ${hwcap_test_file} "${hwcap_test_src}") - - # Compile _and_ run - try_run( - test_run_result test_compile_result - ${CMAKE_BINARY_DIR} - ${hwcap_test_file} - ) - # Compilation will fail if hwcap_spec is not defined - this usually means - # that your Linux kernel is too old. - if(${test_compile_result} AND (DEFINED test_run_result)) - message(${test_run_result}) - message(STATUS "Checking whether ${hwcap_spec} is suported by the host system: ${test_run_result}") - set(${output} ${test_run_result} PARENT_SCOPE) - else() - message(STATUS "Checking whether ${hwcap_spec} is suppported by the host system: FALSE") - endif() -endfunction(check_hwcap) - -# For the given group of e2e tests (defined by the `mlir_e2e_tests` flag), -# checks whether an emulator is required. If yes, verifies that the -# corresponding CMake var pointing to an emulator (`emulator_exec`) has been -# set. -# -# check_emulator( -# mlir_e2e_tests -# hwcap_spec -# emulator_exec -# ) -# -# EXAMPLES: -# mlir_e2e_tests - MLIR CMake variables corresponding to the group of e2e tests -# to check -# hwcap_spec - HWCAP value to check. This should correspond to the hardware -# capabilities required by the tests to be checked. Possible -# values are defined in hwcap.h in the Linux kernel. -# emulator_exec - variable the defines the emulator (ought to be set if -# required, can be empty otherwise). -# -# check_emulator(MLIR_RUN_ARM_SVE_TESTS "HWCAP_SVE" ARM_EMULATOR_EXECUTABLE) -# -function(check_emulator mlir_e2e_tests hwcap_spec emulator_exec) - if (NOT ${mlir_e2e_tests}) - return() - endif() - - check_hwcap(${hwcap_spec} emulator_not_required) - if (${emulator_not_required}) - return() - endif() - - if (${emulator_exec} STREQUAL "") - message(FATAL_ERROR "${mlir_e2e_tests} requires an emulator, but ${emulator_exec} is not set") - endif() - -endfunction() - if (MLIR_INCLUDE_INTEGRATION_TESTS) set(INTEL_SDE_EXECUTABLE "" CACHE STRING "If set, arch-specific integration tests are run with Intel SDE.")