David Svantesson | e0c42ef | 2022-12-15 16:25:57 +0000 | [diff] [blame] | 1 | # 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 | |
| 23 | cmake_minimum_required(VERSION 3.13 FATAL_ERROR) |
| 24 | |
| 25 | # --------------------------------------------------------------------- |
| 26 | # Project ArmCompute |
| 27 | |
| 28 | list(APPEND CMAKE_MESSAGE_CONTEXT ArmCompute) |
| 29 | project( |
| 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 | |
| 36 | include(GNUInstallDirs) |
| 37 | |
| 38 | set(CMAKE_C_STANDARD 99) |
| 39 | set(CMAKE_C_STANDARD_REQUIRED ON) |
| 40 | set(CMAKE_C_EXTENSIONS OFF) |
| 41 | |
| 42 | set(CMAKE_CXX_STANDARD 14) |
| 43 | set(CMAKE_CXX_STANDARD_REQUIRED ON) |
| 44 | set(CMAKE_CXX_EXTENSIONS OFF) |
| 45 | |
| 46 | list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake") |
| 47 | include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/Options.cmake) |
| 48 | include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/Version.cmake) |
| 49 | |
| 50 | # Require at least gcc/g++ 11) CMAKE_CXX_COMPILER_VERSION OR |
| 51 | if(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!") |
| 55 | endif() |
| 56 | |
| 57 | # --------------------------------------------------------------------- |
| 58 | # Configuration |
| 59 | |
| 60 | # Default to Release Build |
| 61 | if(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) |
| 68 | endif() |
| 69 | |
| 70 | # --------------------------------------------------------------------- |
| 71 | # Information |
| 72 | |
| 73 | message(STATUS "Arm Compute Library ${PROJECT_VERSION}") |
| 74 | |
| 75 | message(VERBOSE "-----------------------------------------------------") |
| 76 | message(VERBOSE "Build information:") |
| 77 | list(APPEND CMAKE_MESSAGE_INDENT " ") |
| 78 | message(VERBOSE "Host system: ${CMAKE_SYSTEM_NAME}") |
| 79 | message(VERBOSE "Host processor: ${CMAKE_SYSTEM_PROCESSOR}") |
| 80 | message(VERBOSE "Build path: ${CMAKE_CURRENT_BINARY_DIR}") |
| 81 | message(VERBOSE "Enable OpenCL acceleration: ${ENABLE_OPENCL}") |
| 82 | message(VERBOSE "Enable CPU acceleration: ${ENABLE_NEON}") |
| 83 | list(POP_BACK CMAKE_MESSAGE_INDENT) |
| 84 | message(VERBOSE "-----------------------------------------------------") |
| 85 | |
| 86 | # --------------------------------------------------------------------- |
| 87 | # Compile options and features |
| 88 | |
| 89 | set(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 Svantesson | 4537089 | 2023-02-22 11:08:57 +0000 | [diff] [blame] | 104 | -Wno-ignored-attributes |
| 105 | -Wlogical-op |
| 106 | -Wnoexcept |
| 107 | -Wstrict-null-sentinel |
| 108 | -Wno-misleading-indentation |
| 109 | -O3) |
David Svantesson | e0c42ef | 2022-12-15 16:25:57 +0000 | [diff] [blame] | 110 | |
| 111 | # Disable note popups on compiler ABI changes |
| 112 | if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU") |
| 113 | add_compile_options("-Wno-psabi") |
| 114 | endif() |
| 115 | |
| 116 | # Compile with -Werror if WERROR set |
| 117 | if(WERROR) |
| 118 | add_compile_options("-Werror") |
| 119 | endif() |
| 120 | |
| 121 | # Compile with debug flags and define ARM_COMPUTE_ASSERTS_ENABLED if DEBUG set |
| 122 | if(DEBUG) |
| 123 | add_compile_options("-O0" "-g" "-gdwarf-2") |
| 124 | add_definitions(-DARM_COMPUTE_ASSERTS_ENABLED) # ARM_COMPUTE_DEBUG_ENABLED ?? |
| 125 | endif() |
| 126 | |
| 127 | # Compile with -fno-exceptions flag and define ARM_COMPUTE_EXCEPTIONS_DISABLED |
| 128 | # if DEBUG set |
| 129 | if(NOT EXCEPTIONS) |
| 130 | add_compile_options("-fno-exceptions") |
| 131 | add_definitions(-DARM_COMPUTE_EXCEPTIONS_DISABLED) |
| 132 | endif() |
| 133 | |
| 134 | # Link OpenMP libraries if OPENMP flag on |
| 135 | if(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() |
| 143 | endif() |
| 144 | |
| 145 | # --------------------------------------------------------------------- |
| 146 | # SVE Library |
| 147 | |
| 148 | add_library(arm_compute_sve "") |
| 149 | target_compile_options(arm_compute_sve |
| 150 | PRIVATE "-march=armv8.2-a+sve+fp16+dotprod") |
David Svantesson | 4537089 | 2023-02-22 11:08:57 +0000 | [diff] [blame] | 151 | target_compile_definitions(arm_compute_sve PRIVATE ARM_COMPUTE_ENABLE_BF16) |
David Svantesson | 3b162e5 | 2023-03-28 14:13:32 +0000 | [diff] [blame] | 152 | target_compile_definitions(arm_compute_sve PRIVATE ENABLE_SVE) |
| 153 | target_compile_definitions(arm_compute_sve PRIVATE ARM_COMPUTE_ENABLE_SVE) |
David Svantesson | e0c42ef | 2022-12-15 16:25:57 +0000 | [diff] [blame] | 154 | target_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 | |
| 170 | add_library(arm_compute_sve2 "") |
| 171 | target_compile_options(arm_compute_sve2 |
| 172 | PRIVATE "-march=armv8.6-a+sve2+fp16+dotprod") |
David Svantesson | e0c42ef | 2022-12-15 16:25:57 +0000 | [diff] [blame] | 173 | target_compile_definitions(arm_compute_sve2 PRIVATE ARM_COMPUTE_ENABLE_SVE2) |
David Svantesson | 4537089 | 2023-02-22 11:08:57 +0000 | [diff] [blame] | 174 | target_compile_definitions(arm_compute_sve2 PRIVATE ARM_COMPUTE_ENABLE_BF16) |
David Svantesson | 3b162e5 | 2023-03-28 14:13:32 +0000 | [diff] [blame] | 175 | target_compile_definitions(arm_compute_sve2 PRIVATE ENABLE_SVE) |
| 176 | target_compile_definitions(arm_compute_sve2 PRIVATE ARM_COMPUTE_ENABLE_SVE) |
David Svantesson | e0c42ef | 2022-12-15 16:25:57 +0000 | [diff] [blame] | 177 | target_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 | |
| 193 | add_library(arm_compute_core "") |
| 194 | target_compile_options(arm_compute_core PRIVATE "-march=armv8.2-a+fp16") |
David Svantesson | 4537089 | 2023-02-22 11:08:57 +0000 | [diff] [blame] | 195 | target_compile_definitions(arm_compute_core PRIVATE ARM_COMPUTE_ENABLE_BF16) |
David Svantesson | 3b162e5 | 2023-03-28 14:13:32 +0000 | [diff] [blame] | 196 | target_compile_definitions(arm_compute_core PRIVATE ENABLE_SVE) |
| 197 | target_compile_definitions(arm_compute_core PRIVATE ARM_COMPUTE_ENABLE_SVE) |
David Svantesson | e0c42ef | 2022-12-15 16:25:57 +0000 | [diff] [blame] | 198 | target_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) |
| 209 | target_compile_options(arm_compute_core PUBLIC ${COMMON_CXX_FLAGS}) |
| 210 | |
| 211 | add_library(ArmCompute::Core ALIAS arm_compute_core) |
David Svantesson | 4537089 | 2023-02-22 11:08:57 +0000 | [diff] [blame] | 212 | target_link_libraries( |
| 213 | arm_compute_core PUBLIC arm_compute_sve arm_compute_sve2) |
David Svantesson | e0c42ef | 2022-12-15 16:25:57 +0000 | [diff] [blame] | 214 | |
| 215 | # --------------------------------------------------------------------- |
| 216 | # Graph Library |
| 217 | |
| 218 | add_library(arm_compute_graph "") |
| 219 | target_compile_options(arm_compute_graph PRIVATE "-march=armv8.2-a+fp16") |
David Svantesson | 3b162e5 | 2023-03-28 14:13:32 +0000 | [diff] [blame] | 220 | target_compile_definitions(arm_compute_graph PRIVATE ENABLE_SVE) |
| 221 | target_compile_definitions(arm_compute_graph PRIVATE ARM_COMPUTE_ENABLE_SVE) |
David Svantesson | e0c42ef | 2022-12-15 16:25:57 +0000 | [diff] [blame] | 222 | # add_subdirectory(src/graph) |
| 223 | |
| 224 | target_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) |
| 235 | target_compile_options(arm_compute_graph PUBLIC ${COMMON_CXX_FLAGS}) |
| 236 | |
| 237 | add_library(ArmCompute::Graph ALIAS arm_compute_graph) |
| 238 | |
| 239 | # --------------------------------------------------------------------- |
| 240 | # Library Target Sources |
| 241 | add_subdirectory(src) |
| 242 | |
| 243 | # --------------------------------------------------------------------- |
| 244 | # Validation Framework Library |
| 245 | add_library(arm_compute_validation_framework "") |
| 246 | # target_compile_options(arm_compute_validation_framework PRIVATE |
| 247 | # "-march=armv8.2-a") |
| 248 | target_compile_options(arm_compute_validation_framework |
| 249 | PRIVATE "-march=armv8.2-a+fp16") |
| 250 | |
| 251 | add_subdirectory(tests) |
| 252 | target_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}) |
| 257 | target_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 | |
| 266 | if(BUILD_TESTING) |
| 267 | |
| 268 | add_executable(arm_compute_validation "") |
| 269 | target_compile_options(arm_compute_validation PRIVATE "-march=armv8.2-a+fp16") |
David Svantesson | 4537089 | 2023-02-22 11:08:57 +0000 | [diff] [blame] | 270 | if(ENABLE_BF16_VALIDATION) |
| 271 | target_compile_definitions(arm_compute_validation PRIVATE ARM_COMPUTE_ENABLE_BF16) |
| 272 | endif() |
David Svantesson | 3b162e5 | 2023-03-28 14:13:32 +0000 | [diff] [blame] | 273 | 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 Svantesson | e0c42ef | 2022-12-15 16:25:57 +0000 | [diff] [blame] | 277 | 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 | |
| 303 | endif() # BUILD_TESTING |
| 304 | # --------------------------------------------------------------------- |
| 305 | # Examples Binaries |
| 306 | |
| 307 | if(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 | |
| 334 | endif() # BUILD_EXAMPLES |