|
| 1 | +# Copyright (c) Meta Platforms, Inc. and affiliates. |
| 2 | +# All rights reserved. |
| 3 | +# |
| 4 | +# This source code is licensed under the BSD-style license found in the |
| 5 | +# LICENSE file in the root directory of this source tree. |
| 6 | + |
| 7 | +cmake_minimum_required(VERSION 3.24) |
| 8 | +project(muse_glimmer) |
| 9 | + |
| 10 | +set(CMAKE_CXX_STANDARD 17) |
| 11 | +set(CMAKE_CXX_STANDARD_REQUIRED ON) |
| 12 | + |
| 13 | +if(DEFINED ENV{CONDA_PREFIX} AND EXISTS "$ENV{CONDA_PREFIX}/lib") |
| 14 | + list(PREPEND CMAKE_BUILD_RPATH "$ENV{CONDA_PREFIX}/lib") |
| 15 | +endif() |
| 16 | + |
| 17 | +set(EXECUTORCH_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/../../..) |
| 18 | + |
| 19 | +include(${EXECUTORCH_ROOT}/tools/cmake/Utils.cmake) |
| 20 | + |
| 21 | +set(_common_include_directories ${EXECUTORCH_ROOT}/..) |
| 22 | +set(_json_include |
| 23 | + ${EXECUTORCH_ROOT}/extension/llm/tokenizers/third-party/json/single_include |
| 24 | +) |
| 25 | + |
| 26 | +# gflags |
| 27 | +set(gflags_DIR ${EXECUTORCH_ROOT}/cmake-out/third-party/gflags) |
| 28 | +find_package(gflags REQUIRED) |
| 29 | + |
| 30 | +# executorch |
| 31 | +list(APPEND CMAKE_FIND_ROOT_PATH ${CMAKE_CURRENT_BINARY_DIR}/../../../..) |
| 32 | +find_package(executorch CONFIG REQUIRED FIND_ROOT_PATH_BOTH) |
| 33 | +executorch_target_link_options_shared_lib(executorch) |
| 34 | + |
| 35 | +set(link_libraries executorch gflags) |
| 36 | + |
| 37 | +# CPU ops (for host-side helpers not delegated to CUDA) |
| 38 | +list(APPEND link_libraries optimized_native_cpu_ops_lib cpublas eigen_blas) |
| 39 | +executorch_target_link_options_shared_lib(optimized_native_cpu_ops_lib) |
| 40 | + |
| 41 | +# Extensions |
| 42 | +list( |
| 43 | + APPEND |
| 44 | + link_libraries |
| 45 | + extension_llm_runner |
| 46 | + extension_module |
| 47 | + extension_data_loader |
| 48 | + extension_tensor |
| 49 | + extension_flat_tensor |
| 50 | +) |
| 51 | + |
| 52 | +# Backend: CUDA or MLX (exactly one required) |
| 53 | +if(EXECUTORCH_BUILD_CUDA) |
| 54 | + find_package(CUDAToolkit REQUIRED) |
| 55 | + list(APPEND link_libraries aoti_cuda_backend) |
| 56 | + executorch_target_link_options_shared_lib(aoti_cuda_backend) |
| 57 | + add_compile_definitions(EXECUTORCH_BUILD_CUDA) |
| 58 | +elseif(TARGET mlxdelegate) |
| 59 | + list(APPEND link_libraries mlxdelegate mlx) |
| 60 | + executorch_target_link_options_shared_lib(mlxdelegate) |
| 61 | + add_compile_definitions(EXECUTORCH_BUILD_MLX) |
| 62 | +else() |
| 63 | + message(FATAL_ERROR "Set EXECUTORCH_BUILD_CUDA=ON or EXECUTORCH_BUILD_MLX=ON") |
| 64 | +endif() |
| 65 | + |
| 66 | +# Use a supplied or local stb checkout before fetching it. The resize header is |
| 67 | +# under deprecated/ in the pinned revision. |
| 68 | +if(EXECUTORCH_BUILD_CUDA OR TARGET mlxdelegate) |
| 69 | + if(NOT MUSE_GLIMMER_STB_INCLUDE_DIR |
| 70 | + AND EXISTS "${EXECUTORCH_ROOT}/third-party/stb/stb_image.h" |
| 71 | + ) |
| 72 | + set(MUSE_GLIMMER_STB_INCLUDE_DIR "${EXECUTORCH_ROOT}/third-party/stb") |
| 73 | + endif() |
| 74 | + if(MUSE_GLIMMER_STB_INCLUDE_DIR |
| 75 | + AND EXISTS "${MUSE_GLIMMER_STB_INCLUDE_DIR}/stb_image.h" |
| 76 | + ) |
| 77 | + message( |
| 78 | + STATUS "Using local stb headers from: ${MUSE_GLIMMER_STB_INCLUDE_DIR}" |
| 79 | + ) |
| 80 | + list(APPEND _common_include_directories ${MUSE_GLIMMER_STB_INCLUDE_DIR} |
| 81 | + ${MUSE_GLIMMER_STB_INCLUDE_DIR}/deprecated |
| 82 | + ) |
| 83 | + else() |
| 84 | + include(FetchContent) |
| 85 | + FetchContent_Declare( |
| 86 | + stb |
| 87 | + GIT_REPOSITORY https://github.com/nothings/stb.git |
| 88 | + GIT_TAG f0569113c93ad095470c54bf34a17b36646bbbb5 |
| 89 | + ) |
| 90 | + FetchContent_MakeAvailable(stb) |
| 91 | + list(APPEND _common_include_directories ${stb_SOURCE_DIR} |
| 92 | + ${stb_SOURCE_DIR}/deprecated |
| 93 | + ) |
| 94 | + endif() |
| 95 | +endif() |
| 96 | + |
| 97 | +# Tokenizer (tiktoken via pytorch/tokenizers) |
| 98 | +list(APPEND link_libraries tokenizers::tokenizers) |
| 99 | + |
| 100 | +add_executable( |
| 101 | + solo_runner runtime/runners/solo.cpp runtime/engine/muse_glimmer_engine.cpp |
| 102 | + runtime/engine/dflash_session.cpp |
| 103 | +) |
| 104 | +if(EXECUTORCH_BUILD_CUDA OR TARGET mlxdelegate) |
| 105 | + target_sources( |
| 106 | + solo_runner PRIVATE runtime/engine/muse_glimmer_vision_runtime.cpp |
| 107 | + ) |
| 108 | +endif() |
| 109 | +target_include_directories( |
| 110 | + solo_runner PUBLIC ${_common_include_directories} ${_json_include} |
| 111 | +) |
| 112 | +target_link_libraries(solo_runner PUBLIC ${link_libraries}) |
| 113 | + |
| 114 | +# Export symbols required by the dynamically loaded AOTI CUDA blob. |
| 115 | +if(EXECUTORCH_BUILD_CUDA |
| 116 | + AND NOT APPLE |
| 117 | + AND NOT MSVC |
| 118 | +) |
| 119 | + target_link_options(solo_runner PRIVATE "LINKER:--export-dynamic") |
| 120 | +endif() |
| 121 | + |
| 122 | +add_executable( |
| 123 | + dflash_runner |
| 124 | + runtime/runners/dflash.cpp runtime/engine/muse_glimmer_engine.cpp |
| 125 | + runtime/engine/dflash_session.cpp |
| 126 | +) |
| 127 | +if(EXECUTORCH_BUILD_CUDA OR TARGET mlxdelegate) |
| 128 | + target_sources( |
| 129 | + dflash_runner PRIVATE runtime/engine/muse_glimmer_vision_runtime.cpp |
| 130 | + ) |
| 131 | +endif() |
| 132 | +target_include_directories( |
| 133 | + dflash_runner PUBLIC ${_common_include_directories} ${_json_include} |
| 134 | +) |
| 135 | +target_link_libraries(dflash_runner PUBLIC ${link_libraries}) |
| 136 | + |
| 137 | +add_executable(sampling_test tests/sampling_test.cpp) |
| 138 | +target_include_directories(sampling_test PUBLIC ${_common_include_directories}) |
| 139 | +target_link_libraries(sampling_test PUBLIC extension_tensor executorch) |
| 140 | + |
| 141 | +add_executable(dflash_timing_test tests/dflash_timing_test.cpp) |
| 142 | +target_include_directories( |
| 143 | + dflash_timing_test PUBLIC ${_common_include_directories} |
| 144 | +) |
| 145 | + |
| 146 | +# Worker used by the OpenAI-compatible serving harness. |
| 147 | +add_executable( |
| 148 | + muse_glimmer_worker |
| 149 | + runtime/runners/muse_glimmer_worker.cpp |
| 150 | + runtime/engine/muse_glimmer_engine.cpp runtime/engine/dflash_session.cpp |
| 151 | +) |
| 152 | +if(EXECUTORCH_BUILD_CUDA OR TARGET mlxdelegate) |
| 153 | + target_sources( |
| 154 | + muse_glimmer_worker PRIVATE runtime/engine/muse_glimmer_vision_runtime.cpp |
| 155 | + ) |
| 156 | +endif() |
| 157 | +target_include_directories( |
| 158 | + muse_glimmer_worker PUBLIC ${_common_include_directories} ${_json_include} |
| 159 | +) |
| 160 | +target_link_libraries(muse_glimmer_worker PUBLIC ${link_libraries}) |
| 161 | + |
| 162 | +if(EXECUTORCH_BUILD_CUDA |
| 163 | + AND NOT APPLE |
| 164 | + AND NOT MSVC |
| 165 | +) |
| 166 | + target_link_options(dflash_runner PRIVATE "LINKER:--export-dynamic") |
| 167 | + target_link_options(muse_glimmer_worker PRIVATE "LINKER:--export-dynamic") |
| 168 | +endif() |
| 169 | + |
| 170 | +if(NOT CMAKE_BUILD_TYPE STREQUAL "Debug") |
| 171 | + target_link_options_gc_sections(solo_runner) |
| 172 | + target_link_options_gc_sections(dflash_runner) |
| 173 | + target_link_options_gc_sections(muse_glimmer_worker) |
| 174 | + if(NOT APPLE AND NOT MSVC) |
| 175 | + # CUDA AOTI blobs resolve symbols from the host executable. |
| 176 | + if(NOT EXECUTORCH_BUILD_CUDA) |
| 177 | + target_link_options(solo_runner PRIVATE "LINKER:-s") |
| 178 | + target_link_options(dflash_runner PRIVATE "LINKER:-s") |
| 179 | + target_link_options(muse_glimmer_worker PRIVATE "LINKER:-s") |
| 180 | + endif() |
| 181 | + endif() |
| 182 | +endif() |
| 183 | + |
| 184 | +if(TARGET mlxdelegate) |
| 185 | + executorch_target_copy_mlx_metallib(solo_runner) |
| 186 | + executorch_target_copy_mlx_metallib(dflash_runner) |
| 187 | + executorch_target_copy_mlx_metallib(muse_glimmer_worker) |
| 188 | +endif() |
0 commit comments