Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/ggml/blob/master/src/ggml-et/et-kernels/CMakeLists.txt # ggml [Ported from github.com/ggml-org/ggml] docs : sync ggml_type enum in gguf.md (#1685) Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `master` Branches Tags History `ggml / src / ggml-et / et-kernels / CMakeLists.txt` 137 lines · 5559 bytes Raw Blame History 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 $<$:-fno-zero-initialized-in-bss> 57 $<$:-ffreestanding> 58 $<$:-std=gnu99> 59 $<$:-ffat-lto-objects> 60 $<$:-mcmodel=medany> 61 $<$:-mabi=lp64f> 62 $<$:-march=rv64imf> 63 $<$:-ffunction-sections> 64 $<$:-fdata-sections> 65 $<$:-O3> 66 $<$:-g0> 67 $<$:-nostdlib> 68 $<$:-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 $ 82 COMMAND ${CHECK_SCRIPT} 83 ${CMAKE_OBJDUMP} ${CMAKE_ADDR2LINE} $ 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=_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 $<$:-fno-zero-initialized-in-bss> 113 $<$:-ffreestanding> 114 $<$:-std=gnu99> 115 $<$:-ffat-lto-objects> 116 $<$:-mcmodel=medany> 117 $<$:-mabi=lp64f> 118 $<$:-march=rv64imf> 119 $<$:-ffunction-sections> 120 $<$:-fdata-sections> 121 $<$:-O3> 122 $<$:-g0> 123 $<$:-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 $) 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}")