|
| 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 | +cmake_minimum_required(VERSION 3.29) |
| 18 | + |
| 19 | +set(CMAKE_CXX_STANDARD 17) |
| 20 | +set(CMAKE_CXX_STANDARD_REQUIRED ON) |
| 21 | +set(CMAKE_CUDA_STANDARD 17) |
| 22 | +set(CMAKE_CUDA_STANDARD_REQUIRED ON) |
| 23 | + |
| 24 | +set(CMAKE_EXPORT_COMPILE_COMMANDS ON) |
| 25 | + |
| 26 | +# Source root directory for executorch. |
| 27 | +if(NOT EXECUTORCH_ROOT) |
| 28 | + set(EXECUTORCH_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/../..) |
| 29 | +endif() |
| 30 | + |
| 31 | +find_package(CUDAToolkit REQUIRED) |
| 32 | + |
| 33 | +# Use ExecutorTorch's standard way to find PyTorch libraries for AOTI |
| 34 | +include(${EXECUTORCH_ROOT}/tools/cmake/Utils.cmake) |
| 35 | +find_package_torch() |
| 36 | + |
| 37 | +# CUDA-specific AOTI functionality |
| 38 | +set(_aoti_cuda_sources runtime/cuda_backend.cpp runtime/shims/memory.cpp |
| 39 | + runtime/shims/tensor_attribute.cpp |
| 40 | +) |
| 41 | +add_library(aoti_cuda STATIC ${_aoti_cuda_sources}) |
| 42 | +target_include_directories( |
| 43 | + aoti_cuda |
| 44 | + PUBLIC ${CUDAToolkit_INCLUDE_DIRS} |
| 45 | + $<BUILD_INTERFACE:${EXECUTORCH_ROOT}> |
| 46 | + $<INSTALL_INTERFACE:include> |
| 47 | + # PyTorch AOTI headers from ExecutorTorch's torch detection |
| 48 | + ${TORCH_INCLUDE_DIRS} |
| 49 | +) |
| 50 | +target_compile_options(aoti_cuda PUBLIC -fexceptions -frtti -fPIC) |
| 51 | +# Ensure symbols are exported properly |
| 52 | +target_link_options(aoti_cuda PUBLIC -Wl,--export-dynamic) |
| 53 | + |
| 54 | +# Link against CUDA::cudart, common AOTI library, and PyTorch CUDA libraries |
| 55 | +target_link_libraries( |
| 56 | + aoti_cuda |
| 57 | + PUBLIC aoti_common CUDA::cudart ${CMAKE_DL_LIBS} |
| 58 | + # Link PyTorch libraries for AOTI CUDA functions |
| 59 | + ${TORCH_LIBRARIES} |
| 60 | +) |
| 61 | +# If you need other CUDA libraries, link them similarly: |
| 62 | +# target_link_libraries(aoti_cuda PUBLIC CUDA::cublas CUDA::cufft ...) |
| 63 | +executorch_target_link_options_shared_lib(aoti_cuda) |
| 64 | + |
| 65 | +install( |
| 66 | + TARGETS aoti_cuda |
| 67 | + EXPORT ExecuTorchTargets |
| 68 | + DESTINATION lib |
| 69 | +) |
0 commit comments