ggml
[Ported from github.com/ggml-org/ggml] docs : sync ggml_type enum in gguf.md (#1685)
Brought by drakestapleton
ggml / src / ggml-et / et-kernels / CMakeLists.txt
| 1 | # ggml-et: Device kernels (cross-compiled within the main build) |
| 2 | # |
| 3 | # The RISC-V toolchain is set up in-scope so these targets use the |
| 4 | # cross-compiler while the rest of the build uses the host compiler. |
| 5 | # This keeps kernels in compile_commands.json for full IDE support. |
| 6 | |
| 7 | # --- RISC-V toolchain setup (scoped to this directory) --- |
| 8 | set(TOOLCHAIN_DIR ${ET_PLATFORM_PATH}) |
| 9 | include(${ET_PLATFORM_PATH}/lib/cmake/riscv64-ec-toolchain.cmake) |
| 10 | set(CMAKE_ADDR2LINE "${TOOLCHAIN_DIR}/bin/riscv64-unknown-elf-addr2line") |
| 11 | set(CMAKE_LINKER_TYPE LLD) |
| 12 | |
| 13 | # Ensure kernels are built in this directory even if a global output directory is set |
| 14 | set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) |
| 15 | |
| 16 | message(STATUS "ET kernels using RISC-V toolchain at: ${TOOLCHAIN_DIR}") |
| 17 | |
| 18 | # DeviceUtils provides the add_riscv_executable macro |
| 19 | list(APPEND CMAKE_MODULE_PATH "${ET_PLATFORM_PATH}/lib/cmake/cmake-modules") |
| 20 | list(APPEND CMAKE_PREFIX_PATH "${ET_PLATFORM_PATH}/lib/cmake") |
| 21 | include(DeviceUtils) |
| 22 | |
| 23 | find_package(et-common-libs REQUIRED) |
| 24 | find_package(esperantoTrace REQUIRED) |
| 25 | |
| 26 | # --- Kernel configuration --- |
| 27 | if(NOT DEFINED ADDRESS) |
| 28 | set(ADDRESS "0x8005801000") |
| 29 | message(STATUS "ADDRESS not specified, using default: ${ADDRESS}") |
| 30 | endif() |
| 31 | |
| 32 | set(LINKER_SCRIPT ${CMAKE_CURRENT_SOURCE_DIR}/src/linker.ld) |
| 33 | set(CHECK_SCRIPT ${CMAKE_CURRENT_SOURCE_DIR}/scripts/check_unimplemented_instructions.sh) |
| 34 | |
| 35 | # Track address changes to trigger relinking |
| 36 | set(ADDRESS_FILE ${CMAKE_CURRENT_BINARY_DIR}/et_address.txt) |
| 37 | file(CONFIGURE OUTPUT ${ADDRESS_FILE} CONTENT "${ADDRESS}" @ONLY) |
| 38 | |
| 39 | # KERNELS defined in upper CMakeLists.txt |
| 40 | foreach(KERNEL ${KERNELS}) |
| 41 | add_riscv_executable(${KERNEL}) |
| 42 | target_sources(${KERNEL}.elf PRIVATE |
| 43 | src/${KERNEL}.c |
| 44 | src/crt.S |
| 45 | ) |
| 46 | target_include_directories(${KERNEL}.elf PRIVATE |
| 47 | ${CMAKE_CURRENT_SOURCE_DIR}/src |
| 48 | ${CMAKE_CURRENT_SOURCE_DIR}/.. |
| 49 | ${CMAKE_CURRENT_BINARY_DIR} |
| 50 | ${CMAKE_SOURCE_DIR}/ggml/include |
| 51 | ${CMAKE_SOURCE_DIR}/ggml/src |
| 52 | ) |
| 53 | target_link_libraries(${KERNEL}.elf PRIVATE et-common-libs::cm-umode) |
| 54 | # C-only flags — must not apply to .S files |
| 55 | target_compile_options(${KERNEL}.elf PRIVATE |
| 56 | $<$<COMPILE_LANGUAGE:C>:-fno-zero-initialized-in-bss> |
| 57 | $<$<COMPILE_LANGUAGE:C>:-ffreestanding> |
| 58 | $<$<COMPILE_LANGUAGE:C>:-std=gnu99> |
| 59 | $<$<COMPILE_LANGUAGE:C>:-ffat-lto-objects> |
| 60 | $<$<COMPILE_LANGUAGE:C>:-mcmodel=medany> |
| 61 | $<$<COMPILE_LANGUAGE:C>:-mabi=lp64f> |
| 62 | $<$<COMPILE_LANGUAGE:C>:-march=rv64imf> |
| 63 | $<$<COMPILE_LANGUAGE:C>:-ffunction-sections> |
| 64 | $<$<COMPILE_LANGUAGE:C>:-fdata-sections> |
| 65 | $<$<COMPILE_LANGUAGE:C>:-O3> |
| 66 | $<$<COMPILE_LANGUAGE:C>:-g0> |
| 67 | $<$<COMPILE_LANGUAGE:C>:-nostdlib> |
| 68 | $<$<COMPILE_LANGUAGE:C>:-ffreestanding> |
| 69 | ) |
| 70 | target_link_options(${KERNEL}.elf PRIVATE |
| 71 | -Wl,--defsym=BASE_ADDRESS=${ADDRESS} |
| 72 | -Wl,--entry=_start |
| 73 | ) |
| 74 | # Append to LINK_DEPENDS (macro already sets it for the linker script) |
| 75 | set_property(TARGET ${KERNEL}.elf APPEND PROPERTY |
| 76 | LINK_DEPENDS "${ADDRESS_FILE}" |
| 77 | ) |
| 78 | |
| 79 | # Post-build: strip and check (fails build if check script fails) |
| 80 | add_custom_command(TARGET ${KERNEL}.elf POST_BUILD |
| 81 | COMMAND ${CMAKE_STRIP} --strip-debug $<TARGET_FILE:${KERNEL}.elf> |
| 82 | COMMAND ${CHECK_SCRIPT} |
| 83 | ${CMAKE_OBJDUMP} ${CMAKE_ADDR2LINE} $<TARGET_FILE:${KERNEL}.elf> |
| 84 | DEPENDS ${CHECK_SCRIPT} |
| 85 | VERBATIM |
| 86 | ) |
| 87 | endforeach() |
| 88 | |
| 89 | add_dependencies(uberkernel.elf et-uberkernel-map) |
| 90 | |
| 91 | # Each supported kernel is compiled in its own translation unit with |
| 92 | # -Dentry_point=<kernel>_entry |
| 93 | # so symbols and macros don't leak between kernels. The dispatcher |
| 94 | # (uberkernel.c) calls the renamed entries via extern declarations. |
| 95 | # |
| 96 | # HACK: we need to supresse _me kernels from setting up SCP themselves |
| 97 | set(_UBER_ME_KERNELS mul_mat_f16_matrix_engine mul_mat_f32_matrix_engine flash_attn_ext_f16_me) |
| 98 | |
| 99 | foreach(UK_KERNEL ${UBERKERNEL_SUPPORTED_KERNELS}) |
| 100 | set(_obj uber_${UK_KERNEL}) |
| 101 | add_library(${_obj} OBJECT src/${UK_KERNEL}.c) |
| 102 | target_compile_definitions(${_obj} PRIVATE "entry_point=${UK_KERNEL}_entry" ET_UBERKERNEL) |
| 103 | target_include_directories(${_obj} PRIVATE |
| 104 | ${CMAKE_CURRENT_SOURCE_DIR}/src |
| 105 | ${CMAKE_CURRENT_SOURCE_DIR}/.. |
| 106 | ${CMAKE_CURRENT_BINARY_DIR} |
| 107 | ${CMAKE_SOURCE_DIR}/ggml/include |
| 108 | ${CMAKE_SOURCE_DIR}/ggml/src |
| 109 | ) |
| 110 | target_link_libraries(${_obj} PRIVATE et-common-libs::cm-umode) |
| 111 | target_compile_options(${_obj} PRIVATE |
| 112 | $<$<COMPILE_LANGUAGE:C>:-fno-zero-initialized-in-bss> |
| 113 | $<$<COMPILE_LANGUAGE:C>:-ffreestanding> |
| 114 | $<$<COMPILE_LANGUAGE:C>:-std=gnu99> |
| 115 | $<$<COMPILE_LANGUAGE:C>:-ffat-lto-objects> |
| 116 | $<$<COMPILE_LANGUAGE:C>:-mcmodel=medany> |
| 117 | $<$<COMPILE_LANGUAGE:C>:-mabi=lp64f> |
| 118 | $<$<COMPILE_LANGUAGE:C>:-march=rv64imf> |
| 119 | $<$<COMPILE_LANGUAGE:C>:-ffunction-sections> |
| 120 | $<$<COMPILE_LANGUAGE:C>:-fdata-sections> |
| 121 | $<$<COMPILE_LANGUAGE:C>:-O3> |
| 122 | $<$<COMPILE_LANGUAGE:C>:-g0> |
| 123 | $<$<COMPILE_LANGUAGE:C>:-nostdlib> |
| 124 | ) |
| 125 | # ME kernels: suppress setup_cache_scp() (called once by the dispatcher) |
| 126 | if(UK_KERNEL IN_LIST _UBER_ME_KERNELS) |
| 127 | target_compile_definitions(${_obj} PRIVATE UBERKERNEL_SUPPRESS_SCP_SETUP) |
| 128 | endif() |
| 129 | target_sources(uberkernel.elf PRIVATE $<TARGET_OBJECTS:${_obj}>) |
| 130 | endforeach() |
| 131 | |
| 132 | # Print summary |
| 133 | message(STATUS "GGML ET Kernels configured:") |
| 134 | foreach(KERNEL ${KERNELS}) |
| 135 | message(STATUS " - ${KERNEL}") |
| 136 | endforeach() |
| 137 | message(STATUS "Base address: ${ADDRESS}") |