aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJakub Sujak <jakub.sujak@arm.com>2023-07-05 17:30:02 +0100
committerJakub Sujak <jakub.sujak@arm.com>2023-07-06 15:22:08 +0000
commite86f992d26a79cad76244c4444d113e45afa9b88 (patch)
tree4d02dae037303678123958d3b237fb5d66a513c6
parent2ae536a6ff4e7547c3c8d5fc2be8b7e815ca5f3d (diff)
downloadComputeLibrary-e86f992d26a79cad76244c4444d113e45afa9b88.tar.gz
Pack CKW objects into Compute Library archive
Previously, building the `arm_compute-static` archive would fail the linking stage due to the Compute Kernel Writer (CKW) symbols not being correctly included. We fix this issue by collecting the built CKW objects and packing them into the Compute Library archive during SCons build time. Compiling the shared library remains unchanged, and still statically links against CKW. Resolves: COMPMID-6342 Change-Id: I841ed7379652fbede6afe9e90a98202656683086 Signed-off-by: Jakub Sujak <jakub.sujak@arm.com> Reviewed-on: https://review.mlplatform.org/c/ml/ComputeLibrary/+/9873 Reviewed-by: SiCong Li <sicong.li@arm.com> Reviewed-by: Viet-Hoa Do <viet-hoa.do@arm.com> Comments-Addressed: Arm Jenkins <bsgcomp@arm.com> Tested-by: Arm Jenkins <bsgcomp@arm.com> Benchmark: Arm Jenkins <bsgcomp@arm.com>
-rw-r--r--SConscript45
-rw-r--r--SConstruct6
-rw-r--r--compute_kernel_writer/CMakeLists.txt2
-rw-r--r--compute_kernel_writer/README.md1
-rw-r--r--compute_kernel_writer/prototype/CMakeLists.txt2
5 files changed, 45 insertions, 11 deletions
diff --git a/SConscript b/SConscript
index 5504d48e07..ad67701bae 100644
--- a/SConscript
+++ b/SConscript
@@ -56,8 +56,6 @@ def build_bootcode_objs(sources):
return obj
-
-
# @brief Create a list of object from a given file list.
#
# @param arch_info A dictionary represents the architecture info such as the
@@ -120,6 +118,24 @@ def build_lib_objects():
return lib_static_objs, lib_shared_objs
+# The built-in SCons Glob() method does not support recursive searching of directories, thus we implement our own:
+def recursive_glob(root_dir, pattern):
+ files = []
+ regex = re.compile(pattern)
+
+ for dirpath, _, filenames in os.walk(root_dir):
+ for f in filenames:
+ f = os.path.join(dirpath, f)
+ if regex.match(f):
+ files.append(f)
+
+ return files
+
+
+def get_ckw_obj_list():
+ cmake_obj_dir = os.path.abspath("prototype/CMakeFiles/ckw_prototype.dir/src")
+ return recursive_glob(root_dir=cmake_obj_dir, pattern=".*.o")
+
def build_library(name, build_env, sources, static=False, libs=[]):
cloned_build_env = build_env.Clone()
@@ -127,12 +143,25 @@ def build_library(name, build_env, sources, static=False, libs=[]):
cloned_build_env["LINKFLAGS"].remove('-pie')
cloned_build_env["LINKFLAGS"].remove('-static-libstdc++')
- if env['experimental_dynamic_fusion']:
- libs.append('libckw_prototype.a')
-
+ # -- Static Library --
if static:
- obj = cloned_build_env.StaticLibrary(name, source=sources, LIBS = arm_compute_env["LIBS"] + libs)
+ # Recreate the list to avoid mutating the original
+ static_sources = list(sources)
+
+ # Dynamic Fusion has a direct dependency on the Compute Kernel Writer (CKW) subproject, therefore we collect the
+ # built CKW objects to pack into the Compute Library archive.
+ if env['experimental_dynamic_fusion'] and name == "arm_compute-static":
+ static_sources += get_ckw_obj_list()
+
+ obj = cloned_build_env.StaticLibrary(name, source=static_sources, LIBS=arm_compute_env["LIBS"] + libs)
+
+ # -- Shared Library --
else:
+ # Always statically link Compute Library against CKW
+ if env['experimental_dynamic_fusion'] and name == "arm_compute":
+ libs.append('libckw_prototype.a')
+
+ # Add shared library versioning
if env['set_soname']:
obj = cloned_build_env.SharedLibrary(name, source=sources, SHLIBVERSION = SONAME_VERSION, LIBS = arm_compute_env["LIBS"] + libs)
else:
@@ -560,7 +589,7 @@ custom_operators = []
custom_types = []
custom_layouts = []
-use_custom_ops = env['high_priority'] or env['build_config'];
+use_custom_ops = env['high_priority'] or env['build_config']
if env['high_priority']:
custom_operators = filelist['high_priority']
@@ -695,7 +724,7 @@ arm_compute_graph_env = arm_compute_env.Clone()
# Build graph libraries
arm_compute_graph_env.Append(CXXFLAGS = ['-Wno-redundant-move', '-Wno-pessimizing-move'])
-arm_compute_graph_a = build_library('arm_compute_graph-static', arm_compute_graph_env, graph_files, static=True, libs = [ arm_compute_a ])
+arm_compute_graph_a = build_library('arm_compute_graph-static', arm_compute_graph_env, graph_files, static=True)
Export('arm_compute_graph_a')
if env['os'] != 'bare_metal' and not env['standalone']:
diff --git a/SConstruct b/SConstruct
index 4ab9fdd66a..4480c710d3 100644
--- a/SConstruct
+++ b/SConstruct
@@ -453,9 +453,9 @@ if env['experimental_dynamic_fusion']:
# Configure CKW static objects with -fPIC (CMAKE_POSITION_INDEPENDENT_CODE) option to enable linking statically to ACL
CKW_CMAKE_CONFIGURE_STATIC = CKW_CMAKE_CMD + "-DBUILD_SHARED_LIBS=OFF -DCMAKE_POSITION_INDEPENDENT_CODE=ON"
- CKW_CMAKE_BUILD = "cmake --build {CKW_BUILD_DIR} -j{NUM_JOBS}".format(CKW_BUILD_DIR=CKW_BUILD_DIR,
- NUM_JOBS=GetOption('num_jobs')
- )
+ CKW_CMAKE_BUILD = "cmake --build {CKW_BUILD_DIR} --target ckw_prototype -j{NUM_JOBS}".format(CKW_BUILD_DIR=CKW_BUILD_DIR,
+ NUM_JOBS=GetOption('num_jobs')
+ )
# Build Compute Kernel Writer Static Library
subprocess.check_call(CKW_CMAKE_CONFIGURE_STATIC, stderr=subprocess.STDOUT, shell=True)
diff --git a/compute_kernel_writer/CMakeLists.txt b/compute_kernel_writer/CMakeLists.txt
index f739824402..3bc2aeda63 100644
--- a/compute_kernel_writer/CMakeLists.txt
+++ b/compute_kernel_writer/CMakeLists.txt
@@ -43,6 +43,7 @@ message(STATUS "${CMAKE_PROJECT_NAME} ${CMAKE_PROJECT_VERSION}")
option(CKW_ENABLE_OPENCL "Enable OpenCL code generation" OFF)
option(CKW_ENABLE_ASSERTS "Enable assertions. Always enabled in Debug builds" OFF)
option(CKW_BUILD_TESTING "Build the Compute Kernel Writer validation test suite" OFF)
+option(CKW_BUILD_PROTOTYPE "Build the prototype implementation of kernel writer." OFF)
option(CKW_CCACHE "Use compiler cache for faster recompilation" OFF)
#---------------------------------------------------------------------
@@ -105,6 +106,7 @@ target_compile_options(ckw
# Set CMAKE_CXX_FLAGS last so user can overwrite options
${CMAKE_CXX_FLAGS}
PRIVATE
+ # Always optimize for binary size
$<$<CONFIG:Release>:-Os>
)
diff --git a/compute_kernel_writer/README.md b/compute_kernel_writer/README.md
index 8a24fe20ec..9a920b7882 100644
--- a/compute_kernel_writer/README.md
+++ b/compute_kernel_writer/README.md
@@ -82,5 +82,6 @@ This project can be configured with the following build options. Enable options
| CKW_ENABLE_OPENCL | Enable OpenCL code generation. |
| CKW_ENABLE_ASSERTS | Enable assertions. Always enabled for Debug builds. |
| CKW_BUILD_TESTING | Build the validation test suite. |
+| CKW_BUILD_PROTOTYPE | Build the prototype implementation. |
| CKW_CCACHE | Use compiler cache for faster recompilation. |
| CMAKE_TOOLCHAIN_FILE | When cross-compiling, set this variable to the path of the CMake toolchain file. |
diff --git a/compute_kernel_writer/prototype/CMakeLists.txt b/compute_kernel_writer/prototype/CMakeLists.txt
index 84436a95d6..0def9eacf7 100644
--- a/compute_kernel_writer/prototype/CMakeLists.txt
+++ b/compute_kernel_writer/prototype/CMakeLists.txt
@@ -43,6 +43,8 @@ target_compile_options(ckw_prototype
"$<$<CONFIG:Debug>:${CKW_ASSERTS_OPTS}>"
"$<$<BOOL:${CKW_ASSERTS}>:${CKW_ASSERTS_OPTS}>"
${CMAKE_CXX_FLAGS}
+ PRIVATE
+ $<$<CONFIG:Release>:-Os>
)
target_compile_definitions(ckw_prototype PUBLIC