|
| 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(supertonic_runner) |
| 9 | + |
| 10 | +include(GNUInstallDirs) |
| 11 | + |
| 12 | +if(NOT APPLE) |
| 13 | + message(FATAL_ERROR "The Supertonic MLX runner is supported only on Darwin.") |
| 14 | +endif() |
| 15 | + |
| 16 | +set(_supertonic_target_processor "${CMAKE_OSX_ARCHITECTURES}") |
| 17 | +if(NOT _supertonic_target_processor) |
| 18 | + set(_supertonic_target_processor "${CMAKE_SYSTEM_PROCESSOR}") |
| 19 | +endif() |
| 20 | +if(NOT _supertonic_target_processor STREQUAL "arm64") |
| 21 | + message( |
| 22 | + FATAL_ERROR |
| 23 | + "The Supertonic MLX runner requires an arm64 Darwin target; detected '${_supertonic_target_processor}'." |
| 24 | + ) |
| 25 | +endif() |
| 26 | + |
| 27 | +set(CMAKE_CXX_STANDARD 17) |
| 28 | +set(CMAKE_CXX_STANDARD_REQUIRED ON) |
| 29 | + |
| 30 | +set(EXECUTORCH_SOURCE_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/../../..) |
| 31 | +include(${EXECUTORCH_SOURCE_ROOT}/tools/cmake/Utils.cmake) |
| 32 | + |
| 33 | +set(_json_include |
| 34 | + ${EXECUTORCH_SOURCE_ROOT}/extension/llm/tokenizers/third-party/json/single_include |
| 35 | +) |
| 36 | +find_library(COREFOUNDATION_FRAMEWORK CoreFoundation REQUIRED) |
| 37 | + |
| 38 | +set(_helper_sources runtime/supertonic_runner.cpp runtime/text_processor.cpp |
| 39 | + runtime/style_loader.cpp runtime/wav_writer.cpp |
| 40 | +) |
| 41 | + |
| 42 | +enable_testing() |
| 43 | +add_executable( |
| 44 | + supertonic_runtime_test runtime/tests/supertonic_runtime_test.cpp |
| 45 | + ${_helper_sources} |
| 46 | +) |
| 47 | +target_compile_definitions( |
| 48 | + supertonic_runtime_test PRIVATE SUPERTONIC_PURE_HELPERS_ONLY |
| 49 | +) |
| 50 | +target_include_directories( |
| 51 | + supertonic_runtime_test PRIVATE runtime ${_json_include} |
| 52 | +) |
| 53 | +target_link_libraries( |
| 54 | + supertonic_runtime_test PRIVATE ${COREFOUNDATION_FRAMEWORK} |
| 55 | +) |
| 56 | +add_test(NAME supertonic_runtime_helpers COMMAND supertonic_runtime_test) |
| 57 | + |
| 58 | +set(gflags_DIR ${CMAKE_CURRENT_BINARY_DIR}/../../../third-party/gflags) |
| 59 | +find_package(gflags REQUIRED) |
| 60 | + |
| 61 | +list(APPEND CMAKE_FIND_ROOT_PATH ${CMAKE_CURRENT_BINARY_DIR}/../../..) |
| 62 | +find_package(executorch CONFIG REQUIRED FIND_ROOT_PATH_BOTH) |
| 63 | +executorch_target_link_options_shared_lib(executorch) |
| 64 | + |
| 65 | +if(NOT TARGET mlxdelegate OR NOT TARGET mlx) |
| 66 | + message( |
| 67 | + FATAL_ERROR |
| 68 | + "ExecuTorch must be installed with the MLX delegate and runtime targets." |
| 69 | + ) |
| 70 | +endif() |
| 71 | + |
| 72 | +foreach(required_target extension_module extension_data_loader extension_tensor |
| 73 | + extension_flat_tensor |
| 74 | +) |
| 75 | + if(NOT TARGET ${required_target}) |
| 76 | + message( |
| 77 | + FATAL_ERROR |
| 78 | + "ExecuTorch installation is missing required target ${required_target}." |
| 79 | + ) |
| 80 | + endif() |
| 81 | +endforeach() |
| 82 | + |
| 83 | +add_executable(supertonic_runner runtime/main.cpp ${_helper_sources}) |
| 84 | +target_compile_definitions(supertonic_runner PRIVATE EXECUTORCH_BUILD_MLX) |
| 85 | +target_include_directories( |
| 86 | + supertonic_runner PRIVATE ${EXECUTORCH_SOURCE_ROOT}/.. runtime |
| 87 | + ${_json_include} |
| 88 | +) |
| 89 | +target_link_libraries( |
| 90 | + supertonic_runner |
| 91 | + PRIVATE executorch |
| 92 | + extension_module |
| 93 | + extension_data_loader |
| 94 | + extension_tensor |
| 95 | + extension_flat_tensor |
| 96 | + mlxdelegate |
| 97 | + mlx |
| 98 | + gflags |
| 99 | + ${COREFOUNDATION_FRAMEWORK} |
| 100 | +) |
| 101 | +executorch_target_link_options_shared_lib(mlxdelegate) |
| 102 | +if(NOT CMAKE_BUILD_TYPE STREQUAL "Debug") |
| 103 | + target_link_options_gc_sections(supertonic_runner) |
| 104 | +endif() |
| 105 | +set(EXECUTORCH_BUILD_MLX ON) |
| 106 | +if(NOT DEFINED MLX_METALLIB_PATH OR NOT EXISTS "${MLX_METALLIB_PATH}") |
| 107 | + message(FATAL_ERROR "The installed MLX package did not provide mlx.metallib.") |
| 108 | +endif() |
| 109 | +executorch_target_copy_mlx_metallib(supertonic_runner) |
| 110 | +install(TARGETS supertonic_runner RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) |
| 111 | +install( |
| 112 | + FILES "${MLX_METALLIB_PATH}" |
| 113 | + DESTINATION ${CMAKE_INSTALL_BINDIR} |
| 114 | + RENAME mlx.metallib |
| 115 | +) |
| 116 | + |
| 117 | +set(SUPERTONIC_INTEGRATION_PTE |
| 118 | + "" |
| 119 | + CACHE FILEPATH "Optional Supertonic PTE for the integration test." |
| 120 | +) |
| 121 | +set(SUPERTONIC_INTEGRATION_ASSET_DIR |
| 122 | + "" |
| 123 | + CACHE PATH "Optional published Supertonic asset directory for integration." |
| 124 | +) |
| 125 | +set(SUPERTONIC_INTEGRATION_STYLE |
| 126 | + "" |
| 127 | + CACHE FILEPATH "Optional published voice-style JSON for integration." |
| 128 | +) |
| 129 | +add_test( |
| 130 | + NAME supertonic_integration |
| 131 | + COMMAND |
| 132 | + ${CMAKE_COMMAND} -DRUNNER=$<TARGET_FILE:supertonic_runner> |
| 133 | + -DPTE=${SUPERTONIC_INTEGRATION_PTE} |
| 134 | + -DASSET_DIR=${SUPERTONIC_INTEGRATION_ASSET_DIR} |
| 135 | + -DSTYLE=${SUPERTONIC_INTEGRATION_STYLE} |
| 136 | + -DOUTPUT=${CMAKE_CURRENT_BINARY_DIR}/supertonic-integration.wav -P |
| 137 | + ${CMAKE_CURRENT_SOURCE_DIR}/runtime/tests/run_integration.cmake |
| 138 | +) |
| 139 | +set_tests_properties( |
| 140 | + supertonic_integration |
| 141 | + PROPERTIES TIMEOUT 1800 SKIP_REGULAR_EXPRESSION |
| 142 | + "SKIP: Supertonic integration assets are unavailable" |
| 143 | +) |
0 commit comments