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
161 lines (138 loc) · 4.4 KB
/
CMakeLists.txt
File metadata and controls
161 lines (138 loc) · 4.4 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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
# 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.
#
# Simple CMake build system for selective build demo.
#
# ### Editing this file ###
#
# This file should be formatted with
# ~~~
# cmake-format -i CMakeLists.txt
# ~~~
# It should also be cmake-lint clean.
#
cmake_minimum_required(VERSION 3.19)
project(selective_build_example)
set(EXECUTORCH_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/../..)
set(TORCH_ROOT ${EXECUTORCH_ROOT}/third-party/pytorch)
include(${EXECUTORCH_ROOT}/tools/cmake/Utils.cmake)
include(${EXECUTORCH_ROOT}/tools/cmake/Codegen.cmake)
if(NOT PYTHON_EXECUTABLE)
resolve_python_executable()
endif()
if(NOT CMAKE_CXX_STANDARD)
set(CMAKE_CXX_STANDARD 17)
# Can't set to 11 due to executor_runner.cpp make_unique
endif()
set(_common_compile_options -Wno-deprecated-declarations -fPIC
-ffunction-sections -fdata-sections
)
# Let files say "include <executorch/path/to/header.h>".
set(_common_include_directories ${EXECUTORCH_ROOT}/..)
find_package(executorch CONFIG REQUIRED)
find_package(
gflags REQUIRED PATHS ${CMAKE_CURRENT_BINARY_DIR}/../../third-party
)
target_include_directories(
executorch_core INTERFACE ${_common_include_directories}
)
# ------------------------------ OPTIONS BEGIN -------------------------------
# Option to register ops from yaml file
option(EXECUTORCH_SELECT_OPS_YAML "Register all the ops from a given yaml file"
OFF
)
# Option to register op list
option(EXECUTORCH_SELECT_OPS_LIST "Register a list of ops, separated by comma"
OFF
)
# Selective build options.
option(EXECUTORCH_SELECT_ALL_OPS
"Whether to register all ops defined in portable kernel library." OFF
)
# Option to enable parsing ops and dtypes directly from model pte file
option(EXECUTORCH_SELECT_OPS_FROM_MODEL
"Enable op selection from pte during build." OFF
)
# Option to enable dtype selective build. Note: must be using selective build
# model API.
option(EXECUTORCH_DTYPE_SELECTIVE_BUILD "Enable dtype selective build." OFF)
# ------------------------------- OPTIONS END --------------------------------
#
# The `_<target>_srcs` lists are defined by executorch_load_build_variables.
#
executorch_load_build_variables()
#
# select_build_lib: C++ library to register selected ops in custom kernel
# library
#
set(_kernel_lib)
if(EXECUTORCH_SELECT_OPS_YAML)
set(_custom_ops_yaml
${EXECUTORCH_ROOT}/examples/portable/custom_ops/custom_ops.yaml
)
set(kernel_sources
${EXECUTORCH_ROOT}/examples/portable/custom_ops/custom_ops_1_out.cpp
${EXECUTORCH_ROOT}/examples/portable/custom_ops/custom_ops_2_out.cpp
)
#
# custom_kernels: C++ kernel implementations of custom ops
#
add_library(custom_kernels ${kernel_sources})
target_link_libraries(custom_kernels PRIVATE executorch_core)
target_compile_options(custom_kernels PUBLIC ${_common_compile_options})
list(APPEND _kernel_lib custom_kernels)
else()
list(APPEND _kernel_lib portable_kernels)
endif()
gen_selected_ops(
LIB_NAME
"select_build_lib"
OPS_SCHEMA_YAML
"${_custom_ops_yaml}"
ROOT_OPS
"${EXECUTORCH_SELECT_OPS_LIST}"
INCLUDE_ALL_OPS
"${EXECUTORCH_SELECT_ALL_OPS}"
OPS_FROM_MODEL
"${EXECUTORCH_SELECT_OPS_FROM_MODEL}"
DTYPE_SELECTIVE_BUILD
"${EXECUTORCH_DTYPE_SELECTIVE_BUILD}"
)
generate_bindings_for_kernels(
LIB_NAME
"select_build_lib"
FUNCTIONS_YAML
${EXECUTORCH_ROOT}/kernels/portable/functions.yaml
CUSTOM_OPS_YAML
"${_custom_ops_yaml}"
DTYPE_SELECTIVE_BUILD
"${EXECUTORCH_DTYPE_SELECTIVE_BUILD}"
)
gen_operators_lib(
LIB_NAME
"select_build_lib"
KERNEL_LIBS
${_kernel_lib}
DEPS
executorch_core
DTYPE_SELECTIVE_BUILD
"${EXECUTORCH_DTYPE_SELECTIVE_BUILD}"
)
list(TRANSFORM _executor_runner__srcs PREPEND "${EXECUTORCH_ROOT}/")
#
# selective_build_test: test binary to allow different operator libraries to
# link to
#
add_executable(selective_build_test ${_executor_runner__srcs})
if(NOT CMAKE_BUILD_TYPE STREQUAL "Debug")
target_link_options_gc_sections(selective_build_test)
endif()
target_link_libraries(
selective_build_test PRIVATE executorch_core extension_evalue_util
extension_runner_util gflags select_build_lib
)
executorch_target_link_options_shared_lib(select_build_lib)
target_compile_options(selective_build_test PUBLIC ${_common_compile_options})