blob: 060370d33a6eebae67af61c8ca7931aa197ef970 [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 Svantesson45370892023-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 Svantesson45370892023-02-22 11:08:57 +0000151target_compile_definitions(arm_compute_sve PRIVATE ARM_COMPUTE_ENABLE_BF16)
David Svantesson3b162e52023-03-28 14:13:32 +0000152target_compile_definitions(arm_compute_sve PRIVATE ENABLE_SVE)
153target_compile_definitions(arm_compute_sve PRIVATE ARM_COMPUTE_ENABLE_SVE)
David Svantessone0c42ef2022-12-15 16:25:57 +0000154target_include_directories(
155 arm_compute_sve
156 PUBLIC $<INSTALL_INTERFACE:include>
157 $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
158 ${CMAKE_CURRENT_SOURCE_DIR}
159 PUBLIC src
160 src/core/NEON/kernels/arm_conv
161 src/core/NEON/kernels/arm_gemm
162 src/core/NEON/kernels/assembly
163 src/core/cpu/kernels/assembly
164 src/cpu/kernels/assembly
165 src/core/NEON/kernels/arm_gemm/merges)
166
167# ---------------------------------------------------------------------
168# SVE2 Library
169
170add_library(arm_compute_sve2 "")
171target_compile_options(arm_compute_sve2
172 PRIVATE "-march=armv8.6-a+sve2+fp16+dotprod")
David Svantessone0c42ef2022-12-15 16:25:57 +0000173target_compile_definitions(arm_compute_sve2 PRIVATE ARM_COMPUTE_ENABLE_SVE2)
David Svantesson45370892023-02-22 11:08:57 +0000174target_compile_definitions(arm_compute_sve2 PRIVATE ARM_COMPUTE_ENABLE_BF16)
David Svantesson3b162e52023-03-28 14:13:32 +0000175target_compile_definitions(arm_compute_sve2 PRIVATE ENABLE_SVE)
176target_compile_definitions(arm_compute_sve2 PRIVATE ARM_COMPUTE_ENABLE_SVE)
David Svantessone0c42ef2022-12-15 16:25:57 +0000177target_include_directories(
178 arm_compute_sve2
179 PUBLIC $<INSTALL_INTERFACE:include>
180 $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
181 ${CMAKE_CURRENT_SOURCE_DIR}
182 PUBLIC src
183 src/core/NEON/kernels/arm_conv
184 src/core/NEON/kernels/arm_gemm
185 src/core/NEON/kernels/assembly
186 src/core/cpu/kernels/assembly
187 src/cpu/kernels/assembly
188 src/core/NEON/kernels/arm_gemm/merges)
189
190# ---------------------------------------------------------------------
191# Core Library
192
193add_library(arm_compute_core "")
194target_compile_options(arm_compute_core PRIVATE "-march=armv8.2-a+fp16")
David Svantesson45370892023-02-22 11:08:57 +0000195target_compile_definitions(arm_compute_core PRIVATE ARM_COMPUTE_ENABLE_BF16)
David Svantesson3b162e52023-03-28 14:13:32 +0000196target_compile_definitions(arm_compute_core PRIVATE ENABLE_SVE)
197target_compile_definitions(arm_compute_core PRIVATE ARM_COMPUTE_ENABLE_SVE)
David Svantessone0c42ef2022-12-15 16:25:57 +0000198target_include_directories(
199 arm_compute_core
200 PUBLIC $<INSTALL_INTERFACE:include>
201 $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
202 ${CMAKE_CURRENT_SOURCE_DIR}
203 PRIVATE src
204 src/cpu/kernels/assembly
205 src/core/NEON/kernels/assembly
206 src/core/NEON/kernels/convolution/common
207 src/core/NEON/kernels/arm_conv/depthwise
208 src/core/NEON/kernels/convolution/winograd)
209target_compile_options(arm_compute_core PUBLIC ${COMMON_CXX_FLAGS})
210
211add_library(ArmCompute::Core ALIAS arm_compute_core)
David Svantesson45370892023-02-22 11:08:57 +0000212target_link_libraries(
213 arm_compute_core PUBLIC arm_compute_sve arm_compute_sve2)
David Svantessone0c42ef2022-12-15 16:25:57 +0000214
215# ---------------------------------------------------------------------
216# Graph Library
217
218add_library(arm_compute_graph "")
219target_compile_options(arm_compute_graph PRIVATE "-march=armv8.2-a+fp16")
David Svantesson3b162e52023-03-28 14:13:32 +0000220target_compile_definitions(arm_compute_graph PRIVATE ENABLE_SVE)
221target_compile_definitions(arm_compute_graph PRIVATE ARM_COMPUTE_ENABLE_SVE)
David Svantessone0c42ef2022-12-15 16:25:57 +0000222# add_subdirectory(src/graph)
223
224target_include_directories(
225 arm_compute_graph
226 PUBLIC $<INSTALL_INTERFACE:include>
227 $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
228 ${CMAKE_CURRENT_SOURCE_DIR}
229 PRIVATE src
230 src/cpu/kernels/assembly
231 src/core/NEON/kernels/assembly
232 src/core/NEON/kernels/convolution/common
233 src/core/NEON/kernels/arm_conv/depthwise
234 src/core/NEON/kernels/convolution/winograd)
235target_compile_options(arm_compute_graph PUBLIC ${COMMON_CXX_FLAGS})
236
237add_library(ArmCompute::Graph ALIAS arm_compute_graph)
238
239# ---------------------------------------------------------------------
240# Library Target Sources
241add_subdirectory(src)
242
243# ---------------------------------------------------------------------
244# Validation Framework Library
245add_library(arm_compute_validation_framework "")
246# target_compile_options(arm_compute_validation_framework PRIVATE
247# "-march=armv8.2-a")
248target_compile_options(arm_compute_validation_framework
249 PRIVATE "-march=armv8.2-a+fp16")
250
251add_subdirectory(tests)
252target_include_directories(
253 arm_compute_validation_framework
254 PUBLIC $<INSTALL_INTERFACE:include>
255 $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
256 ${CMAKE_CURRENT_SOURCE_DIR})
257target_compile_options(arm_compute_validation_framework
258 PUBLIC ${COMMON_CXX_FLAGS})
259 target_link_libraries(
260 arm_compute_validation_framework
261 PUBLIC arm_compute_core arm_compute_graph)
262
263# ---------------------------------------------------------------------
264# Validation Binary
265
266if(BUILD_TESTING)
267
268 add_executable(arm_compute_validation "")
269 target_compile_options(arm_compute_validation PRIVATE "-march=armv8.2-a+fp16")
David Svantesson45370892023-02-22 11:08:57 +0000270 if(ENABLE_BF16_VALIDATION)
271 target_compile_definitions(arm_compute_validation PRIVATE ARM_COMPUTE_ENABLE_BF16)
272 endif()
David Svantesson3b162e52023-03-28 14:13:32 +0000273 if(ENABLE_SVE_VALIDATION)
274 target_compile_definitions(arm_compute_validation PRIVATE ENABLE_SVE)
275 target_compile_definitions(arm_compute_validation PRIVATE ARM_COMPUTE_ENABLE_SVE)
276 endif()
David Svantessone0c42ef2022-12-15 16:25:57 +0000277 add_subdirectory(tests/validation)
278 target_compile_options(arm_compute_validation PUBLIC ${COMMON_CXX_FLAGS})
279 set_target_properties(
280 arm_compute_validation PROPERTIES RUNTIME_OUTPUT_DIRECTORY
281 "${CMAKE_BINARY_DIR}/validation")
282 target_link_libraries(
283 arm_compute_validation
284 PUBLIC arm_compute_core arm_compute_graph arm_compute_validation_framework
285 arm_compute_sve)
286 target_link_directories(arm_compute_validation PUBLIC tests)
287
288 # ---------------------------------------------------------------------
289 # Benchmark Binary
290
291 add_executable(arm_compute_benchmark)
292 target_compile_options(arm_compute_benchmark PRIVATE "-march=armv8.2-a+fp16")
293
294 add_subdirectory(tests/benchmark)
295 target_compile_options(arm_compute_benchmark PUBLIC ${COMMON_CXX_FLAGS})
296 set_target_properties(
297 arm_compute_benchmark PROPERTIES RUNTIME_OUTPUT_DIRECTORY
298 "${CMAKE_BINARY_DIR}/validation")
299 target_link_libraries(
300 arm_compute_benchmark PUBLIC arm_compute_core arm_compute_graph
301 arm_compute_validation_framework)
302
303endif() # BUILD_TESTING
304# ---------------------------------------------------------------------
305# Examples Binaries
306
307if(BUILD_EXAMPLES)
308
309 add_subdirectory(examples)
310
311 # Graph Examples
312 foreach(test_name ${EXAMPLE_GRAPH_NAMES})
313 add_executable(
314 ${test_name} "examples/${test_name}.cpp" utils/Utils.cpp
315 utils/GraphUtils.cpp utils/CommonGraphOptions.cpp)
316 target_compile_options(${test_name} PRIVATE "-march=armv8.2-a+fp16")
317 set_target_properties(
318 ${test_name} PROPERTIES RUNTIME_OUTPUT_DIRECTORY
319 "${CMAKE_BINARY_DIR}/examples")
320 target_link_libraries(${test_name} PUBLIC arm_compute_core
321 arm_compute_graph arm_compute_sve)
322 endforeach()
323
324 # NEON Examples
325 foreach(test_name ${EXAMPLE_NEON_NAMES})
326 add_executable(${test_name} "examples/${test_name}.cpp" utils/Utils.cpp)
327 target_compile_options(${test_name} PRIVATE "-march=armv8.2-a+fp16")
328 set_target_properties(
329 ${test_name} PROPERTIES RUNTIME_OUTPUT_DIRECTORY
330 "${CMAKE_BINARY_DIR}/examples")
331 target_link_libraries(${test_name} PUBLIC arm_compute_core)
332 endforeach()
333
334endif() # BUILD_EXAMPLES