Skip to content

Compile bug: Vulkan Build Fails in Termux/Proot Due to Missing Cooperative Matrix Shader Variables #13801

Open
@Manamama

Description

@Manamama

Git commit

git rev-parse HEAD
79c137f

Operating systems

Other? (Please let us know in description)

GGML backends

Vulkan

Problem description & steps to reproduce

Termux. Related to: #13753 (comment)

Grok AI wrote most of below, I hope it is pithy enough:

When building llama.cpp with Vulkan support in a Termux (or the prooted Debian environment) on Android (aarch64) , the build fails due to undefined identifiers flash_attn_f32_f16_f16_f16acc_cm1_len and flash_attn_f32_f16_f16_f16acc_cm1_data in ggml/src/ggml-vulkan/ggml-vulkan.cpp. These errors occur when GL_KHR_cooperative_matrix is reported as supported by glslc, but the generated ggml-vulkan-shaders.hpp lacks the corresponding _cm1 variables. This is likely due to a mismatch between glslc's reported support and actual hardware/driver capabilities in Termux on an ARM device.

CMake: 3.31

Compiler: Clang 14.0.6

Vulkan Packages: libvulkan-dev, libshaderc-dev, glslc (2023.2-1)

Error
The build fails with:

/data/data/com.termux/files/home/downloads/llama.cpp/ggml/src/ggml-vulkan/ggml-vulkan.cpp:1992:9: error: use of undeclared identifier 'flash_attn_f32_f16_f16_f16acc_cm1_len'; did you mean 'flash_attn_f32_f16_f16_f16acc_len'?
/data/data/com.termux/files/home/downloads/llama.cpp/ggml/src/ggml-vulkan/ggml-vulkan.cpp:1992:9: error: use of undeclared identifier 'flash_attn_f32_f16_f16_f16acc_cm1_data'; did you mean 'flash_attn_f32_f16_f16_f16acc_data'?

This occurs because glslc reports GL_KHR_cooperative_matrix as supported:

-- GL_KHR_cooperative_matrix supported by glslc

But the generated ggml-vulkan-shaders.hpp does not include the _cm1 variables expected by the CREATE_FA(GGML_TYPE_F16, f16, FA_COOPMAT1, _cm1) macro call.
Workaround
To resolve this, I modified ggml/src/ggml-vulkan/CMakeLists.txt to force GGML_VULKAN_COOPMAT_GLSLC_SUPPORT=OFF, even when glslc reports support for GL_KHR_cooperative_matrix. This skips the cooperative matrix path, avoiding the undefined variables and allowing the build to proceed.
Modified CMakeLists.txt:

Fix needed:

cmake_minimum_required(VERSION 3.19)
cmake_policy(SET CMP0114 NEW)

find_package(Vulkan COMPONENTS glslc REQUIRED)
add_subdirectory(vulkan-shaders)

# Function to test shader extension support
function(test_shader_extension_support EXTENSION_NAME TEST_SHADER_FILE RESULT_VARIABLE)
    execute_process(
        COMMAND ${Vulkan_GLSLC_EXECUTABLE} -o - -fshader-stage=compute --target-env=vulkan1.3 "${TEST_SHADER_FILE}"
        OUTPUT_VARIABLE glslc_output
        ERROR_VARIABLE glslc_error
    )
    if (${glslc_error} MATCHES ".*extension not supported: ${EXTENSION_NAME}.*")
        message(STATUS "${EXTENSION_NAME} not supported by glslc")
        set(${RESULT_VARIABLE} OFF PARENT_SCOPE)
    else()
        message(STATUS "${EXTENSION_NAME} supported by glslc")
        set(${RESULT_VARIABLE} OFF PARENT_SCOPE) # Force OFF for cooperative matrix
        if (NOT "${EXTENSION_NAME}" STREQUAL "GL_KHR_cooperative_matrix")
            add_compile_definitions(${RESULT_VARIABLE})
        endif()
    endif()
endfunction()

if (Vulkan_FOUND)
    message(STATUS "Vulkan found")

    ggml_add_backend_library(ggml-vulkan
                             ggml-vulkan.cpp
                             ../../include/ggml-vulkan.h
                            )

    # Test all shader extensions
    test_shader_extension_support(
        "GL_KHR_cooperative_matrix"
        "${CMAKE_CURRENT_SOURCE_DIR}/vulkan-shaders/test_coopmat_support.comp"
        "GGML_VULKAN_COOPMAT_GLSLC_SUPPORT"
    )
    test_shader_extension_support(
        "GL_NV_cooperative_matrix2"
        "${CMAKE_CURRENT_SOURCE_DIR}/vulkan-shaders/test_coopmat2_support.comp"
        "GGML_VULKAN_COOPMAT2_GLSLC_SUPPORT"
    )
    test_shader_extension_support(
        "GL_EXT_integer_dot_product"
        "${CMAKE_CURRENT_SOURCE_DIR}/vulkan-shaders/test_integer_dot_support.comp"
        "GGML_VULKAN_INTEGER_DOT_GLSLC_SUPPORT"
    )
    test_shader_extension_support(
        "GL_EXT_bfloat16"
        "${CMAKE_CURRENT_SOURCE_DIR}/vulkan-shaders/test_bfloat16_support.comp"
        "GGML_VULKAN_BFLOAT16_GLSLC_SUPPORT"
    )

    target_link_libraries(ggml-vulkan PRIVATE Vulkan::Vulkan)
    target_include_directories(ggml-vulkan PRIVATE ${CMAKE_CURRENT_BINARY_DIR})

    if (MSVC AND CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
        add_compile_definitions(_ITERATOR_DEBUG_LEVEL=0)
    endif()

    if (GGML_VULKAN_CHECK_RESULTS)
        add_compile_definitions(GGML_VULKAN_CHECK_RESULTS)
    endif()
    if (GGML_VULKAN_DEBUG)
        add_compile_definitions(GGML_VULKAN_DEBUG)
    endif()
    if (GGML_VULKAN_MEMORY_DEBUG)
        add_compile_definitions(GGML_VULKAN_MEMORY_DEBUG)
    endif()
    if (GGML_VULKAN_SHADER_DEBUG_INFO)
        add_compile_definitions(GGML_VULKAN_SHADER_DEBUG_INFO)
    endif()
    if (GGML_VULKAN_PERF)
        add_compile_definitions(GGML_VULKAN_PERF)
    endif()
    if (GGML_VULKAN_VALIDATE)
        add_compile_definitions(GGML_VULKAN_VALIDATE)
    endif()
    if (GGML_VULKAN_RUN_TESTS)
        add_compile_definitions(GGML_VULKAN_RUN_TESTS)
    endif()

    set(_ggml_vk_header ${CMAKE_CURRENT_BINARY_DIR}/ggml-vulkan-shaders.hpp)
    set(_ggml_vk_source ${CMAKE_CURRENT_BINARY_DIR}/ggml-vulkan-shaders.cpp)
    set(_ggml_vk_input_dir ${CMAKE_CURRENT_SOURCE_DIR}/vulkan-shaders)
    set(_ggml_vk_output_dir ${CMAKE_CURRENT_BINARY_DIR}/vulkan-shaders.spv)
    set(_ggml_vk_genshaders_cmd ${CMAKE_BINARY_DIR}/bin/vulkan-shaders-gen)

    file(GLOB _ggml_vk_shader_deps "${_ggml_vk_input_dir}/*.comp")
    add_custom_command(
        OUTPUT ${_ggml_vk_header} ${_ggml_vk_source}
        COMMAND ${_ggml_vk_genshaders_cmd}
            --glslc ${Vulkan_GLSLC_EXECUTABLE}
            --input-dir ${_ggml_vk_input_dir}
            --output-dir ${_ggml_vk_output_dir}
            --target-hpp ${_ggml_vk_header}
            --target-cpp ${_ggml_vk_source}
            --no-clean
        DEPENDS vulkan-shaders-gen ${_ggml_vk_shader_deps}
        COMMENT "Generate vulkan shaders"
    )

    target_sources(ggml-vulkan PRIVATE ${_ggml_vk_source} ${_ggml_vk_header})

else()
    message(WARNING "Vulkan not found")
endif()

Why This Happens
The GL_KHR_cooperative_matrix extension is reported as supported by glslc, but the generated ggml-vulkan-shaders.hpp lacks the _cm1 variables (flash_attn_f32_f16_f16_f16acc_cm1_len and flash_attn_f32_f16_f16_f16acc_cm1_data) expected by ggml-vulkan.cpp:1992.

This is likely due to a hardware or driver limitation on the ARM device (realme RMX3085) in the Termux prooted environment, where glslc incorrectly reports support or fails to generate cooperative matrix shaders correctly.

Forcing GGML_VULKAN_COOPMAT_GLSLC_SUPPORT=OFF skips the cooperative matrix path, allowing the build to proceed without errors.

First Bad Commit

?

Compile command

cmake -S .   -B build -DLLAMA_CURL=ON -DCMAKE_BUILD_TYPE=Release  -DGGML_VULKAN=ON -DGGML_BLAS=ON -DGGML_BLAS_VENDOR=OpenBLAS -DGGML_CUDA=OFF  -DGGML_ARCH_FLAGS="-march=armv8.2-a+dotprod+fp16"    -DCMAKE_CXX_FLAGS="-g -O0 -fno-omit-frame-pointer"   -DLLAMA_BUILD_EXAMPLES=ON

Relevant log output

After the fix #13753 (comment) :

~/downloads/llama.cpp $ bash  ../_install_llama1.sh 
ver. 2.4
-- The C compiler identification is Clang 20.1.5
-- The CXX compiler identification is Clang 20.1.5
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /data/data/com.termux/files/usr/bin/clang - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /data/data/com.termux/files/usr/bin/clang++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Found Git: /data/data/com.termux/files/usr/bin/git (found version "2.49.0")
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD - Failed
-- Check if compiler accepts -pthread
-- Check if compiler accepts -pthread - yes
-- Found Threads: TRUE
-- ccache found, compilation results will be cached. Disable with GGML_CCACHE=OFF.
-- CMAKE_SYSTEM_PROCESSOR: aarch64
-- Including CPU backend
-- Found OpenMP_C: -fopenmp=libomp (found version "5.1")
-- Found OpenMP_CXX: -fopenmp=libomp (found version "5.1")
-- Found OpenMP: TRUE (found version "5.1")
-- ARM detected
-- Performing Test GGML_COMPILER_SUPPORTS_FP16_FORMAT_I3E
-- Performing Test GGML_COMPILER_SUPPORTS_FP16_FORMAT_I3E - Failed
-- ARM -mcpu not found, -mcpu=native will be used
-- Performing Test GGML_MACHINE_SUPPORTS_dotprod
-- Performing Test GGML_MACHINE_SUPPORTS_dotprod - Success
-- Performing Test GGML_MACHINE_SUPPORTS_i8mm
-- Performing Test GGML_MACHINE_SUPPORTS_i8mm - Failed
-- Performing Test GGML_MACHINE_SUPPORTS_noi8mm
-- Performing Test GGML_MACHINE_SUPPORTS_noi8mm - Success
-- Performing Test GGML_MACHINE_SUPPORTS_sve
-- Performing Test GGML_MACHINE_SUPPORTS_sve - Failed
-- Performing Test GGML_MACHINE_SUPPORTS_nosve
-- Performing Test GGML_MACHINE_SUPPORTS_nosve - Success
-- Performing Test GGML_MACHINE_SUPPORTS_sme
-- Performing Test GGML_MACHINE_SUPPORTS_sme - Failed
-- Performing Test GGML_MACHINE_SUPPORTS_nosme
-- Performing Test GGML_MACHINE_SUPPORTS_nosme - Success
-- ARM feature DOTPROD enabled
-- ARM feature FMA enabled
-- ARM feature FP16_VECTOR_ARITHMETIC enabled
-- Adding CPU backend variant ggml-cpu: -mcpu=native+dotprod+noi8mm+nosve+nosme 
-- Looking for sgemm_
-- Looking for sgemm_ - found
-- Found BLAS: /data/data/com.termux/files/usr/lib/libopenblas.so
-- BLAS found, Libraries: /data/data/com.termux/files/usr/lib/libopenblas.so
-- Found PkgConfig: /data/data/com.termux/files/usr/bin/pkg-config (found version "0.29.2")
-- Checking for module 'openblas64'
--   No package 'openblas64' found
-- Checking for module 'openblas'
--   Found openblas, version 0.3.29
-- BLAS found, Includes: /data/data/com.termux/files/usr/include/openblas
-- Including BLAS backend
-- Found Vulkan: /data/data/com.termux/files/usr/lib/libvulkan.so (found version "1.4.315") found components: glslc glslangValidator
-- Vulkan found
-- GL_KHR_cooperative_matrix supported by glslc
-- GL_NV_cooperative_matrix2 not supported by glslc
-- GL_EXT_integer_dot_product not supported by glslc
-- GL_EXT_bfloat16 not supported by glslc
-- Including Vulkan backend
-- Looking for pthread_create in pthreads
-- Looking for pthread_create in pthreads - not found
-- Looking for pthread_create in pthread
-- Looking for pthread_create in pthread - found
-- Found CURL: /data/data/com.termux/files/usr/lib/libcurl.so (found version "8.13.0")
-- Configuring done (29.1s)
-- Generating done (0.7s)
-- Build files have been written to: /data/data/com.termux/files/home/downloads/llama.cpp/build
[  0%] Building C object ggml/src/CMakeFiles/ggml-base.dir/ggml.c.o
[  1%] Building C object ggml/src/CMakeFiles/ggml-base.dir/ggml-alloc.c.o
[  1%] Building CXX object ggml/src/CMakeFiles/ggml-base.dir/ggml-backend.cpp.o
[  2%] Building CXX object ggml/src/CMakeFiles/ggml-base.dir/ggml-opt.cpp.o
[  2%] Building CXX object ggml/src/CMakeFiles/ggml-base.dir/ggml-threading.cpp.o
[  2%] Building C object ggml/src/CMakeFiles/ggml-base.dir/ggml-quants.c.o
[  3%] Building CXX object ggml/src/CMakeFiles/ggml-base.dir/gguf.cpp.o
[  3%] Linking CXX shared library ../../bin/libggml-base.so
[  3%] Built target ggml-base
[  4%] Building CXX object ggml/src/ggml-vulkan/vulkan-shaders/CMakeFiles/vulkan-shaders-gen.dir/vulkan-shaders-gen.cpp.o
[  4%] Linking CXX executable ../../../../bin/vulkan-shaders-gen
[  4%] Built target vulkan-shaders-gen
[  4%] Generate vulkan shaders
ggml_vulkan: Generating and compiling shaders to SPIR-V
[  5%] Building CXX object ggml/src/ggml-vulkan/CMakeFiles/ggml-vulkan.dir/ggml-vulkan.cpp.o
/data/data/com.termux/files/home/downloads/llama.cpp/ggml/src/ggml-vulkan/ggml-vulkan.cpp:1656:2: warning: extra ';' outside of a function is incompatible with C++98 [-Wc++98-compat-extra-semi]
 1656 | };
      |  ^
/data/data/com.termux/files/home/downloads/llama.cpp/ggml/src/ggml-vulkan/ggml-vulkan.cpp:1992:9: error: use of undeclared identifier 'flash_attn_f32_f16_f16_f16acc_cm1_len'; did you mean 'flash_attn_f32_f16_f16_f16acc_len'?
 1992 |         CREATE_FA(GGML_TYPE_F16, f16, FA_COOPMAT1, _cm1)
      |         ^
/data/data/com.termux/files/home/downloads/llama.cpp/ggml/src/ggml-vulkan/ggml-vulkan.cpp:1980:9: note: expanded from macro 'CREATE_FA'
 1980 |         CREATE_FA2(TYPE, NAMELC, FAPATH, SUFFIX, 64) \
      |         ^
/data/data/com.termux/files/home/downloads/llama.cpp/ggml/src/ggml-vulkan/ggml-vulkan.cpp:1970:181: note: expanded from macro 'CREATE_FA2'
 1970 |         ggml_vk_create_pipeline(device, device->pipeline_flash_attn_f32_f16_D ## D ## SUFFIX[TYPE][0][0][0], "flash_attn_f32_f16_D" #D "_f16acc"         #NAMELC #SUFFIX,           flash_attn_f32_f16_ ## NAMELC ## _f16acc ## SUFFIX ## _len,  flash_attn_f32_f16_ ## NAMELC ## _f16acc ## SUFFIX ## _data,  "main", 5, sizeof(vk_flash_attn_push_constants), fa_wg_denoms(FAPATH, D,1,TYPE,false), fa_spec_constants(FAPATH, D,1,TYPE,false), 1,                                      true, FAPATH==FA_COOPMAT1, (FAPATH==FA_COOPMAT1 ? 32 : 0));     \
      |                                                                                                                                                                                     ^
<scratch space>:59:1: note: expanded from here
   59 | flash_attn_f32_f16_f16_f16acc_cm1_len
      | ^
/data/data/com.termux/files/home/downloads/llama.cpp/build/ggml/src/ggml-vulkan/ggml-vulkan-shaders.hpp:241:16: note: 'flash_attn_f32_f16_f16_f16acc_len' declared here
  241 | const uint64_t flash_attn_f32_f16_f16_f16acc_len = 21516;
      |                ^
/data/data/com.termux/files/home/downloads/llama.cpp/ggml/src/ggml-vulkan/ggml-vulkan.cpp:1992:9: error: use of undeclared identifier 'flash_attn_f32_f16_f16_f16acc_cm1_data'; did you mean 'flash_attn_f32_f16_f16_f16acc_data'?
 1992 |         CREATE_FA(GGML_TYPE_F16, f16, FA_COOPMAT1, _cm1)

After that further fix here:

-- Build files have been written to: /data/data/com.termux/files/home/downloads/llama.cpp/build
[  3%] Built target ggml-base
[  4%] Built target vulkan-shaders-gen
[  5%] Building CXX object ggml/src/ggml-vulkan/CMakeFiles/ggml-vulkan.dir/ggml-vulkan.cpp.o
/data/data/com.termux/files/home/downloads/llama.cpp/ggml/src/ggml-vulkan/ggml-vulkan.cpp:1656:2: warning: extra ';' outside of a function is incompatible with C++98 [-Wc++98-compat-extra-semi]
 1656 | };
      |  ^
/data/data/com.termux/files/home/downloads/llama.cpp/ggml/src/ggml-vulkan/ggml-vulkan.cpp:5955:13: warning: 'return' will never be executed [-Wunreachable-code-return]
 5955 |             return;
      |             ^~~~~~
/data/data/com.termux/files/home/downloads/llama.cpp/ggml/src/ggml-vulkan/ggml-vulkan.cpp:5942:13: warning: 'return' will never be executed [-Wunreachable-code-return]
 5942 |             return;
      |             ^~~~~~
/data/data/com.termux/files/home/downloads/llama.cpp/ggml/src/ggml-vulkan/ggml-vulkan.cpp:5929:13: warning: 'return' will never be executed [-Wunreachable-code-return]
 5929 |             return;
      |             ^~~~~~
/data/data/com.termux/files/home/downloads/llama.cpp/ggml/src/ggml-vulkan/ggml-vulkan.cpp:7448:9: warning: suggest braces around initialization of subobject [-Wmissing-braces]
 7448 |         sections[0], sections[1], sections[2], sections[3], backprop
      |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      |         {                                                 }
/data/data/com.termux/files/home/downloads/llama.cpp/ggml/src/ggml-vulkan/ggml-vulkan.cpp:8613:16: warning: 'return' will never be executed [-Wunreachable-code-return]
 8613 |         return false;
      |                ^~~~~
/data/data/com.termux/files/home/downloads/llama.cpp/ggml/src/ggml-vulkan/ggml-vulkan.cpp:9919:15: warning: 'break' will never be executed [-Wunreachable-code-break]
 9919 |             } break;
      |               ^~~~~
/data/data/com.termux/files/home/downloads/llama.cpp/ggml/src/ggml-vulkan/ggml-vulkan.cpp:9867:15: warning: 'break' will never be executed [-Wunreachable-code-break]
 9867 |             } break;
      |               ^~~~~
/data/data/com.termux/files/home/downloads/llama.cpp/ggml/src/ggml-vulkan/ggml-vulkan.cpp:9770:15: warning: 'break' will never be executed [-Wunreachable-code-break]
 9770 |             } break;
      |               ^~~~~
/data/data/com.termux/files/home/downloads/llama.cpp/ggml/src/ggml-vulkan/ggml-vulkan.cpp:9709:13: warning: 'break' will never be executed [-Wunreachable-code-break]
 9709 |             break;
      |             ^~~~~
10 warnings generated.
[  5%] Building CXX object ggml/src/ggml-vulkan/CMakeFiles/ggml-vulkan.dir/ggml-vulkan-shaders.cpp.o
[  5%] Linking CXX shared library ../../../bin/libggml-vulkan.so
[  5%] Built target ggml-vulkan
[  5%] Building C object ggml/src/CMakeFiles/ggml-cpu.dir/ggml-cpu/ggml-cpu.c.o
[  6%] Building CXX object ggml/src/CMakeFiles/ggml-cpu.dir/ggml-cpu/ggml-cpu.cpp.o
[  6%] Building CXX object ggml/src/CMakeFiles/ggml-cpu.dir/ggml-cpu/ggml-cpu-aarch64.cpp.o
[  7%] Building CXX object ggml/src/CMakeFiles/ggml-cpu.dir/ggml-cpu/ggml-cpu-hbm.cpp.o
[  7%] Building C object ggml/src/CMakeFiles/ggml-cpu.dir/ggml-cpu/ggml-cpu-quants.c.o
[  7%] Building CXX object ggml/src/CMakeFiles/ggml-cpu.dir/ggml-cpu/ggml-cpu-traits.cpp.o
[  8%] Building CXX object ggml/src/CMakeFiles/ggml-cpu.dir/ggml-cpu/amx/amx.cpp.o
[  8%] Building CXX object ggml/src/CMakeFiles/ggml-cpu.dir/ggml-cpu/amx/mmq.cpp.o
[  9%] Building CXX object ggml/src/CMakeFiles/ggml-cpu.dir/ggml-cpu/binary-ops.cpp.o
[  9%] Building CXX object ggml/src/CMakeFiles/ggml-cpu.dir/ggml-cpu/unary-ops.cpp.o
[ 10%] Building CXX object ggml/src/CMakeFiles/ggml-cpu.dir/ggml-cpu/vec.cpp.o
[ 10%] Building CXX object ggml/src/CMakeFiles/ggml-cpu.dir/ggml-cpu/ops.cpp.o
[ 10%] Building CXX object ggml/src/CMakeFiles/ggml-cpu.dir/ggml-cpu/llamafile/sgemm.cpp.o
[ 11%] Linking CXX shared library ../../bin/libggml-cpu.so
[ 11%] Built target ggml-cpu
[ 12%] Building CXX object ggml/src/ggml-blas/CMakeFiles/ggml-blas.dir/ggml-blas.cpp.o
[ 12%] Linking CXX shared library ../../../bin/libggml-blas.so
[ 12%] Built target ggml-blas
[ 12%] Building CXX object ggml/src/CMakeFiles/ggml.dir/ggml-backend-reg.cpp.o
[ 13%] Linking CXX shared library ../../bin/libggml.so
[ 13%] Built target ggml
...

ok to the end. 

Ver. 1.1

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions