blob: 4ac0c722a6d18d95584b27af32d9262bb8839c3a [file] [log] [blame]
David Svantessone0c42ef2022-12-15 16:25:57 +00001# Copyright (c) 2023 Arm Limited.
2#
3# SPDX-License-Identifier: MIT
4#
5# Permission is hereby granted, free of charge, to any person obtaining a copy
6# of this software and associated documentation files (the "Software"), to
7# deal in the Software without restriction, including without limitation the
8# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
9# sell copies of the Software, and to permit persons to whom the Software is
10# furnished to do so, subject to the following conditions:
11#
12# The above copyright notice and this permission notice shall be included in all
13# copies or substantial portions of the Software.
14#
15# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21# SOFTWARE.
22
23cmake_minimum_required(VERSION 3.13 FATAL_ERROR)
24
25# ---------------------------------------------------------------------
26# Project ArmCompute
27
28list(APPEND CMAKE_MESSAGE_CONTEXT ArmCompute)
29project(
30 ArmCompute
31 VERSION 28.0.8
32 DESCRIPTION
33 "The Arm Compute Library is a collection of low-level machine learning functions optimized for Arm® Cortex®-A CPU and Arm® Mali™ GPU architectures"
34 LANGUAGES C CXX ASM)
35
36include(GNUInstallDirs)
37
38set(CMAKE_C_STANDARD 99)
39set(CMAKE_C_STANDARD_REQUIRED ON)
40set(CMAKE_C_EXTENSIONS OFF)
41
42set(CMAKE_CXX_STANDARD 14)
43set(CMAKE_CXX_STANDARD_REQUIRED ON)
44set(CMAKE_CXX_EXTENSIONS OFF)
45
46list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
47include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/Options.cmake)
48include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/Version.cmake)
49
50# Require at least gcc/g++ 11) CMAKE_CXX_COMPILER_VERSION OR
51if(CMAKE_C_COMPILER_VERSION VERSION_LESS 10.2 OR CMAKE_CXX_COMPILER_VERSION
52 VERSION_LESS 10.2)
53 message(
54 FATAL_ERROR "gcc and g++ version => 10.2 is required for building project!")
55endif()
56
57# ---------------------------------------------------------------------
58# Configuration
59
60# Default to Release Build
61if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
62 set(CMAKE_BUILD_TYPE
63 "Release"
64 CACHE
65 STRING
66 "Choose build type, available options are: Debug, Release, RelWithDebInfo"
67 FORCE)
68endif()
69
70# ---------------------------------------------------------------------
71# Information
72
73message(STATUS "Arm Compute Library ${PROJECT_VERSION}")
74
75message(VERBOSE "-----------------------------------------------------")
76message(VERBOSE "Build information:")
77list(APPEND CMAKE_MESSAGE_INDENT " ")
78message(VERBOSE "Host system: ${CMAKE_SYSTEM_NAME}")
79message(VERBOSE "Host processor: ${CMAKE_SYSTEM_PROCESSOR}")
80message(VERBOSE "Build path: ${CMAKE_CURRENT_BINARY_DIR}")
81message(VERBOSE "Enable OpenCL acceleration: ${ENABLE_OPENCL}")
82message(VERBOSE "Enable CPU acceleration: ${ENABLE_NEON}")
83list(POP_BACK CMAKE_MESSAGE_INDENT)
84message(VERBOSE "-----------------------------------------------------")
85
86# ---------------------------------------------------------------------
87# Compile options and features
88
89set(COMMON_CXX_FLAGS
90 -Wall
91 -DARCH_ARM
92 -Wextra
93 -Wdisabled-optimization
94 -Wformat=2
95 -Winit-self
96 -Wstrict-overflow=2
97 -Wswitch-default
98 -Woverloaded-virtual
99 -Wformat-security
100 -Wctor-dtor-privacy
101 -Wsign-promo
102 -Weffc++
103 -Wno-overlength-strings
104 -Wno-ignored-attributes)
105
106# Disable note popups on compiler ABI changes
107if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
108 add_compile_options("-Wno-psabi")
109endif()
110
111# Compile with -Werror if WERROR set
112if(WERROR)
113 add_compile_options("-Werror")
114endif()
115
116# Compile with debug flags and define ARM_COMPUTE_ASSERTS_ENABLED if DEBUG set
117if(DEBUG)
118 add_compile_options("-O0" "-g" "-gdwarf-2")
119 add_definitions(-DARM_COMPUTE_ASSERTS_ENABLED) # ARM_COMPUTE_DEBUG_ENABLED ??
120endif()
121
122# Compile with -fno-exceptions flag and define ARM_COMPUTE_EXCEPTIONS_DISABLED
123# if DEBUG set
124if(NOT EXCEPTIONS)
125 add_compile_options("-fno-exceptions")
126 add_definitions(-DARM_COMPUTE_EXCEPTIONS_DISABLED)
127endif()
128
129# Link OpenMP libraries if OPENMP flag on
130if(OPENMP)
131 find_package(OpenMP)
132 if(OpenMP_CXX_FOUND)
133 link_libraries(OpenMP::OpenMP_CXX)
134 add_definitions(-DARM_COMPUTE_OPENMP_SCHEDULER)
135 else()
136 message(FATAL_ERROR "OPENMP was set but no OpenMP library was found!")
137 endif()
138endif()
139
140# ---------------------------------------------------------------------
141# SVE Library
142
143add_library(arm_compute_sve "")
144target_compile_options(arm_compute_sve
145 PRIVATE "-march=armv8.2-a+sve+fp16+dotprod")
146target_compile_definitions(arm_compute_sve PRIVATE ENABLE_SVE)
147target_compile_definitions(arm_compute_sve PRIVATE ARM_COMPUTE_ENABLE_SVE)
148
149target_include_directories(
150 arm_compute_sve
151 PUBLIC $<INSTALL_INTERFACE:include>
152 $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
153 ${CMAKE_CURRENT_SOURCE_DIR}
154 PUBLIC src
155 src/core/NEON/kernels/arm_conv
156 src/core/NEON/kernels/arm_gemm
157 src/core/NEON/kernels/assembly
158 src/core/cpu/kernels/assembly
159 src/cpu/kernels/assembly
160 src/core/NEON/kernels/arm_gemm/merges)
161
162# ---------------------------------------------------------------------
163# SVE2 Library
164
165add_library(arm_compute_sve2 "")
166target_compile_options(arm_compute_sve2
167 PRIVATE "-march=armv8.6-a+sve2+fp16+dotprod")
168target_compile_definitions(arm_compute_sve2 PRIVATE ENABLE_SVE)
169target_compile_definitions(arm_compute_sve2 PRIVATE ARM_COMPUTE_ENABLE_SVE)
170target_compile_definitions(arm_compute_sve2 PRIVATE ARM_COMPUTE_ENABLE_SVE2)
171
172target_include_directories(
173 arm_compute_sve2
174 PUBLIC $<INSTALL_INTERFACE:include>
175 $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
176 ${CMAKE_CURRENT_SOURCE_DIR}
177 PUBLIC src
178 src/core/NEON/kernels/arm_conv
179 src/core/NEON/kernels/arm_gemm
180 src/core/NEON/kernels/assembly
181 src/core/cpu/kernels/assembly
182 src/cpu/kernels/assembly
183 src/core/NEON/kernels/arm_gemm/merges)
184
185# ---------------------------------------------------------------------
186# Core Library
187
188add_library(arm_compute_core "")
189target_compile_options(arm_compute_core PRIVATE "-march=armv8.2-a+fp16")
190target_include_directories(
191 arm_compute_core
192 PUBLIC $<INSTALL_INTERFACE:include>
193 $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
194 ${CMAKE_CURRENT_SOURCE_DIR}
195 PRIVATE src
196 src/cpu/kernels/assembly
197 src/core/NEON/kernels/assembly
198 src/core/NEON/kernels/convolution/common
199 src/core/NEON/kernels/arm_conv/depthwise
200 src/core/NEON/kernels/convolution/winograd)
201target_compile_options(arm_compute_core PUBLIC ${COMMON_CXX_FLAGS})
202
203add_library(ArmCompute::Core ALIAS arm_compute_core)
204
205# ---------------------------------------------------------------------
206# Graph Library
207
208add_library(arm_compute_graph "")
209target_compile_options(arm_compute_graph PRIVATE "-march=armv8.2-a+fp16")
210# add_subdirectory(src/graph)
211
212target_include_directories(
213 arm_compute_graph
214 PUBLIC $<INSTALL_INTERFACE:include>
215 $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
216 ${CMAKE_CURRENT_SOURCE_DIR}
217 PRIVATE src
218 src/cpu/kernels/assembly
219 src/core/NEON/kernels/assembly
220 src/core/NEON/kernels/convolution/common
221 src/core/NEON/kernels/arm_conv/depthwise
222 src/core/NEON/kernels/convolution/winograd)
223target_compile_options(arm_compute_graph PUBLIC ${COMMON_CXX_FLAGS})
224
225add_library(ArmCompute::Graph ALIAS arm_compute_graph)
226
227# ---------------------------------------------------------------------
228# Library Target Sources
229add_subdirectory(src)
230
231# ---------------------------------------------------------------------
232# Validation Framework Library
233add_library(arm_compute_validation_framework "")
234# target_compile_options(arm_compute_validation_framework PRIVATE
235# "-march=armv8.2-a")
236target_compile_options(arm_compute_validation_framework
237 PRIVATE "-march=armv8.2-a+fp16")
238
239add_subdirectory(tests)
240target_include_directories(
241 arm_compute_validation_framework
242 PUBLIC $<INSTALL_INTERFACE:include>
243 $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
244 ${CMAKE_CURRENT_SOURCE_DIR})
245target_compile_options(arm_compute_validation_framework
246 PUBLIC ${COMMON_CXX_FLAGS})
247 target_link_libraries(
248 arm_compute_validation_framework
249 PUBLIC arm_compute_core arm_compute_graph)
250
251# ---------------------------------------------------------------------
252# Validation Binary
253
254if(BUILD_TESTING)
255
256 add_executable(arm_compute_validation "")
257 target_compile_options(arm_compute_validation PRIVATE "-march=armv8.2-a+fp16")
258
259 add_subdirectory(tests/validation)
260 target_compile_options(arm_compute_validation PUBLIC ${COMMON_CXX_FLAGS})
261 set_target_properties(
262 arm_compute_validation PROPERTIES RUNTIME_OUTPUT_DIRECTORY
263 "${CMAKE_BINARY_DIR}/validation")
264 target_link_libraries(
265 arm_compute_validation
266 PUBLIC arm_compute_core arm_compute_graph arm_compute_validation_framework
267 arm_compute_sve)
268 target_link_directories(arm_compute_validation PUBLIC tests)
269
270 # ---------------------------------------------------------------------
271 # Benchmark Binary
272
273 add_executable(arm_compute_benchmark)
274 target_compile_options(arm_compute_benchmark PRIVATE "-march=armv8.2-a+fp16")
275
276 add_subdirectory(tests/benchmark)
277 target_compile_options(arm_compute_benchmark PUBLIC ${COMMON_CXX_FLAGS})
278 set_target_properties(
279 arm_compute_benchmark PROPERTIES RUNTIME_OUTPUT_DIRECTORY
280 "${CMAKE_BINARY_DIR}/validation")
281 target_link_libraries(
282 arm_compute_benchmark PUBLIC arm_compute_core arm_compute_graph
283 arm_compute_validation_framework)
284
285endif() # BUILD_TESTING
286# ---------------------------------------------------------------------
287# Examples Binaries
288
289if(BUILD_EXAMPLES)
290
291 add_subdirectory(examples)
292
293 # Graph Examples
294 foreach(test_name ${EXAMPLE_GRAPH_NAMES})
295 add_executable(
296 ${test_name} "examples/${test_name}.cpp" utils/Utils.cpp
297 utils/GraphUtils.cpp utils/CommonGraphOptions.cpp)
298 target_compile_options(${test_name} PRIVATE "-march=armv8.2-a+fp16")
299 set_target_properties(
300 ${test_name} PROPERTIES RUNTIME_OUTPUT_DIRECTORY
301 "${CMAKE_BINARY_DIR}/examples")
302 target_link_libraries(${test_name} PUBLIC arm_compute_core
303 arm_compute_graph arm_compute_sve)
304 endforeach()
305
306 # NEON Examples
307 foreach(test_name ${EXAMPLE_NEON_NAMES})
308 add_executable(${test_name} "examples/${test_name}.cpp" utils/Utils.cpp)
309 target_compile_options(${test_name} PRIVATE "-march=armv8.2-a+fp16")
310 set_target_properties(
311 ${test_name} PROPERTIES RUNTIME_OUTPUT_DIRECTORY
312 "${CMAKE_BINARY_DIR}/examples")
313 target_link_libraries(${test_name} PUBLIC arm_compute_core)
314 endforeach()
315
316endif() # BUILD_EXAMPLES