forked from pytorch/executorch
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
143 lines (125 loc) · 4.03 KB
/
CMakeLists.txt
File metadata and controls
143 lines (125 loc) · 4.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
# Copyright (c) Meta Platforms, Inc. and affiliates.
# All rights reserved.
#
# This source code is licensed under the BSD-style license found in the
# LICENSE file in the root directory of this source tree.
#
# Build llm runner lib.
#
# ### Editing this file ###
#
# This file should be formatted with
# ~~~
# cmake-format -i CMakeLists.txt
# ~~~
# It should also be cmake-lint clean.
#
if(NOT EXECUTORCH_ROOT)
set(EXECUTORCH_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/../../..)
endif()
include(${EXECUTORCH_ROOT}/tools/cmake/Utils.cmake)
include(${EXECUTORCH_ROOT}/tools/cmake/Codegen.cmake)
#
# The `_<target>_srcs` lists are defined by executorch_load_build_variables.
#
executorch_load_build_variables()
# build llm runner library
list(TRANSFORM _extension_llm_runner__srcs PREPEND "${EXECUTORCH_ROOT}/")
add_library(extension_llm_runner STATIC ${_extension_llm_runner__srcs})
# include sampler
add_subdirectory(
${EXECUTORCH_ROOT}/extension/llm/sampler
${CMAKE_CURRENT_BINARY_DIR}/../sampler
)
set(runner_deps executorch_core extension_module extension_tensor
extension_llm_sampler tokenizers::tokenizers
)
# depend on arange_utils
if(NOT TARGET kernels_util_all_deps)
add_subdirectory(
${EXECUTORCH_ROOT}/kernels/portable/cpu/util
${CMAKE_CURRENT_BINARY_DIR}/kernels_util
)
endif()
list(APPEND runner_deps kernels_util_all_deps)
target_link_libraries(extension_llm_runner PUBLIC ${runner_deps})
set_target_properties(
extension_llm_runner PROPERTIES POSITION_INDEPENDENT_CODE ON
)
target_include_directories(
extension_llm_runner INTERFACE ${_common_include_directories}
)
# If the project is configured to build with CUDA support, try to find a CUDA
# runtime (prefer the CUDAToolkit package). If found, expose a compile-time
# macro so sources can conditionally compile CUDA-aware code.
if(EXECUTORCH_BUILD_CUDA)
# Prefer the modern CMake CUDAToolkit module, fall back to searching for the
# CUDA runtime library (cudart) if the package isn't available.
find_package(CUDAToolkit QUIET)
if(CUDAToolkit_FOUND)
target_compile_definitions(extension_llm_runner PUBLIC CUDA_AVAILABLE)
target_link_libraries(extension_llm_runner PUBLIC CUDA::cudart)
message(STATUS "CUDAToolkit found; defining CUDA_AVAILABLE")
else()
message(
STATUS
"CUDA requested (EXECUTORCH_BUILD_CUDA=ON) but no CUDA runtime found"
)
endif()
endif()
install(
TARGETS extension_llm_runner
EXPORT ExecuTorchTargets
DESTINATION ${CMAKE_INSTALL_LIBDIR}
INCLUDES
DESTINATION ${_common_include_directories}
)
install(
DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/executorch/extension/llm/runner
FILES_MATCHING
PATTERN "*.h"
)
if(BUILD_TESTING)
add_subdirectory(test)
endif()
# Python bindings for MultimodalRunner
if(EXECUTORCH_BUILD_PYBIND)
# Create the Python extension module for LLM runners
pybind11_add_module(
_llm_runner SHARED ${CMAKE_CURRENT_SOURCE_DIR}/pybindings.cpp
)
find_package_torch()
find_library(
TORCH_PYTHON_LIBRARY torch_python PATHS "${TORCH_INSTALL_PREFIX}/lib"
)
# Link with the extension_llm_runner library and its dependencies
target_link_libraries(
_llm_runner PRIVATE extension_llm_runner tokenizers::tokenizers
portable_lib ${TORCH_PYTHON_LIBRARY} ${TORCH_LIBRARIES}
)
set_target_properties(
_llm_runner
PROPERTIES POSITION_INDEPENDENT_CODE ON
CXX_VISIBILITY_PRESET "hidden"
INTERPROCEDURAL_OPTIMIZATION TRUE
CXX_STANDARD 20
)
if(APPLE)
set(RPATH
"@loader_path/../../pybindings;@loader_path/../../../../torch/lib"
)
else()
set(RPATH "$ORIGIN/../../pybindings:$ORIGIN/../../../../torch/lib")
endif()
set_target_properties(
_llm_runner PROPERTIES BUILD_RPATH "${RPATH}" INSTALL_RPATH "${RPATH}"
)
# Add include directories
target_include_directories(
_llm_runner PRIVATE ${_common_include_directories} ${TORCH_INCLUDE_DIRS}
)
install(TARGETS _llm_runner
LIBRARY DESTINATION executorch/extension/llm/runner
)
endif()