[CI] Skip tests that need non-X86 LLVM targets in the BYO LLVM build (#25221) ukernel_inlining.mlir, added in https://github.com/iree-org/iree/pull/24833, compiles for aarch64 and riscv64, but byo_llvm.sh builds LLVM with only the X86 target. The test has failed the scheduled linux_x64_clang_byollvm job since https://github.com/iree-org/iree/pull/24833 landed. Move the aarch64 and riscv64 RUN lines into their own tests. CMake adds these tests only if iree_compiler_targeting_iree_arch() is true for their architecture. The same check decides whether CMake builds the ukernel bitcode for the architecture. Without the LLVM target, CMake writes an empty bitcode file instead, so the tests cannot pass in such a build. The Bazel build always has these targets. The aarch64 RUN lines also crashed iree-compile: populateDefaultsFromTargetMachine only asserted that LLVM could create the target machine, so builds without assertions dereferenced a null pointer. It now reports a fatal usage error. --------- Signed-off-by: Tobias Fuchs <fuchs@roofline.ai> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
diff --git a/compiler/plugins/target/LLVMCPU/LLVMTargetOptions.cpp b/compiler/plugins/target/LLVMCPU/LLVMTargetOptions.cpp index 366edf0..c5cfcad 100644 --- a/compiler/plugins/target/LLVMCPU/LLVMTargetOptions.cpp +++ b/compiler/plugins/target/LLVMCPU/LLVMTargetOptions.cpp
@@ -408,10 +408,10 @@ cachedTargetMachine = createTargetMachine(*this); // TODO(#13988): proper error propagation. This is a common user scenario. if (!cachedTargetMachine) { - llvm::errs() << "createTargetMachine(" << getTriple() - << ") failed; machine may not be " - "enabled in LLVM\n"; - assert(cachedTargetMachine && "createTargetMachine failed"); + llvm::reportFatalUsageError(llvm::Twine("createTargetMachine(") + + getTriple() + + ") failed; machine may not be enabled " + "in LLVM"); } } return cachedTargetMachine.get();
diff --git a/compiler/plugins/target/LLVMCPU/builtins/ukernel/test/BUILD.bazel b/compiler/plugins/target/LLVMCPU/builtins/ukernel/test/BUILD.bazel index 21c7a28..2c9afd4 100644 --- a/compiler/plugins/target/LLVMCPU/builtins/ukernel/test/BUILD.bazel +++ b/compiler/plugins/target/LLVMCPU/builtins/ukernel/test/BUILD.bazel
@@ -4,6 +4,7 @@ # See https://llvm.org/LICENSE.txt for license information. # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +load("//build_tools/bazel:build_defs.oss.bzl", "iree_cmake_extra_content") load("//build_tools/bazel:enforce_glob.bzl", "enforce_glob") load("//build_tools/bazel:iree_lit_test.bzl", "iree_lit_test_suite") @@ -25,6 +26,10 @@ "ukernel_inlining.mlir", ], include = ["*.mlir"], + exclude = [ + "ukernel_inlining_aarch64.mlir", + "ukernel_inlining_riscv64.mlir", + ], ), cfg = "//compiler:lit.cfg.py", tools = [ @@ -33,3 +38,58 @@ "@llvm-project//llvm:FileCheck", ], ) + +# The tests below compile for other architectures. That needs the LLVM target +# and the ukernel bitcode of the architecture. CMake builds both only if +# LLVM_TARGETS_TO_BUILD has the target, and only then adds the test. The Bazel +# build always has these targets. + +iree_cmake_extra_content( + content = """ +iree_compiler_targeting_iree_arch(_IREE_COMPILER_TARGETING_ARM_64 "arm_64") +if(_IREE_COMPILER_TARGETING_ARM_64) +""", + inline = True, +) + +iree_lit_test_suite( + name = "lit_aarch64", + srcs = ["ukernel_inlining_aarch64.mlir"], + cfg = "//compiler:lit.cfg.py", + tools = [ + "//tools:iree-compile", + "@llvm-project//llvm:FileCheck", + ], +) + +iree_cmake_extra_content( + content = """ +endif() +""", + inline = True, +) + +iree_cmake_extra_content( + content = """ +iree_compiler_targeting_iree_arch(_IREE_COMPILER_TARGETING_RISCV_64 "riscv_64") +if(_IREE_COMPILER_TARGETING_RISCV_64) +""", + inline = True, +) + +iree_lit_test_suite( + name = "lit_riscv64", + srcs = ["ukernel_inlining_riscv64.mlir"], + cfg = "//compiler:lit.cfg.py", + tools = [ + "//tools:iree-compile", + "@llvm-project//llvm:FileCheck", + ], +) + +iree_cmake_extra_content( + content = """ +endif() +""", + inline = True, +)
diff --git a/compiler/plugins/target/LLVMCPU/builtins/ukernel/test/CMakeLists.txt b/compiler/plugins/target/LLVMCPU/builtins/ukernel/test/CMakeLists.txt index 5d316e7..be5f62f 100644 --- a/compiler/plugins/target/LLVMCPU/builtins/ukernel/test/CMakeLists.txt +++ b/compiler/plugins/target/LLVMCPU/builtins/ukernel/test/CMakeLists.txt
@@ -26,4 +26,34 @@ iree-opt ) +iree_compiler_targeting_iree_arch(_IREE_COMPILER_TARGETING_ARM_64 "arm_64") +if(_IREE_COMPILER_TARGETING_ARM_64) + +iree_lit_test_suite( + NAME + lit_aarch64 + SRCS + "ukernel_inlining_aarch64.mlir" + TOOLS + FileCheck + iree-compile +) + +endif() + +iree_compiler_targeting_iree_arch(_IREE_COMPILER_TARGETING_RISCV_64 "riscv_64") +if(_IREE_COMPILER_TARGETING_RISCV_64) + +iree_lit_test_suite( + NAME + lit_riscv64 + SRCS + "ukernel_inlining_riscv64.mlir" + TOOLS + FileCheck + iree-compile +) + +endif() + ### BAZEL_TO_CMAKE_PRESERVES_ALL_CONTENT_BELOW_THIS_LINE ###
diff --git a/compiler/plugins/target/LLVMCPU/builtins/ukernel/test/ukernel_inlining.mlir b/compiler/plugins/target/LLVMCPU/builtins/ukernel/test/ukernel_inlining.mlir index 2d5f564..4e1147e 100644 --- a/compiler/plugins/target/LLVMCPU/builtins/ukernel/test/ukernel_inlining.mlir +++ b/compiler/plugins/target/LLVMCPU/builtins/ukernel/test/ukernel_inlining.mlir
@@ -10,39 +10,13 @@ // RUN: cat %t/x86/*.linked.ll | FileCheck %s --check-prefix=LINKED // RUN: cat %t/x86/*.optimized.ll | FileCheck %s --check-prefix=OPT -// aarch64, i8mm: -// RUN: iree-compile --iree-hal-target-device=local \ -// RUN: --iree-hal-local-target-device-backends=llvm-cpu \ -// RUN: --iree-llvmcpu-target-triple=aarch64-none-elf \ -// RUN: --iree-llvmcpu-target-cpu-features=+i8mm \ -// RUN: --iree-opt-data-tiling --iree-llvmcpu-enable-ukernels=mmt4d \ -// RUN: --iree-hal-dump-executable-intermediates-to=%t/i8mm %s -o /dev/null -// RUN: cat %t/i8mm/*.linked.ll | FileCheck %s --check-prefix=LINKED -// RUN: cat %t/i8mm/*.optimized.ll | FileCheck %s --check-prefix=OPT - -// aarch64, dotprod: -// RUN: iree-compile --iree-hal-target-device=local \ -// RUN: --iree-hal-local-target-device-backends=llvm-cpu \ -// RUN: --iree-llvmcpu-target-triple=aarch64-none-elf \ -// RUN: --iree-llvmcpu-target-cpu-features=+dotprod \ -// RUN: --iree-opt-data-tiling --iree-llvmcpu-enable-ukernels=mmt4d \ -// RUN: --iree-hal-dump-executable-intermediates-to=%t/dotprod %s -o /dev/null -// RUN: cat %t/dotprod/*.linked.ll | FileCheck %s --check-prefix=LINKED -// RUN: cat %t/dotprod/*.optimized.ll | FileCheck %s --check-prefix=OPT - -// riscv64, RVV + xsmtvdot: -// RUN: iree-compile --iree-hal-target-device=local \ -// RUN: --iree-hal-local-target-device-backends=llvm-cpu \ -// RUN: --iree-llvmcpu-target-triple=riscv64-unknown-elf \ -// RUN: --iree-llvmcpu-target-cpu-features=+m,+a,+f,+d,+c,+v,+xsmtvdot,+zvl256b \ -// RUN: --iree-opt-data-tiling --iree-llvmcpu-enable-ukernels=mmt4d \ -// RUN: --iree-hal-dump-executable-intermediates-to=%t/rvv %s -o /dev/null -// RUN: cat %t/rvv/*.linked.ll | FileCheck %s --check-prefix=LINKED -// RUN: cat %t/rvv/*.optimized.ll | FileCheck %s --check-prefix=OPT - // Ukernels must inline into the dispatch so their compile-time specialization -// can be DCE'd. For each target above, check that a ukernel is linked in and -// that, after optimization, no call to a ukernel symbol survives in the dispatch. +// can be DCE'd. Check that a ukernel is linked in and that, after optimization, +// no call to a ukernel symbol survives in the dispatch. +// +// ukernel_inlining_aarch64.mlir and ukernel_inlining_riscv64.mlir run the same +// checks on other targets. They are separate tests because they need LLVM +// targets that not every LLVM build includes. // LINKED: call {{.*}}@iree_uk_mmt4d( // OPT: define {{.*}}_dispatch_0
diff --git a/compiler/plugins/target/LLVMCPU/builtins/ukernel/test/ukernel_inlining_aarch64.mlir b/compiler/plugins/target/LLVMCPU/builtins/ukernel/test/ukernel_inlining_aarch64.mlir new file mode 100644 index 0000000..a425d27 --- /dev/null +++ b/compiler/plugins/target/LLVMCPU/builtins/ukernel/test/ukernel_inlining_aarch64.mlir
@@ -0,0 +1,39 @@ +// RUN: rm -rf %t && mkdir -p %t + +// aarch64, i8mm: +// RUN: iree-compile --iree-hal-target-device=local \ +// RUN: --iree-hal-local-target-device-backends=llvm-cpu \ +// RUN: --iree-llvmcpu-target-triple=aarch64-none-elf \ +// RUN: --iree-llvmcpu-target-cpu-features=+i8mm \ +// RUN: --iree-opt-data-tiling --iree-llvmcpu-enable-ukernels=mmt4d \ +// RUN: --iree-hal-dump-executable-intermediates-to=%t/i8mm %s -o /dev/null +// RUN: cat %t/i8mm/*.linked.ll | FileCheck %s --check-prefix=LINKED +// RUN: cat %t/i8mm/*.optimized.ll | FileCheck %s --check-prefix=OPT + +// aarch64, dotprod: +// RUN: iree-compile --iree-hal-target-device=local \ +// RUN: --iree-hal-local-target-device-backends=llvm-cpu \ +// RUN: --iree-llvmcpu-target-triple=aarch64-none-elf \ +// RUN: --iree-llvmcpu-target-cpu-features=+dotprod \ +// RUN: --iree-opt-data-tiling --iree-llvmcpu-enable-ukernels=mmt4d \ +// RUN: --iree-hal-dump-executable-intermediates-to=%t/dotprod %s -o /dev/null +// RUN: cat %t/dotprod/*.linked.ll | FileCheck %s --check-prefix=LINKED +// RUN: cat %t/dotprod/*.optimized.ll | FileCheck %s --check-prefix=OPT + +// Same checks as ukernel_inlining.mlir, on aarch64. CMake only adds this test +// if LLVM_TARGETS_TO_BUILD has AArch64, see BUILD.bazel. + +// LINKED: call {{.*}}@iree_uk_mmt4d( +// OPT: define {{.*}}_dispatch_0 +// OPT-NOT: call {{.*}}@iree_uk_ + +func.func @matmul(%a: tensor<128x128xi8>, %b: tensor<128x128xi8>) + -> tensor<128x128xi32> { + %c0 = arith.constant 0 : i32 + %init = tensor.empty() : tensor<128x128xi32> + %fill = linalg.fill ins(%c0 : i32) outs(%init : tensor<128x128xi32>) + -> tensor<128x128xi32> + %result = linalg.matmul ins(%a, %b : tensor<128x128xi8>, tensor<128x128xi8>) + outs(%fill : tensor<128x128xi32>) -> tensor<128x128xi32> + return %result : tensor<128x128xi32> +}
diff --git a/compiler/plugins/target/LLVMCPU/builtins/ukernel/test/ukernel_inlining_riscv64.mlir b/compiler/plugins/target/LLVMCPU/builtins/ukernel/test/ukernel_inlining_riscv64.mlir new file mode 100644 index 0000000..a977c0e --- /dev/null +++ b/compiler/plugins/target/LLVMCPU/builtins/ukernel/test/ukernel_inlining_riscv64.mlir
@@ -0,0 +1,29 @@ +// RUN: rm -rf %t && mkdir -p %t + +// riscv64, RVV + xsmtvdot: +// RUN: iree-compile --iree-hal-target-device=local \ +// RUN: --iree-hal-local-target-device-backends=llvm-cpu \ +// RUN: --iree-llvmcpu-target-triple=riscv64-unknown-elf \ +// RUN: --iree-llvmcpu-target-cpu-features=+m,+a,+f,+d,+c,+v,+xsmtvdot,+zvl256b \ +// RUN: --iree-opt-data-tiling --iree-llvmcpu-enable-ukernels=mmt4d \ +// RUN: --iree-hal-dump-executable-intermediates-to=%t/rvv %s -o /dev/null +// RUN: cat %t/rvv/*.linked.ll | FileCheck %s --check-prefix=LINKED +// RUN: cat %t/rvv/*.optimized.ll | FileCheck %s --check-prefix=OPT + +// Same checks as ukernel_inlining.mlir, on riscv64. CMake only adds this test +// if LLVM_TARGETS_TO_BUILD has RISCV, see BUILD.bazel. + +// LINKED: call {{.*}}@iree_uk_mmt4d( +// OPT: define {{.*}}_dispatch_0 +// OPT-NOT: call {{.*}}@iree_uk_ + +func.func @matmul(%a: tensor<128x128xi8>, %b: tensor<128x128xi8>) + -> tensor<128x128xi32> { + %c0 = arith.constant 0 : i32 + %init = tensor.empty() : tensor<128x128xi32> + %fill = linalg.fill ins(%c0 : i32) outs(%init : tensor<128x128xi32>) + -> tensor<128x128xi32> + %result = linalg.matmul ins(%a, %b : tensor<128x128xi8>, tensor<128x128xi8>) + outs(%fill : tensor<128x128xi32>) -> tensor<128x128xi32> + return %result : tensor<128x128xi32> +}
diff --git a/compiler/plugins/target/LLVMCPU/test/hal_target_device_attributes.mlir b/compiler/plugins/target/LLVMCPU/test/hal_target_device_attributes.mlir index f7c806c..c6ace54 100644 --- a/compiler/plugins/target/LLVMCPU/test/hal_target_device_attributes.mlir +++ b/compiler/plugins/target/LLVMCPU/test/hal_target_device_attributes.mlir
@@ -32,6 +32,14 @@ // // CHECK-INCORRECT-OPT-STACK-VALUE: for the --iree-llvmcpu-stack-allocation-limit option: '64266' value not a power-of-two +// A triple that no LLVM target supports must fail with an error, not crash, +// also in builds without assertions (`not` fails on a crash). +// +// RUN: not iree-compile --compile-to=preprocessing --iree-hal-target-device=local --iree-hal-local-target-device-backends=llvm-cpu --iree-llvmcpu-target-triple=unknownarch-unknown-unknown %s \ +// RUN: 2>&1 | FileCheck %s --check-prefix=CHECK-UNKNOWN-TARGET +// +// CHECK-UNKNOWN-TARGET: LLVM ERROR: createTargetMachine(unknownarch-unknown-unknown-eabi-elf) failed; machine may not be enabled in LLVM + // RUN: iree-compile --compile-to=preprocessing --iree-hal-target-device=local --iree-hal-local-target-device-backends=llvm-cpu --iree-llvmcpu-target-triple=x86_64-linux-gnu --iree-llvmcpu-enable-inner-tiled %s \ // RUN: | FileCheck %s --check-prefix=CHECK-INNER-TILED-FLAG //