From 1984298c71a273f468ba6c608c4e6689000a5600 Mon Sep 17 00:00:00 2001 From: plawanrath Date: Tue, 19 May 2026 13:40:27 -0700 Subject: [PATCH] Fix flash_attention_test link error on multi-target SIMD builds flash_attention_test.cc uses hwy/foreach_target.h and is compiled with HWY_IS_TEST=1, expanding the test TU for every attainable SIMD target (including EMU128). It references per-target symbols like gcpp::N_EMU128::FlashAttention, gcpp::N_EMU128::DotSoftmaxWeightedSum, and gcpp::N_EMU128::GetVTileSize, defined in libgemma's flash_attention.cc and attention.cc. libgemma is built without HWY_IS_TEST=1, so its foreach_target sources emit only the baseline+best targets, not EMU128. Linking fails with "Undefined symbols for architecture arm64: gcpp::N_EMU128::FlashAttention". When GEMMA_ENABLE_TESTS is enabled, build libgemma with HWY_IS_TEST=1 so its foreach_target sources emit all attainable targets, matching what the tests reference. Also add an explicit find_package(GTest REQUIRED): the CMakeLists references GTest::Main but the target only existed transitively via Highway's vendored gtest, which is unavailable when HWY_ENABLE_TESTS is disabled (required to avoid test-target name collisions with Highway's dot_test/image_test). Verified flash_attention_test now passes 3/3 cases across NEON_BF16, NEON_WITHOUT_AES, and EMU128 targets on arm64. No regressions in tensor_info_test, blob_store_test, fields_test, compress_test, sfp_test, nuq_test, distortion_test, ops_test, matmul_test, image_test, or basics_test. --- CMakeLists.txt | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 52dc7ca7..5bc037e7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -240,8 +240,18 @@ set(GEMMA_ENABLE_TESTS OFF CACHE BOOL "Enable Gemma tests") if (GEMMA_ENABLE_TESTS) enable_testing() +find_package(GTest REQUIRED) include(GoogleTest) +# Tests use HWY_IS_TEST=1 with `hwy/foreach_target.h`, which expands the test +# TU for every attainable SIMD target (including EMU128). libgemma's +# foreach_target sources (flash_attention.cc, attention.cc, gemma.cc, vit.cc) +# normally compile only for the baseline+best targets, so tests would fail to +# link against per-target symbols like N_EMU128::FlashAttention. Build +# libgemma for all attainable targets when tests are enabled, matching what +# the tests reference. +target_compile_definitions(libgemma PRIVATE HWY_IS_TEST=1) + set(GEMMA_TEST_FILES compression/compress_test.cc compression/distortion_test.cc