forked from openvinotoolkit/openvino
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
255 lines (217 loc) · 9.86 KB
/
CMakeLists.txt
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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
# Copyright (C) 2018-2024 Intel Corporation
# SPDX-License-Identifier: Apache-2.0
#
if(NOT ENABLE_INTEL_CPU)
return()
endif()
set(TARGET_NAME "openvino_intel_cpu_plugin")
if((CMAKE_COMPILER_IS_GNUCXX OR OV_COMPILER_IS_CLANG) AND CMAKE_CXX_STANDARD GREATER_EQUAL 20)
set(CMAKE_CXX_FLAGS "-Wno-error=deprecated ${CMAKE_CXX_FLAGS}")
endif()
if(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
# C4267, 4244 issues from oneDNN headers conversion from 'XXX' to 'YYY', possible loss of data
ov_add_compiler_flags(/wd4018)
ov_add_compiler_flags(/wd4267)
ov_add_compiler_flags(/wd4244)
# mkldnn headers: '<<': result of 32-bit shift implicitly converted to 64 bits
ov_add_compiler_flags(/wd4334)
# oneDNN arm64: unary minus operator applied to unsigned type, result still unsigned
ov_add_compiler_flags(/wd4146)
elseif(OV_COMPILER_IS_CLANG)
# -Wno-delete-non-abstract-non-virtual-dtor is support > clang 9.0
if(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 9.0)
ov_add_compiler_flags(-Wno-delete-non-abstract-non-virtual-dtor)
else()
ov_add_compiler_flags(-Wno-delete-non-virtual-dtor)
endif()
endif()
if (AARCH64 AND NOT APPLE AND CMAKE_COMPILER_IS_GNUCXX AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 10.2)
# according to https://github.com/ARM-software/ComputeLibrary/issues/1053#issuecomment-1846903707 comment
# the 'multi_isa=1' below enables FP32, FP16 and SVE / SVE2 kernels
# But: arm_sve.h header is not available on gcc older 10.2 (let's test it), so we have to check it
set(OV_CPU_AARCH64_USE_MULTI_ISA_DEFAULT ON)
else()
set(OV_CPU_AARCH64_USE_MULTI_ISA_DEFAULT OFF)
endif()
set(OV_CPU_AARCH64_USE_MULTI_ISA ${OV_CPU_AARCH64_USE_MULTI_ISA_DEFAULT} CACHE BOOL "Build multi-ISA ACL")
set(OV_CPU_ARM_TARGET_GENERIC_ARCHS armv8a
armv8.2-a
armv8.6-a armv8.6-a-sve armv8.6-a-sve2 armv8.6-a-sve2-sme2
armv8r64 # the same as armv8.4-a
)
if(ARM)
set(OV_CPU_ARM_TARGET_ARCH_DEFAULT armv7a)
set(OV_CPU_ARM_TARGET_ARCHS armv7a armv7a-hf
# requires estate=32
${OV_CPU_ARM_TARGET_GENERIC_ARCHS})
elseif(AARCH64)
if(APPLE)
set(OV_CPU_ARM_TARGET_ARCH_DEFAULT arm64-v8.2-a)
else()
if(OV_CPU_AARCH64_USE_MULTI_ISA)
# set v8a even we want fp16 kernels, because
# we use multi_isa=1 in ACLConfig.cmake to enable both fp16 and fp32 kernels
# actual kernel is selected in runtime based on runtime capabilities
set(OV_CPU_ARM_TARGET_ARCH_DEFAULT arm64-v8a)
else()
set(OV_CPU_ARM_TARGET_ARCH_DEFAULT arm64-v8.2-a)
endif()
endif()
set(OV_CPU_ARM_TARGET_ARCHS arm64-v8a
arm64-v8.2-a arm64-v8.2-a-sve arm64-v8.2-a-sve2
# used with estate=64
${OV_CPU_ARM_TARGET_GENERIC_ARCHS})
endif()
set(OV_CPU_ARM_TARGET_ARCH ${OV_CPU_ARM_TARGET_ARCH_DEFAULT} CACHE STRING "Architecture for ARM ComputeLibrary")
set_property(CACHE OV_CPU_ARM_TARGET_ARCH PROPERTY STRINGS ${OV_CPU_ARM_TARGET_ARCHS})
if(X86 OR X86_64 OR AARCH64)
# disable mlas with webassembly
if(EMSCRIPTEN OR (WIN32 AND AARCH64) OR MINGW OR (CMAKE_COMPILER_IS_GNUCXX AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 7))
set(ENABLE_MLAS_FOR_CPU_DEFAULT OFF)
else()
set(ENABLE_MLAS_FOR_CPU_DEFAULT ON)
endif()
else()
set(ENABLE_MLAS_FOR_CPU_DEFAULT OFF)
endif()
ov_option(ENABLE_MLAS_FOR_CPU "Enable MLAS for OpenVINO CPU Plugin" ${ENABLE_MLAS_FOR_CPU_DEFAULT})
add_subdirectory(thirdparty)
if(WIN32)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DNOMINMAX")
endif()
if(ENABLE_CPU_DEBUG_CAPS)
add_definitions(-DCPU_DEBUG_CAPS)
endif()
set(OV_CPU_WITH_DNNL ON)
if(OV_CPU_WITH_DNNL)
add_definitions(-DOV_CPU_WITH_DNNL)
endif()
if(DNNL_USE_ACL)
add_definitions(-DOV_CPU_WITH_ACL)
set(OV_CPU_WITH_ACL ON)
endif()
if(OV_CPU_WITH_ACL)
set(CMAKE_CXX_STANDARD 14)
endif()
file(GLOB_RECURSE SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/src/*.cpp)
file(GLOB_RECURSE HEADERS ${CMAKE_CURRENT_SOURCE_DIR}/src/*.h
${CMAKE_CURRENT_SOURCE_DIR}/src/*.hpp)
if(NOT OV_CPU_WITH_ACL)
list(APPEND EXCLUDE_PATHS ${CMAKE_CURRENT_SOURCE_DIR}/src/nodes/executors/acl/*)
endif()
if(NOT X86_64)
list(APPEND EXCLUDE_PATHS ${CMAKE_CURRENT_SOURCE_DIR}/src/nodes/executors/x64/*
${CMAKE_CURRENT_SOURCE_DIR}/src/nodes/kernels/x64/*
${CMAKE_CURRENT_SOURCE_DIR}/src/emitters/x64/*
${CMAKE_CURRENT_SOURCE_DIR}/src/transformations/cpu_opset/x64/*
${CMAKE_CURRENT_SOURCE_DIR}/src/transformations/snippets/x64/*)
endif()
if(NOT (AARCH64 OR ARM))
list(APPEND EXCLUDE_PATHS ${CMAKE_CURRENT_SOURCE_DIR}/src/transformations/cpu_opset/arm/*
${CMAKE_CURRENT_SOURCE_DIR}/src/emitters/plugin/aarch64/*
${CMAKE_CURRENT_SOURCE_DIR}/src/nodes/executors/aarch64/*
${CMAKE_CURRENT_SOURCE_DIR}/src/nodes/kernels/aarch64/*)
endif()
if (NOT ENABLE_MLAS_FOR_CPU)
list(APPEND EXCLUDE_PATHS ${CMAKE_CURRENT_SOURCE_DIR}/src/nodes/executors/mlas/*)
list(APPEND EXCLUDE_PATHS ${CMAKE_CURRENT_SOURCE_DIR}/src/mlas/*)
endif()
file(GLOB_RECURSE FILES_TO_REMOVE ${EXCLUDE_PATHS})
list(REMOVE_ITEM SOURCES ${FILES_TO_REMOVE})
list(REMOVE_ITEM HEADERS ${FILES_TO_REMOVE})
# create plugin
ov_add_plugin(NAME ${TARGET_NAME}
DEVICE_NAME "CPU"
AS_EXTENSION
VERSION_DEFINES_FOR src/plugin.cpp
SOURCES ${SOURCES} ${HEADERS})
# give a different file name depending on target platform architecture
if(ARM OR AARCH64)
set_target_properties(${TARGET_NAME} PROPERTIES OUTPUT_NAME "openvino_arm_cpu_plugin")
elseif(RISCV64)
set_target_properties(${TARGET_NAME} PROPERTIES OUTPUT_NAME "openvino_riscv_cpu_plugin")
endif()
ov_mark_target_as_cc(${TARGET_NAME})
target_link_libraries(${TARGET_NAME} PRIVATE dnnl
openvino::shape_inference
openvino::snippets)
target_include_directories(${TARGET_NAME} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/src)
if (ENABLE_MLAS_FOR_CPU)
target_link_libraries(${TARGET_NAME} PRIVATE mlas)
target_include_directories(${TARGET_NAME} SYSTEM PRIVATE $<TARGET_PROPERTY:mlas,INCLUDE_DIRECTORIES>)
add_definitions(-DOV_CPU_WITH_MLAS)
endif()
target_include_directories(${TARGET_NAME} SYSTEM PRIVATE $<TARGET_PROPERTY:dnnl,INCLUDE_DIRECTORIES>)
# Cross compiled function
# TODO: The same for proposal, proposalONNX, topk
cross_compiled_file(${TARGET_NAME}
ARCH AVX2 ANY
src/nodes/proposal_imp.cpp
API src/nodes/proposal_imp.hpp
NAME proposal_exec
NAMESPACE ov::Extensions::Cpu::XARCH
)
cross_compiled_file(${TARGET_NAME}
ARCH AVX512F AVX2 ANY
src/nodes/kernels/scaled_attn/softmax.cpp
API src/nodes/kernels/scaled_attn/softmax.hpp
NAME attn_softmax
NAMESPACE ov::Extensions::Cpu::XARCH
)
cross_compiled_file(${TARGET_NAME}
ARCH AVX512F AVX2 ANY
src/nodes/kernels/scaled_attn/mha_single_token.cpp
API src/nodes/kernels/scaled_attn/mha_single_token.hpp
NAME mha_single_token
NAMESPACE ov::Extensions::Cpu::XARCH
)
cross_compiled_file(${TARGET_NAME}
ARCH AVX512F AVX2 ANY
src/nodes/kernels/scaled_attn/attn_memcpy.cpp
API src/nodes/kernels/scaled_attn/attn_memcpy.hpp
NAME attn_memcpy paged_attn_memcpy attn_memcpy2d_kernel
NAMESPACE ov::Extensions::Cpu::XARCH
)
cross_compiled_file(${TARGET_NAME}
ARCH AVX512F AVX2 ANY
src/nodes/kernels/scaled_attn/attn_quant.cpp
API src/nodes/kernels/scaled_attn/attn_quant.hpp
NAME attn_quantkv attn_quant_u8 attn_dequant_u8
NAMESPACE ov::Extensions::Cpu::XARCH
)
# system dependencies must go last
target_link_libraries(${TARGET_NAME} PRIVATE openvino::pugixml)
ov_set_threading_interface_for(${TARGET_NAME})
# must be called after all target_link_libraries
ov_add_api_validator_post_build_step(TARGET ${TARGET_NAME})
# LTO
set_target_properties(${TARGET_NAME} PROPERTIES INTERPROCEDURAL_OPTIMIZATION_RELEASE ${ENABLE_LTO})
#
# add test object library
#
if(BUILD_SHARED_LIBS)
add_library(${TARGET_NAME}_obj OBJECT ${SOURCES} ${HEADERS})
ov_link_system_libraries(${TARGET_NAME}_obj PUBLIC dnnl openvino::pugixml)
ov_add_version_defines(src/plugin.cpp ${TARGET_NAME}_obj)
target_include_directories(${TARGET_NAME}_obj
PRIVATE
$<TARGET_PROPERTY:openvino::runtime::dev,INTERFACE_INCLUDE_DIRECTORIES>
$<TARGET_PROPERTY:openvino::itt,INTERFACE_INCLUDE_DIRECTORIES>
$<TARGET_PROPERTY:openvino::shape_inference,INTERFACE_INCLUDE_DIRECTORIES>
$<TARGET_PROPERTY:openvino::snippets,INTERFACE_INCLUDE_DIRECTORIES>
PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}/src
$<TARGET_PROPERTY:openvino::conditional_compilation,INTERFACE_INCLUDE_DIRECTORIES>)
target_include_directories(${TARGET_NAME}_obj SYSTEM PUBLIC $<TARGET_PROPERTY:dnnl,INCLUDE_DIRECTORIES>)
if(ENABLE_MLAS_FOR_CPU)
target_include_directories(${TARGET_NAME}_obj SYSTEM PUBLIC $<TARGET_PROPERTY:mlas,INCLUDE_DIRECTORIES>)
endif()
ov_set_threading_interface_for(${TARGET_NAME}_obj)
target_compile_definitions(${TARGET_NAME}_obj PRIVATE USE_STATIC_IE)
set_target_properties(${TARGET_NAME}_obj PROPERTIES EXCLUDE_FROM_ALL ON)
# LTO
set_target_properties(${TARGET_NAME}_obj PROPERTIES INTERPROCEDURAL_OPTIMIZATION_RELEASE ${ENABLE_LTO})
endif()
if(ENABLE_TESTS)
add_subdirectory(tests)
endif()