blob: 72992ed03846ec7ac0a4d6fc14dcbf12348ed470 [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
David Svantessonb8b70342023-02-22 11:08:57 +0000104 -Wno-ignored-attributes
105 -Wlogical-op
106 -Wnoexcept
107 -Wstrict-null-sentinel
108 -Wno-misleading-indentation
109 -O3)
David Svantessone0c42ef2022-12-15 16:25:57 +0000110
111# Disable note popups on compiler ABI changes
112if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
113 add_compile_options("-Wno-psabi")
114endif()
115
116# Compile with -Werror if WERROR set
117if(WERROR)
118 add_compile_options("-Werror")
119endif()
120
121# Compile with debug flags and define ARM_COMPUTE_ASSERTS_ENABLED if DEBUG set
122if(DEBUG)
123 add_compile_options("-O0" "-g" "-gdwarf-2")
124 add_definitions(-DARM_COMPUTE_ASSERTS_ENABLED) # ARM_COMPUTE_DEBUG_ENABLED ??
125endif()
126
127# Compile with -fno-exceptions flag and define ARM_COMPUTE_EXCEPTIONS_DISABLED
128# if DEBUG set
129if(NOT EXCEPTIONS)
130 add_compile_options("-fno-exceptions")
131 add_definitions(-DARM_COMPUTE_EXCEPTIONS_DISABLED)
132endif()
133
134# Link OpenMP libraries if OPENMP flag on
135if(OPENMP)
136 find_package(OpenMP)
137 if(OpenMP_CXX_FOUND)
138 link_libraries(OpenMP::OpenMP_CXX)
139 add_definitions(-DARM_COMPUTE_OPENMP_SCHEDULER)
140 else()
141 message(FATAL_ERROR "OPENMP was set but no OpenMP library was found!")
142 endif()
143endif()
144
145# ---------------------------------------------------------------------
146# SVE Library
147
148add_library(arm_compute_sve "")
149target_compile_options(arm_compute_sve
150 PRIVATE "-march=armv8.2-a+sve+fp16+dotprod")
David Svantessonb8b70342023-02-22 11:08:57 +0000151target_compile_definitions(arm_compute_sve PRIVATE ARM_COMPUTE_ENABLE_BF16)
David Svantessone0c42ef2022-12-15 16:25:57 +0000152target_include_directories(
153 arm_compute_sve
154 PUBLIC $<INSTALL_INTERFACE:include>
155 $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
156 ${CMAKE_CURRENT_SOURCE_DIR}
157 PUBLIC src
158 src/core/NEON/kernels/arm_conv
159 src/core/NEON/kernels/arm_gemm
160 src/core/NEON/kernels/assembly
161 src/core/cpu/kernels/assembly
162 src/cpu/kernels/assembly
163 src/core/NEON/kernels/arm_gemm/merges)
164
165# ---------------------------------------------------------------------
166# SVE2 Library
167
168add_library(arm_compute_sve2 "")
169target_compile_options(arm_compute_sve2
170 PRIVATE "-march=armv8.6-a+sve2+fp16+dotprod")
David Svantessone0c42ef2022-12-15 16:25:57 +0000171target_compile_definitions(arm_compute_sve2 PRIVATE ARM_COMPUTE_ENABLE_SVE2)
David Svantessonb8b70342023-02-22 11:08:57 +0000172target_compile_definitions(arm_compute_sve2 PRIVATE ARM_COMPUTE_ENABLE_BF16)
David Svantessone0c42ef2022-12-15 16:25:57 +0000173target_include_directories(
174 arm_compute_sve2
175 PUBLIC $<INSTALL_INTERFACE:include>
176 $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
177 ${CMAKE_CURRENT_SOURCE_DIR}
178 PUBLIC src
179 src/core/NEON/kernels/arm_conv
180 src/core/NEON/kernels/arm_gemm
181 src/core/NEON/kernels/assembly
182 src/core/cpu/kernels/assembly
183 src/cpu/kernels/assembly
184 src/core/NEON/kernels/arm_gemm/merges)
185
186# ---------------------------------------------------------------------
187# Core Library
188
189add_library(arm_compute_core "")
190target_compile_options(arm_compute_core PRIVATE "-march=armv8.2-a+fp16")
David Svantessonb8b70342023-02-22 11:08:57 +0000191target_compile_definitions(arm_compute_core PRIVATE ARM_COMPUTE_ENABLE_BF16)
David Svantessone0c42ef2022-12-15 16:25:57 +0000192target_include_directories(
193 arm_compute_core
194 PUBLIC $<INSTALL_INTERFACE:include>
195 $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
196 ${CMAKE_CURRENT_SOURCE_DIR}
197 PRIVATE src
198 src/cpu/kernels/assembly
199 src/core/NEON/kernels/assembly
200 src/core/NEON/kernels/convolution/common
201 src/core/NEON/kernels/arm_conv/depthwise
202 src/core/NEON/kernels/convolution/winograd)
203target_compile_options(arm_compute_core PUBLIC ${COMMON_CXX_FLAGS})
204
205add_library(ArmCompute::Core ALIAS arm_compute_core)
David Svantessonb8b70342023-02-22 11:08:57 +0000206target_link_libraries(
207 arm_compute_core PUBLIC arm_compute_sve arm_compute_sve2)
David Svantessone0c42ef2022-12-15 16:25:57 +0000208
209# ---------------------------------------------------------------------
210# Graph Library
211
212add_library(arm_compute_graph "")
213target_compile_options(arm_compute_graph PRIVATE "-march=armv8.2-a+fp16")
214# add_subdirectory(src/graph)
215
216target_include_directories(
217 arm_compute_graph
218 PUBLIC $<INSTALL_INTERFACE:include>
219 $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
220 ${CMAKE_CURRENT_SOURCE_DIR}
221 PRIVATE src
222 src/cpu/kernels/assembly
223 src/core/NEON/kernels/assembly
224 src/core/NEON/kernels/convolution/common
225 src/core/NEON/kernels/arm_conv/depthwise
226 src/core/NEON/kernels/convolution/winograd)
227target_compile_options(arm_compute_graph PUBLIC ${COMMON_CXX_FLAGS})
228
229add_library(ArmCompute::Graph ALIAS arm_compute_graph)
230
231# ---------------------------------------------------------------------
232# Library Target Sources
233add_subdirectory(src)
234
235# ---------------------------------------------------------------------
236# Validation Framework Library
237add_library(arm_compute_validation_framework "")
238# target_compile_options(arm_compute_validation_framework PRIVATE
239# "-march=armv8.2-a")
240target_compile_options(arm_compute_validation_framework
241 PRIVATE "-march=armv8.2-a+fp16")
242
243add_subdirectory(tests)
244target_include_directories(
245 arm_compute_validation_framework
246 PUBLIC $<INSTALL_INTERFACE:include>
247 $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
248 ${CMAKE_CURRENT_SOURCE_DIR})
249target_compile_options(arm_compute_validation_framework
250 PUBLIC ${COMMON_CXX_FLAGS})
251 target_link_libraries(
252 arm_compute_validation_framework
253 PUBLIC arm_compute_core arm_compute_graph)
254
255# ---------------------------------------------------------------------
256# Validation Binary
257
258if(BUILD_TESTING)
259
260 add_executable(arm_compute_validation "")
261 target_compile_options(arm_compute_validation PRIVATE "-march=armv8.2-a+fp16")
David Svantessonb8b70342023-02-22 11:08:57 +0000262 if(ENABLE_BF16_VALIDATION)
263 target_compile_definitions(arm_compute_validation PRIVATE ARM_COMPUTE_ENABLE_BF16)
264 endif()
David Svantessone0c42ef2022-12-15 16:25:57 +0000265 add_subdirectory(tests/validation)
266 target_compile_options(arm_compute_validation PUBLIC ${COMMON_CXX_FLAGS})
267 set_target_properties(
268 arm_compute_validation PROPERTIES RUNTIME_OUTPUT_DIRECTORY
269 "${CMAKE_BINARY_DIR}/validation")
270 target_link_libraries(
271 arm_compute_validation
272 PUBLIC arm_compute_core arm_compute_graph arm_compute_validation_framework
273 arm_compute_sve)
274 target_link_directories(arm_compute_validation PUBLIC tests)
275
276 # ---------------------------------------------------------------------
277 # Benchmark Binary
278
279 add_executable(arm_compute_benchmark)
280 target_compile_options(arm_compute_benchmark PRIVATE "-march=armv8.2-a+fp16")
281
282 add_subdirectory(tests/benchmark)
283 target_compile_options(arm_compute_benchmark PUBLIC ${COMMON_CXX_FLAGS})
284 set_target_properties(
285 arm_compute_benchmark PROPERTIES RUNTIME_OUTPUT_DIRECTORY
286 "${CMAKE_BINARY_DIR}/validation")
287 target_link_libraries(
288 arm_compute_benchmark PUBLIC arm_compute_core arm_compute_graph
289 arm_compute_validation_framework)
290
291endif() # BUILD_TESTING
292# ---------------------------------------------------------------------
293# Examples Binaries
294
295if(BUILD_EXAMPLES)
296
297 add_subdirectory(examples)
298
299 # Graph Examples
300 foreach(test_name ${EXAMPLE_GRAPH_NAMES})
301 add_executable(
302 ${test_name} "examples/${test_name}.cpp" utils/Utils.cpp
303 utils/GraphUtils.cpp utils/CommonGraphOptions.cpp)
304 target_compile_options(${test_name} PRIVATE "-march=armv8.2-a+fp16")
305 set_target_properties(
306 ${test_name} PROPERTIES RUNTIME_OUTPUT_DIRECTORY
307 "${CMAKE_BINARY_DIR}/examples")
308 target_link_libraries(${test_name} PUBLIC arm_compute_core
309 arm_compute_graph arm_compute_sve)
310 endforeach()
311
312 # NEON Examples
313 foreach(test_name ${EXAMPLE_NEON_NAMES})
314 add_executable(${test_name} "examples/${test_name}.cpp" utils/Utils.cpp)
315 target_compile_options(${test_name} PRIVATE "-march=armv8.2-a+fp16")
316 set_target_properties(
317 ${test_name} PROPERTIES RUNTIME_OUTPUT_DIRECTORY
318 "${CMAKE_BINARY_DIR}/examples")
319 target_link_libraries(${test_name} PUBLIC arm_compute_core)
320 endforeach()
321
322endif() # BUILD_EXAMPLES