Skip to content

Commit 8280dbb

Browse files
committed
feat: Modernize ACL CMake build
These changes are in preparation for consuming ACL in higher level ML frameworks as part of the native CMake build. Notable changes made: - Removed incorrect compiler flags and definitions from targets. - Removed dependency on global CMake variables. ARM_COMPUTE_XXX variables are used to defined the build. - Adding coverage and sanitizer flags. - Providing more robust clang support, along with libcxx. - Fixed typo: QASYMM8_SINGED -> QASYMM8_SIGNED. - Now building a single 'arm_compute' library (i.e. there's no separate 'arm_compute_graph' library now). - Renaming *_CXX_*FLAGS -> *_CCXX_*FLAGS to indicate that they're used on C and C++ files. - Separated fp16 sources from the core library to follow the SCons build system. - Updated scripts/generate_build_files.py to handle the splitting of the fp16 sources from the core lib. NOTE: This does affect the ordering of files in src/BUILD.bazel. Changes for the future: - Organise source files in a scalable way and find a way to keep them in sync automatically with the scons build. - Add tests as part of the CMake test suite. - Add CMakePresets.json. - Further clean up. Change-Id: I51c76a20b5cbc5ca8d4c64d3d15ce0becd858f60 Signed-off-by: Puneet Matharu <puneet.matharu@arm.com> Signed-off-by: Hamza Butt <hamza.butt@arm.com> Reviewed-on: https://review.mlplatform.org/c/ml/ComputeLibrary/+/13643 Benchmark: Arm Jenkins <bsgcomp@arm.com> Comments-Addressed: Arm Jenkins <bsgcomp@arm.com> Tested-by: Arm Jenkins <bsgcomp@arm.com> Reviewed-by: Gunes Bayir <gunes.bayir@arm.com>
1 parent abd1caf commit 8280dbb

14 files changed

Lines changed: 692 additions & 631 deletions

File tree

CMakeLists.txt

Lines changed: 216 additions & 302 deletions
Large diffs are not rendered by default.

cmake/Options.cmake

Lines changed: 0 additions & 123 deletions
This file was deleted.

cmake/compilers/clang.cmake

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# Copyright (c) 2025 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+
if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang" AND CMAKE_CXX_COMPILER_FRONTEND_VARIANT STREQUAL "GNU")
24+
set(ARM_COMPUTE_NO_WARN_FLAG -w CACHE STRING "Compiler flags to disable warnings")
25+
set(ARM_COMPUTE_STANDARD_WARNINGS -Wall -Wextra -Wpedantic CACHE STRING "Compiler flags to enable warnings.")
26+
27+
# * Address sanitizer.
28+
set(ARM_COMPUTE_ASAN_COMPILER_FLAG_INIT -fsanitize=address -fno-omit-frame-pointer -fsanitize=undefined)
29+
set(ARM_COMPUTE_ASAN_LINKER_FLAG_INIT -fsanitize=address -fsanitize=undefined)
30+
31+
# * If we want to link with libc++.
32+
set(ARM_COMPUTE_LIBCXX_COMPILER_FLAG -stdlib=libc++ CACHE STRING "Compiler flags to use libc++.")
33+
set(ARM_COMPUTE_LIBCXX_LINKER_FLAG -stdlib=libc++ -lc++ -lc++abi -lm CACHE STRING "Linker flags to use libc++.")
34+
35+
# * Code coverage.
36+
set(ARM_COMPUTE_CODE_COVERAGE_COMPILER_FLAG_INIT --coverage CACHE STRING "Compiler flags to enable code coverage.")
37+
set(ARM_COMPUTE_CODE_COVERAGE_LINKER_FLAG_INIT --coverage CACHE STRING "Linker flags to enable code coverage.")
38+
39+
# * C/CXX flags.
40+
set(ARM_COMPUTE_CCXX_FLAGS_INIT "" CACHE STRING "Base C/CXX flags.")
41+
set(ARM_COMPUTE_CCXX_FLAGS_RELEASE -O3 CACHE STRING "Release config specific C/CXX flags.")
42+
set(ARM_COMPUTE_CCXX_FLAGS_DEBUG -g -O0 CACHE STRING "Debug config specific C/CXX flags.")
43+
44+
# * Linker flags.
45+
set(ARM_COMPUTE_LINKER_FLAGS_INIT "" CACHE STRING "Base linker flags.")
46+
set(ARM_COMPUTE_LINKER_FLAGS_DEBUG "" CACHE STRING "Debug config specific linker flags.")
47+
set(ARM_COMPUTE_LINKER_FLAGS_RELEASE "" CACHE STRING "Release config specific linker flags.")
48+
49+
# * LLD flags
50+
set(ARM_COMPUTE_LLD_LINKER_FLAGS "-fuse-ld=lld" CACHE STRING "Linker flags to use the LLD linker.")
51+
endif()

cmake/compilers/gcc.cmake

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# Copyright (c) 2025 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+
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
24+
set(ARM_COMPUTE_NO_WARN_FLAG -w CACHE STRING "Compiler flags to disable warnings")
25+
set(ARM_COMPUTE_STANDARD_WARNINGS -Wall -Wextra -Wpedantic CACHE STRING "Compiler flags to enable warnings.")
26+
27+
# * Address sanitizer.
28+
set(ARM_COMPUTE_ASAN_COMPILER_FLAG_INIT -fsanitize=address -fno-omit-frame-pointer -fsanitize=undefined)
29+
set(ARM_COMPUTE_ASAN_LINKER_FLAG_INIT -fsanitize=address -fsanitize=undefined)
30+
31+
# * Code coverage.
32+
set(ARM_COMPUTE_CODE_COVERAGE_COMPILER_FLAG_INIT --coverage CACHE STRING "Compiler flags to enable code coverage.")
33+
set(ARM_COMPUTE_CODE_COVERAGE_LINKER_FLAG_INIT --coverage CACHE STRING "Linker flags to enable code coverage.")
34+
35+
# * CXX flags.
36+
set(ARM_COMPUTE_CCXX_FLAGS_INIT "" CACHE STRING "Base C/CXX flags.")
37+
set(ARM_COMPUTE_CCXX_FLAGS_RELEASE -O3 CACHE STRING "Release config specific C/CXX flags.")
38+
set(ARM_COMPUTE_CCXX_FLAGS_DEBUG -g -O0 CACHE STRING "Debug config specific C/CXX flags.")
39+
40+
# * Linker flags.
41+
set(ARM_COMPUTE_LINKER_FLAGS_INIT "" CACHE STRING "Base linker flags.")
42+
set(ARM_COMPUTE_LINKER_FLAGS_DEBUG "" CACHE STRING "Debug config specific linker flags.")
43+
set(ARM_COMPUTE_LINKER_FLAGS_RELEASE "" CACHE STRING "Release config specific linker flags.")
44+
45+
if(ARM_COMPUTE_USE_LIBCXX)
46+
message(FATAL_ERROR "Libcxx is not enabled for this compiler/platform.")
47+
endif()
48+
49+
if(ARM_COMPUTE_USE_LLD)
50+
message(FATAL_ERROR "LLD is not enabled for this compiler/platform.")
51+
endif()
52+
endif()

cmake/compilers/setup.cmake

Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
# Copyright (c) 2025 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+
include(${CMAKE_CURRENT_LIST_DIR}/gcc.cmake)
24+
include(${CMAKE_CURRENT_LIST_DIR}/clang.cmake)
25+
26+
# Common definitions for all projects.
27+
set(
28+
ARM_COMPUTE_DEFINES
29+
30+
ARCH_ARM
31+
ARM_COMPUTE_CPU_ENABLED
32+
ARM_COMPUTE_GRAPH_ENABLED
33+
34+
# Kernels to build.
35+
ARM_COMPUTE_ENABLE_NEON
36+
ARM_COMPUTE_ENABLE_BF16
37+
ARM_COMPUTE_ENABLE_FP16
38+
ARM_COMPUTE_ENABLE_I8MM
39+
ARM_COMPUTE_ENABLE_SVE
40+
ARM_COMPUTE_ENABLE_SVE2
41+
ARM_COMPUTE_ENABLE_SVEF32MM
42+
ARM_COMPUTE_ENABLE_FIXED_FORMAT_KERNELS
43+
ENABLE_SVE
44+
ENABLE_SVE2
45+
ENABLE_NEON
46+
ENABLE_FP16_KERNELS
47+
ENABLE_FP32_KERNELS
48+
ENABLE_QASYMM8_KERNELS
49+
ENABLE_QASYMM8_SIGNED_KERNELS
50+
ENABLE_QSYMM16_KERNELS
51+
ENABLE_INTEGER_KERNELS
52+
ENABLE_NHWC_KERNELS
53+
ENABLE_NCHW_KERNELS
54+
55+
# Features controlled by options.
56+
$<$<BOOL:${ARM_COMPUTE_ENABLE_ASSERTS}>:ARM_COMPUTE_ASSERTS_ENABLED>
57+
$<$<BOOL:${ARM_COMPUTE_ENABLE_CPPTHREADS}>:ARM_COMPUTE_CPP_SCHEDULER>
58+
$<$<BOOL:${ARM_COMPUTE_ENABLE_LOGGING}>:ARM_COMPUTE_LOGGING_ENABLED>
59+
$<$<BOOL:${ARM_COMPUTE_ENABLE_OPENMP}>:ARM_COMPUTE_OPENMP_SCHEDULER>
60+
)
61+
62+
# * Select the correct compiler flags based on build configuration.
63+
set(
64+
ARM_COMPUTE_CCXX_WARNING_FLAGS
65+
$<IF:$<BOOL:${ARM_COMPUTE_ENABLE_WARNINGS}>,${ARM_COMPUTE_STANDARD_WARNINGS},${ARM_COMPUTE_NO_WARN_FLAG}>
66+
CACHE STRING "Overrides ARM_COMPUTE_STANDARD_WARNINGS and ARM_COMPUTE_NO_WARN_FLAG."
67+
)
68+
69+
set(
70+
ARM_COMPUTE_CCXX_FLAGS
71+
${ARM_COMPUTE_CCXX_FLAGS_INIT}
72+
$<IF:$<CONFIG:Debug>,${ARM_COMPUTE_CCXX_FLAGS_DEBUG},${ARM_COMPUTE_CCXX_FLAGS_RELEASE}>
73+
CACHE STRING "Overrides ARM_COMPUTE_CCXX_FLAGS_INIT, ARM_COMPUTE_CCXX_FLAGS_DEBUG and ARM_COMPUTE_CCXX_FLAGS_RELEASE"
74+
)
75+
76+
set(
77+
ARM_COMPUTE_LINKER_FLAGS
78+
${ARM_COMPUTE_LINKER_FLAGS_INIT}
79+
$<IF:$<CONFIG:Debug>,${ARM_COMPUTE_LINKER_FLAGS_DEBUG},${ARM_COMPUTE_LINKER_FLAGS_RELEASE}>
80+
CACHE STRING "Active linker flags."
81+
)
82+
83+
if(ARM_COMPUTE_ENABLE_SANITIZERS)
84+
set(ARM_COMPUTE_ASAN_COMPILER_FLAG $<$<CONFIG:DEBUG>:${ARM_COMPUTE_ASAN_COMPILER_FLAG_INIT}>)
85+
list(APPEND ARM_COMPUTE_LINKER_FLAGS $<$<CONFIG:DEBUG>:${ARM_COMPUTE_ASAN_LINKER_FLAG_INIT}>)
86+
endif()
87+
88+
if(ARM_COMPUTE_ENABLE_CODECOVERAGE)
89+
set(ARM_COMPUTE_CODE_COVERAGE_COMPILER_FLAG $<$<CONFIG:DEBUG>:${ARM_COMPUTE_CODE_COVERAGE_COMPILER_FLAG}>)
90+
list(APPEND ARM_COMPUTE_LINKER_FLAGS $<$<CONFIG:DEBUG>:${ARM_COMPUTE_CODE_COVERAGE_LINKER_FLAG}>)
91+
endif()
92+
93+
set(
94+
ARM_COMPUTE_LINK_LIBS
95+
$<$<BOOL:${ARM_COMPUTE_ENABLE_OPENMP}>:OpenMP::OpenMP_CXX>
96+
$<$<BOOL:${ARM_COMPUTE_ENABLE_OPENMP}>:OpenMP::OpenMP_C>
97+
)
98+
99+
if(ARM_COMPUTE_USE_LIBCXX)
100+
list(APPEND ARM_COMPUTE_CCXX_FLAGS ${ARM_COMPUTE_LIBCXX_COMPILER_FLAG})
101+
list(APPEND ARM_COMPUTE_LINKER_FLAGS ${ARM_COMPUTE_LIBCXX_LINKER_FLAG})
102+
endif()
103+
104+
if(ARM_COMPUTE_USE_LLD)
105+
list(APPEND ARM_COMPUTE_LINKER_FLAGS ${ARM_COMPUTE_LLD_LINKER_FLAGS})
106+
endif()
107+
108+
set(
109+
ARM_COMPUTE_COMMON_CCXX_FLAGS
110+
${ARM_COMPUTE_CCXX_FLAGS}
111+
${ARM_COMPUTE_CCXX_WARNING_FLAGS}
112+
${ARM_COMPUTE_ASAN_COMPILER_FLAG}
113+
${ARM_COMPUTE_CODE_COVERAGE_COMPILER_FLAG}
114+
)
115+
116+
set(
117+
ARM_COMPUTE_COMMON_CCXX_FLAGS
118+
${ARM_COMPUTE_CCXX_FLAGS}
119+
${ARM_COMPUTE_CCXX_WARNING_FLAGS}
120+
${ARM_COMPUTE_ASAN_COMPILER_FLAG}
121+
${ARM_COMPUTE_CODE_COVERAGE_COMPILER_FLAG}
122+
)
123+
124+
# Add -march to arch values.
125+
string(PREPEND ARM_COMPUTE_ARCH -march=)
126+
string(PREPEND ARM_COMPUTE_CORE_FP16_ARCH -march=)
127+
string(PREPEND ARM_COMPUTE_SVE_ARCH -march=)
128+
string(PREPEND ARM_COMPUTE_SVE2_ARCH -march=)
129+
130+
# Remove any CMake additions so we have clean build line.
131+
set(CMAKE_CXX_FLAGS "" CACHE STRING "" FORCE)
132+
set(CMAKE_CXX_FLAGS_INIT "" CACHE STRING "" FORCE)
133+
set(CMAKE_CXX_FLAGS_DEBUG "" CACHE STRING "" FORCE)
134+
set(CMAKE_CXX_FLAGS_RELEASE "" CACHE STRING "" FORCE)

cmake/toolchains/aarch64_linux_toolchain.cmake renamed to cmake/configurations.cmake

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright (c) 2023, 2025 Arm Limited.
1+
# Copyright (c) 2025 Arm Limited.
22
#
33
# SPDX-License-Identifier: MIT
44
#
@@ -20,8 +20,19 @@
2020
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2121
# SOFTWARE.
2222

23-
set(CMAKE_SYSTEM_NAME Linux)
24-
set(CMAKE_SYSTEM_PROCESSOR aarch64)
23+
# * For multiconfig generators, we only do debug and release builds.
24+
if(CMAKE_CONFIGURATION_TYPES)
25+
set(
26+
CMAKE_CONFIGURATION_TYPES "Release;Debug"
27+
CACHE STRING "Allowed project configurations" FORCE
28+
)
2529

26-
set(CMAKE_C_COMPILER gcc)
27-
set(CMAKE_CXX_COMPILER g++)
30+
# * Default for single config build system is release.
31+
elseif(NOT CMAKE_BUILD_TYPE)
32+
set(CMAKE_BUILD_TYPE "Release")
33+
message("CMAKE_BUILD_TYPE not specified. Assuming Release.")
34+
35+
# * Single config generators are restricted to debug and release builds.
36+
elseif(NOT CMAKE_BUILD_TYPE STREQUAL "Debug" AND NOT CMAKE_BUILD_TYPE STREQUAL "Release")
37+
message(FATAL_ERROR "Only Debug and Release build configurations are supported.")
38+
endif()
File renamed without changes.

0 commit comments

Comments
 (0)