|
| 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 | +# Build AOTI CUDA backend for runtime. |
| 8 | +# |
| 9 | +# ### Editing this file ### |
| 10 | +# |
| 11 | +# This file should be formatted with |
| 12 | +# ~~~ |
| 13 | +# cmake-format -i CMakeLists.txt |
| 14 | +# ~~~ |
| 15 | +# It should also be cmake-lint clean. |
| 16 | +# |
| 17 | + |
| 18 | +set(CMAKE_EXPORT_COMPILE_COMMANDS ON) |
| 19 | + |
| 20 | +# Source root directory for executorch. |
| 21 | +if(NOT EXECUTORCH_ROOT) |
| 22 | + set(EXECUTORCH_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/../..) |
| 23 | +endif() |
| 24 | + |
| 25 | +find_package(CUDAToolkit REQUIRED) |
| 26 | + |
| 27 | +# Use ExecutorTorch's standard way to find PyTorch libraries for AOTI |
| 28 | +include(${EXECUTORCH_ROOT}/tools/cmake/Utils.cmake) |
| 29 | +find_package_torch() |
| 30 | + |
| 31 | +# CUDA-specific AOTI functionality |
| 32 | +set(_aoti_cuda_sources |
| 33 | + runtime/cuda_backend.cpp |
| 34 | + runtime/shims/memory.cpp |
| 35 | + runtime/shims/tensor_attribute.cpp) |
| 36 | +add_library(aoti_cuda STATIC ${_aoti_cuda_sources}) |
| 37 | +target_include_directories( |
| 38 | + aoti_cuda |
| 39 | + PUBLIC |
| 40 | + ${CUDAToolkit_INCLUDE_DIRS} |
| 41 | + $<BUILD_INTERFACE:${EXECUTORCH_ROOT}> |
| 42 | + $<INSTALL_INTERFACE:include> |
| 43 | + # PyTorch AOTI headers from ExecutorTorch's torch detection |
| 44 | + ${TORCH_INCLUDE_DIRS} |
| 45 | +) |
| 46 | +target_compile_options(aoti_cuda PUBLIC -fexceptions -frtti -fPIC) |
| 47 | +# Ensure symbols are exported properly |
| 48 | +target_link_options(aoti_cuda PUBLIC -Wl,--export-dynamic) |
| 49 | + |
| 50 | +# Link against CUDA::cudart, common AOTI library, and PyTorch CUDA libraries |
| 51 | +target_link_libraries( |
| 52 | + aoti_cuda |
| 53 | + PUBLIC |
| 54 | + aoti_common |
| 55 | + CUDA::cudart |
| 56 | + ${CMAKE_DL_LIBS} |
| 57 | + # Link PyTorch libraries for AOTI CUDA functions |
| 58 | + ${TORCH_LIBRARIES} |
| 59 | +) |
| 60 | +# If you need other CUDA libraries, link them similarly: |
| 61 | +# target_link_libraries(aoti_cuda PUBLIC CUDA::cublas CUDA::cufft ...) |
| 62 | +executorch_target_link_options_shared_lib(aoti_cuda) |
| 63 | + |
| 64 | +# Add runtime |
| 65 | +add_executable(voxtral_runner tests/voxtral_runner.cpp) |
| 66 | +target_link_libraries(voxtral_runner PUBLIC aoti_cuda extension_module_static extension_flat_tensor) |
| 67 | + |
| 68 | +install( |
| 69 | + TARGETS aoti_cuda |
| 70 | + EXPORT ExecuTorchTargets |
| 71 | + DESTINATION lib |
| 72 | +) |
0 commit comments