Skip to content

Commit 4222fe6

Browse files
committed
ET AOTI CUDA runtime libraries
1 parent 74e7ffa commit 4222fe6

File tree

6 files changed

+681
-1
lines changed

6 files changed

+681
-1
lines changed

CMakeLists.txt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -587,6 +587,16 @@ endif()
587587

588588
if(EXECUTORCH_BUILD_CORTEX_M)
589589
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/backends/cortex_m)
590+
list(APPEND _executorch_backends coretex_m_backend)
591+
endif()
592+
593+
if(EXECUTORCH_BUILD_CUDA)
594+
# Build common AOTI functionality (required for CUDA)
595+
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/backends/aoti)
596+
# Build CUDA-specific AOTI functionality
597+
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/backends/cuda)
598+
# Add aoti_cuda to backends - it already depends on aoti_common
599+
list(APPEND _executorch_backends aoti_cuda)
590600
endif()
591601

592602
if(EXECUTORCH_BUILD_EXTENSION_APPLE)
@@ -1021,6 +1031,11 @@ if(EXECUTORCH_BUILD_EXECUTOR_RUNNER)
10211031
extension_runner_util gflags executorch_backends
10221032
)
10231033

1034+
# Add flat tensor extension if it's built
1035+
if(EXECUTORCH_BUILD_EXTENSION_FLAT_TENSOR)
1036+
list(APPEND _executor_runner_libs extension_flat_tensor)
1037+
endif()
1038+
10241039
if(EXECUTORCH_BUILD_KERNELS_OPTIMIZED)
10251040
list(APPEND _executor_runner_libs optimized_native_cpu_ops_lib)
10261041
elseif(EXECUTORCH_BUILD_CADENCE)

backends/aoti/aoti_model_container.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ using executorch::runtime::etensor::Tensor;
2121
extern "C" {
2222

2323
// Type definitions
24+
using AOTITensorHandle = Tensor*;
2425
using AOTIRuntimeError = Error;
2526

2627
// Forward declarations for AOT Inductor model container

backends/cuda/CMakeLists.txt

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
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

Comments
 (0)