diff options
Diffstat (limited to 'SConstruct')
-rw-r--r-- | SConstruct | 516 |
1 files changed, 406 insertions, 110 deletions
diff --git a/SConstruct b/SConstruct index 4be00f3070..bad85e503d 100644 --- a/SConstruct +++ b/SConstruct @@ -1,4 +1,6 @@ -# Copyright (c) 2016, 2017 Arm Limited. +# -*- coding: utf-8 -*- + +# Copyright (c) 2016-2024 Arm Limited. # # SPDX-License-Identifier: MIT # @@ -21,6 +23,7 @@ # SOFTWARE. import SCons +import json import os import subprocess @@ -37,45 +40,122 @@ def version_at_least(version, required): return True +def read_build_config_json(build_config): + build_config_contents = {} + custom_types = [] + custom_layouts = [] + if os.path.isfile(build_config): + with open(build_config) as f: + try: + build_config_contents = json.load(f) + except: + print("Warning: Build configuration file is of invalid JSON format!") + else: + try: + build_config_contents = json.loads(build_config) + except: + print("Warning: Build configuration string is of invalid JSON format!") + if build_config_contents: + custom_types = build_config_contents.get("data_types", []) + custom_layouts = build_config_contents.get("data_layouts", []) + return custom_types, custom_layouts + +def update_data_type_layout_flags(env, data_types, data_layouts): + # Manage data-types + if env['multi_isa']: + if any(i in data_types for i in ['all', 'fp16']): + env.Append(CXXFLAGS = ['-DENABLE_FP16_KERNELS', '-DARM_COMPUTE_ENABLE_FP16']) + else: + if not 'v8a' in env['arch'] and not 'v7a' in env['arch'] and not 'armv8r64' in env['arch']: + if any(i in data_types for i in ['all', 'fp16']): + env.Append(CXXFLAGS = ['-DENABLE_FP16_KERNELS','-DARM_COMPUTE_ENABLE_FP16']) + + if any(i in data_types for i in ['all', 'fp32']): + env.Append(CXXFLAGS = ['-DENABLE_FP32_KERNELS']) + if any(i in data_types for i in ['all', 'qasymm8']): + env.Append(CXXFLAGS = ['-DENABLE_QASYMM8_KERNELS']) + if any(i in data_types for i in ['all', 'qasymm8_signed']): + env.Append(CXXFLAGS = ['-DENABLE_QASYMM8_SIGNED_KERNELS']) + if any(i in data_types for i in ['all', 'qsymm16']): + env.Append(CXXFLAGS = ['-DENABLE_QSYMM16_KERNELS']) + if any(i in data_types for i in ['all', 'integer']): + env.Append(CXXFLAGS = ['-DENABLE_INTEGER_KERNELS']) + + # Manage data-layouts + if any(i in data_layouts for i in ['all', 'nhwc']): + env.Append(CXXFLAGS = ['-DENABLE_NHWC_KERNELS']) + if any(i in data_layouts for i in ['all', 'nchw']): + env.Append(CXXFLAGS = ['-DENABLE_NCHW_KERNELS']) + + return env + + vars = Variables("scons") vars.AddVariables( BoolVariable("debug", "Debug", False), BoolVariable("asserts", "Enable asserts (this flag is forced to 1 for debug=1)", False), - BoolVariable("logging", "Logging (this flag is forced to 1 for debug=1)", False), - EnumVariable("arch", "Target Architecture", "armv7a", - allowed_values=("armv7a", "arm64-v8a", "arm64-v8.2-a", "arm64-v8.2-a-sve", "x86_32", "x86_64", - "armv8a", "armv8.2-a", "armv8.2-a-sve", "armv8.6-a", "armv8.6-a-sve", "x86")), + BoolVariable("logging", "Enable Logging", False), + EnumVariable("arch", "Target Architecture. The x86_32 and x86_64 targets can only be used with neon=0 and opencl=1.", "armv7a", + allowed_values=("armv7a", "armv7a-hf", "arm64-v8a", "arm64-v8.2-a", "arm64-v8.2-a-sve", "arm64-v8.2-a-sve2", "x86_32", "x86_64", + "armv8a", "armv8.2-a", "armv8.2-a-sve", "armv8.6-a", "armv8.6-a-sve", "armv8.6-a-sve2", "armv8.6-a-sve2-sme2", "armv8r64", "x86")), EnumVariable("estate", "Execution State", "auto", allowed_values=("auto", "32", "64")), - EnumVariable("os", "Target OS", "linux", allowed_values=("linux", "android", "tizen", "bare_metal")), - EnumVariable("build", "Build type", "cross_compile", allowed_values=("native", "cross_compile", "embed_only")), + EnumVariable("os", "Target OS. With bare metal selected, only Arm® Neon™ (not OpenCL) can be used, static libraries get built and Neon™'s multi-threading support is disabled.", "linux", allowed_values=("linux", "android", "tizen", "macos", "bare_metal", "openbsd","windows")), + EnumVariable("build", "Either build directly on your device (native) or cross compile from your desktop machine (cross-compile). In both cases make sure the compiler is available in your path.", "cross_compile", allowed_values=("native", "cross_compile", "embed_only")), BoolVariable("examples", "Build example programs", True), BoolVariable("gemm_tuner", "Build gemm_tuner programs", True), BoolVariable("Werror", "Enable/disable the -Werror compilation flag", True), + BoolVariable("multi_isa", "Build Multi ISA binary version of library. Works for armv8a without the support for FP16 vector arithmetic. Use armv8.2-a or beyond to enable FP16 vector arithmetic support", False), BoolVariable("standalone", "Builds the tests as standalone executables, links statically with libgcc, libstdc++ and libarm_compute", False), BoolVariable("opencl", "Enable OpenCL support", True), - BoolVariable("neon", "Enable Neon support", False), - BoolVariable("gles_compute", "Enable OpenGL ES Compute Shader support", False), - BoolVariable("embed_kernels", "Embed OpenCL kernels and OpenGL ES compute shaders in library binary", True), - BoolVariable("set_soname", "Set the library's soname and shlibversion (requires SCons 2.4 or above)", False), - BoolVariable("tracing", "Enable runtime tracing", False), - BoolVariable("openmp", "Enable OpenMP backend", False), + BoolVariable("neon", "Enable Arm® Neon™ support", False), + BoolVariable("embed_kernels", "Enable if you want the OpenCL kernels to be built in the library's binaries instead of being read from separate '.cl' / '.cs' files. If embed_kernels is set to 0 then the application can set the path to the folder containing the OpenCL kernel files by calling CLKernelLibrary::init(). By default the path is set to './cl_kernels'.", True), + BoolVariable("compress_kernels", "Compress embedded OpenCL kernels in library binary using zlib. Useful for reducing the binary size. embed_kernels should be enabled", False), + BoolVariable("set_soname", "If enabled the library will contain a SONAME and SHLIBVERSION and some symlinks will automatically be created between the objects. (requires SCons 2.4 or above)", False), + BoolVariable("openmp", "Enable OpenMP backend. Only works when building with g++ and not clang++", False), BoolVariable("cppthreads", "Enable C++11 threads backend", True), PathVariable("build_dir", "Specify sub-folder for the build", ".", PathVariable.PathAccept), PathVariable("install_dir", "Specify sub-folder for the install", "", PathVariable.PathAccept), BoolVariable("exceptions", "Enable/disable C++ exception support", True), + BoolVariable("high_priority", "Generate a library containing only the high priority operators", False), PathVariable("linker_script", "Use an external linker script", "", PathVariable.PathAccept), - #FIXME Remove before release (And remove all references to INTERNAL_ONLY) - BoolVariable("internal_only", "Enable ARM internal only tests", False), + PathVariable("external_tests_dir", """Add examples, benchmarks and tests to the tests suite from an external path. In order to use this option, the external tests directory must have the following structure: + EXTERNAL_TESTS_DIR: + └── tests + ├── benchmark + │ ├── CL + │ ├── datasets + │ ├── fixtures + │ └── Neon + └── validation + ├── CL + ├── datasets + ├── fixtures + └── Neon\n""", "", PathVariable.PathAccept), + BoolVariable("experimental_dynamic_fusion", "Build the experimental dynamic fusion files. This option also enables opencl=1 on which it has a direct dependency.", False), + BoolVariable("fixed_format_kernels", "Enable fixed format kernels for GEMM", False), + BoolVariable("mapfile", "Generate a map file", False), ListVariable("custom_options", "Custom options that can be used to turn on/off features", "none", ["disable_mmla_fp"]), - ListVariable("data_type_support", "Enable a list of data types to support", "all", ["qasymm8", "qasymm8_signed", "qsymm16", "fp16", "fp32"]), - ("toolchain_prefix", "Override the toolchain prefix", ""), - ("compiler_prefix", "Override the compiler prefix", ""), + ListVariable("data_type_support", "Enable a list of data types to support", "all", ["qasymm8", "qasymm8_signed", "qsymm16", "fp16", "fp32", "integer"]), + ListVariable("data_layout_support", "Enable a list of data layout to support", "all", ["nhwc", "nchw"]), + ("toolchain_prefix", "Override the toolchain prefix; used by all toolchain components: compilers, linker, assembler etc. If unspecified, use default(auto) prefixes; if passed an empty string '' prefixes would be disabled", "auto"), + ("compiler_prefix", "Override the compiler prefix; used by just compilers (CC,CXX); further overrides toolchain_prefix for compilers; this is for when the compiler prefixes are different from that of the linkers, archivers etc. If unspecified, this is the same as toolchain_prefix; if passed an empty string '' prefixes would be disabled", "auto"), + BoolVariable("address_sanitizer", "Enable AddressSanitizer", False), + BoolVariable("undefined_sanitizer", "Enable UndefinedBehaviorSanitizer", False), + BoolVariable("thread_sanitizer", "Enable ThreadSanitizer", False), ("extra_cxx_flags", "Extra CXX flags to be appended to the build command", ""), ("extra_link_flags", "Extra LD flags to be appended to the build command", ""), - ("compiler_cache", "Command to prefix to the C and C++ compiler (e.g ccache)", "") + ("compiler_cache", "Command to prefix to the C and C++ compiler (e.g ccache)", ""), + ("specs_file", "Specs file to use (e.g. rdimon.specs)", ""), + ("build_config", "Operator/Data-type/Data-layout configuration to use for tailored ComputeLibrary builds. Can be a JSON file or a JSON formatted string", "") ) -env = Environment(platform="posix", variables=vars, ENV = os.environ) +if version_at_least(SCons.__version__, "4.0"): + vars.Add(BoolVariable("export_compile_commands", "Export compile_commands.json file.", False)) + + +env = Environment(variables=vars, ENV = os.environ) + + build_path = env['build_dir'] # If build_dir is a relative path then add a #build/ prefix: if not env['build_dir'].startswith('/'): @@ -89,7 +169,7 @@ install_path = env['install_dir'] if not env['install_dir'].startswith('/') and install_path != "": install_path = "%s/%s" % (build_path, install_path) -env.Append(LIBPATH = [build_path]) +env.Append(LIBPATH = [build_path, os.path.join(build_path, "")]) Export('env') Export('vars') @@ -113,6 +193,14 @@ Export('install_bin') Help(vars.GenerateHelpText(env)) +# Export compile_commands.json file +if env.get("export_compile_commands", False): + env.Tool("compilation_db") + env.CompilationDatabase("%s/compile_commands.json" % build_path) + +if 'armv7a' in env['arch'] and env['os'] == 'android': + print("WARNING: armv7a on Android is no longer maintained") + if env['linker_script'] and env['os'] != 'bare_metal': print("Linker script is only supported for bare_metal builds") Exit(1) @@ -122,7 +210,7 @@ if env['build'] == "embed_only": Return() if env['neon'] and 'x86' in env['arch']: - print("Cannot compile NEON for x86") + print("Cannot compile Arm® Neon™ for x86") Exit(1) if env['set_soname'] and not version_at_least(SCons.__version__, "2.4"): @@ -135,24 +223,42 @@ if env['os'] == 'bare_metal': print("ERROR: OpenMP and C++11 threads not supported in bare_metal. Use cppthreads=0 openmp=0") Exit(1) +if env['experimental_dynamic_fusion']: + # Dynamic Fusion on GPU has a direct dependency on OpenCL and Compute Kernel Writer + env['opencl'] = 1 + +if env['opencl'] and env['embed_kernels'] and env['compress_kernels'] and env['os'] not in ['android']: + print("Compressed kernels are supported only for android builds") + Exit(1) + if not env['exceptions']: - if env['opencl'] or env['gles_compute']: - print("ERROR: OpenCL and GLES are not supported when building without exceptions. Use opencl=0 gles_compute=0") + if env['opencl']: + print("ERROR: OpenCL is not supported when building without exceptions. Use opencl=0") Exit(1) env.Append(CPPDEFINES = ['ARM_COMPUTE_EXCEPTIONS_DISABLED']) env.Append(CXXFLAGS = ['-fno-exceptions']) -env.Append(CXXFLAGS = ['-Wall','-DARCH_ARM', - '-Wextra','-pedantic','-Wdisabled-optimization','-Wformat=2', +env.Append(CXXFLAGS = ['-DARCH_ARM', + '-Wextra','-Wdisabled-optimization','-Wformat=2', '-Winit-self','-Wstrict-overflow=2','-Wswitch-default', - '-std=gnu++11','-Woverloaded-virtual', '-Wformat-security', + '-Woverloaded-virtual', '-Wformat-security', '-Wctor-dtor-privacy','-Wsign-promo','-Weffc++','-Wno-overlength-strings']) -env.Append(CPPDEFINES = ['_GLIBCXX_USE_NANOSLEEP']) +if not 'windows' in env['os']: + env.Append(CXXFLAGS = ['-Wall','-std=c++14', '-pedantic' ]) + -default_cpp_compiler = 'g++' if env['os'] != 'android' else 'clang++' -default_c_compiler = 'gcc' if env['os'] != 'android' else 'clang' +cpp_tool = {'linux': 'g++', 'android' : 'clang++', + 'tizen': 'g++', 'macos':'clang++', + 'bare_metal':'g++', 'openbsd':'g++','windows':'clang-cl'} + +c_tool = {'linux':'gcc', 'android': 'clang', 'tizen':'gcc', + 'macos':'clang','bare_metal':'gcc', + 'openbsd':'gcc','windows':'clang-cl'} + +default_cpp_compiler = cpp_tool[env['os']] +default_c_compiler = c_tool[env['os']] cpp_compiler = os.environ.get('CXX', default_cpp_compiler) c_compiler = os.environ.get('CC', default_c_compiler) @@ -163,17 +269,17 @@ if 'clang++' in cpp_compiler: env.Append(CXXFLAGS = ['-Wno-vla-extension']) elif 'armclang' in cpp_compiler: pass -else: - env.Append(CXXFLAGS = ['-Wlogical-op','-Wnoexcept','-Wstrict-null-sentinel']) +elif not 'windows' in env['os']: + env.Append(CXXFLAGS = ['-Wlogical-op','-Wnoexcept','-Wstrict-null-sentinel','-Wno-misleading-indentation']) + +if cpp_compiler == 'g++': + # Don't strip comments that could include markers + env.Append(CXXFLAGS = ['-C']) if env['cppthreads']: env.Append(CPPDEFINES = [('ARM_COMPUTE_CPP_SCHEDULER', 1)]) if env['openmp']: - if 'clang++' in cpp_compiler: - print( "Clang does not support OpenMP. Use scheduler=cpp.") - Exit(1) - env.Append(CPPDEFINES = [('ARM_COMPUTE_OPENMP_SCHEDULER', 1)]) env.Append(CXXFLAGS = ['-fopenmp']) env.Append(LINKFLAGS = ['-fopenmp']) @@ -193,78 +299,183 @@ if 'v7a' in env['estate'] and env['estate'] == '64': print("ERROR: armv7a architecture has only 32-bit execution state") Exit(1) +env.Append(CPPDEFINES = ['ENABLE_NEON', 'ARM_COMPUTE_ENABLE_NEON']) + +if 'sve' in env['arch']: + env.Append(CPPDEFINES = ['ENABLE_SVE', 'ARM_COMPUTE_ENABLE_SVE']) + if 'sve2' in env['arch']: + env.Append(CPPDEFINES = ['ARM_COMPUTE_ENABLE_SVE2']) + +if 'sme' in env['arch']: + env.Append(CPPDEFINES = ['ENABLE_SME', 'ARM_COMPUTE_ENABLE_SME']) + if 'sme2' in env['arch']: + env.Append(CPPDEFINES = ['ARM_COMPUTE_ENABLE_SME2']) + # Add architecture specific flags -prefix = "" -if 'v7a' in env['arch']: - env.Append(CXXFLAGS = ['-march=armv7-a', '-mthumb', '-mfpu=neon']) - if env['os'] == 'android' or env['os'] == 'tizen': - env.Append(CXXFLAGS = ['-mfloat-abi=softfp']) +if env['multi_isa']: + # assert arch version is v8 + if 'v8' not in env['arch']: + print("Currently Multi ISA binary is only supported for arm v8 family") + Exit(1) + + if 'v8a' in env['arch']: + env.Append(CXXFLAGS = ['-march=armv8-a']) else: - env.Append(CXXFLAGS = ['-mfloat-abi=hard']) -elif 'v8' in env['arch']: - if 'sve' in env['arch']: - env.Append(CXXFLAGS = ['-march=armv8.2-a+sve+fp16+dotprod']) - elif 'v8.2-a' in env['arch']: + if 'v8.6-a' in env['arch']: + if "disable_mmla_fp" not in env['custom_options']: + env.Append(CPPDEFINES = ['ARM_COMPUTE_ENABLE_SVEF32MM']) + env.Append(CXXFLAGS = ['-march=armv8.2-a+fp16']) # explicitly enable fp16 extension otherwise __ARM_FEATURE_FP16_VECTOR_ARITHMETIC is undefined - else: - env.Append(CXXFLAGS = ['-march=armv8-a']) - if 'v8.6-a' in env['arch']: - env.Append(CPPDEFINES = ['MMLA_INT8', 'V8P6', 'V8P6_BF', 'ARM_COMPUTE_FORCE_BF16']) - if "disable_mmla_fp" not in env['custom_options']: - env.Append(CPPDEFINES = ['MMLA_FP32']) +else: # NONE "multi_isa" builds -elif 'x86' in env['arch']: - if env['estate'] == '32': - env.Append(CCFLAGS = ['-m32']) - env.Append(LINKFLAGS = ['-m32']) - else: - env.Append(CXXFLAGS = ['-fPIC']) - env.Append(CCFLAGS = ['-m64']) - env.Append(LINKFLAGS = ['-m64']) + if 'v7a' in env['arch']: + env.Append(CXXFLAGS = ['-march=armv7-a', '-mthumb', '-mfpu=neon']) + if (env['os'] == 'android' or env['os'] == 'tizen') and not 'hf' in env['arch']: + env.Append(CXXFLAGS = ['-mfloat-abi=softfp']) + else: + env.Append(CXXFLAGS = ['-mfloat-abi=hard']) + elif 'v8.6-a' in env['arch']: + if 'armv8.6-a-sve2' in env['arch']: + env.Append(CXXFLAGS = ['-march=armv8.6-a+sve2']) + elif 'armv8.6-a-sve' == env['arch']: + env.Append(CXXFLAGS = ['-march=armv8.6-a+sve']) + elif 'armv8.6-a' == env['arch']: + env.Append(CXXFLAGS = ['-march=armv8.6-a+fp16']) + + env.Append(CPPDEFINES = ['ARM_COMPUTE_ENABLE_I8MM', 'ARM_COMPUTE_ENABLE_BF16','ARM_COMPUTE_ENABLE_FP16']) + if "disable_mmla_fp" not in env['custom_options']: + env.Append(CPPDEFINES = ['ARM_COMPUTE_ENABLE_SVEF32MM']) + elif 'v8' in env['arch']: + # Preserve the V8 archs for non-multi-ISA variants + if 'sve2' in env['arch']: + env.Append(CXXFLAGS = ['-march=armv8.2-a+sve2+fp16+dotprod']) + elif 'sve' in env['arch']: + env.Append(CXXFLAGS = ['-march=armv8.2-a+sve+fp16+dotprod']) + elif 'armv8r64' in env['arch']: + env.Append(CXXFLAGS = ['-march=armv8.4-a']) + elif 'v8.' in env['arch']: + env.Append(CXXFLAGS = ['-march=armv8.2-a+fp16']) # explicitly enable fp16 extension otherwise __ARM_FEATURE_FP16_VECTOR_ARITHMETIC is undefined + else: + env.Append(CXXFLAGS = ['-march=armv8-a']) + + if 'v8.' in env['arch']: + env.Append(CPPDEFINES = ['ARM_COMPUTE_ENABLE_FP16']) + + elif 'x86' in env['arch']: + if env['estate'] == '32': + env.Append(CCFLAGS = ['-m32']) + env.Append(LINKFLAGS = ['-m32']) + else: + env.Append(CXXFLAGS = ['-fPIC']) + env.Append(CCFLAGS = ['-m64']) + env.Append(LINKFLAGS = ['-m64']) # Define toolchain -prefix = "" +# The reason why we distinguish toolchain_prefix from compiler_prefix is for cases where the linkers/archivers use a +# different prefix than the compilers. An example is the NDK r20 toolchain +auto_toolchain_prefix = "" if 'x86' not in env['arch']: if env['estate'] == '32': if env['os'] == 'linux': - prefix = "arm-linux-gnueabihf-" if 'v7' in env['arch'] else "armv8l-linux-gnueabihf-" + auto_toolchain_prefix = "arm-linux-gnueabihf-" if 'v7' in env['arch'] else "armv8l-linux-gnueabihf-" elif env['os'] == 'bare_metal': - prefix = "arm-eabi-" + auto_toolchain_prefix = "arm-eabi-" elif env['os'] == 'android': - prefix = "arm-linux-androideabi-" + auto_toolchain_prefix = "arm-linux-androideabi-" elif env['os'] == 'tizen': - prefix = "armv7l-tizen-linux-gnueabi-" + auto_toolchain_prefix = "armv7l-tizen-linux-gnueabi-" elif env['estate'] == '64' and 'v8' in env['arch']: if env['os'] == 'linux': - prefix = "aarch64-linux-gnu-" + auto_toolchain_prefix = "aarch64-linux-gnu-" elif env['os'] == 'bare_metal': - prefix = "aarch64-elf-" + auto_toolchain_prefix = "aarch64-elf-" elif env['os'] == 'android': - prefix = "aarch64-linux-android-" + auto_toolchain_prefix = "aarch64-linux-android-" elif env['os'] == 'tizen': - prefix = "aarch64-tizen-linux-gnu-" + auto_toolchain_prefix = "aarch64-tizen-linux-gnu-" -if env['build'] == 'native': - prefix = "" - -if env["toolchain_prefix"] != "": - prefix = env["toolchain_prefix"] +if env['build'] == 'native' or env["toolchain_prefix"] == "": + toolchain_prefix = "" +elif env["toolchain_prefix"] == "auto": + toolchain_prefix = auto_toolchain_prefix +else: + toolchain_prefix = env["toolchain_prefix"] -compiler_prefix = prefix -if env["compiler_prefix"] != "": +if env['build'] == 'native' or env["compiler_prefix"] == "": + compiler_prefix = "" +elif env["compiler_prefix"] == "auto": + compiler_prefix = toolchain_prefix +else: compiler_prefix = env["compiler_prefix"] env['CC'] = env['compiler_cache']+ " " + compiler_prefix + c_compiler env['CXX'] = env['compiler_cache']+ " " + compiler_prefix + cpp_compiler -env['LD'] = prefix + "ld" -env['AS'] = prefix + "as" -env['AR'] = prefix + "ar" -env['RANLIB'] = prefix + "ranlib" +env['LD'] = toolchain_prefix + "ld" +env['AS'] = toolchain_prefix + "as" + +if env['os'] == 'windows': + env['AR'] = "llvm-lib" + env['RANLIB'] = "llvm-ranlib" +else: + env['AR'] = toolchain_prefix + "ar" + +env['RANLIB'] = toolchain_prefix + "ranlib" + +print("Using compilers:") +print("CC", env['CC']) +print("CXX", env['CXX']) + +"""Build the Compute Kernel Writer subproject""" +if env['experimental_dynamic_fusion']: + # Strip ccache prefix from CC and CXX to obtain only the target triple + CKW_CC = env['CC'].replace(env['compiler_cache'] + " ", "") + CKW_CXX = env['CXX'].replace(env['compiler_cache'] + " ", "") + CKW_CCACHE = 1 if env['compiler_cache'] else 0 + + CKW_BUILD_TYPE = "Debug" if env['debug'] else "Release" + + CKW_ENABLE_OPENCL = env['opencl'] + CKW_ENABLE_ASSERTS = env['debug'] or env['asserts'] + + CKW_PROJECT_DIR = Dir('.').path + "/compute_kernel_writer" + CKW_INCLUDE_DIR = CKW_PROJECT_DIR + "/include" + CKW_BUILD_DIR = build_path.replace("#", "") + + CKW_CMAKE_CMD = "CC={CKW_CC} CXX={CKW_CXX} cmake -G \"Unix Makefiles\" " \ + "-S {CKW_PROJECT_DIR} -B {CKW_BUILD_DIR} " \ + "-DCMAKE_BUILD_TYPE={CKW_BUILD_TYPE} " \ + "-DCKW_ENABLE_OPENCL=ON " \ + "-DCKW_ENABLE_ASSERTS={CKW_ENABLE_ASSERTS} " \ + "-DCKW_CCACHE={CKW_CCACHE} ".format(CKW_CC=CKW_CC, + CKW_CXX=CKW_CXX, + CKW_PROJECT_DIR=CKW_PROJECT_DIR, + CKW_BUILD_DIR=CKW_BUILD_DIR, + CKW_BUILD_TYPE=CKW_BUILD_TYPE, + CKW_ENABLE_OPENCL=CKW_ENABLE_OPENCL, + CKW_ENABLE_ASSERTS=CKW_ENABLE_ASSERTS, + CKW_CCACHE=CKW_CCACHE + ) + + # 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} --target ckw -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) + subprocess.check_call(CKW_CMAKE_BUILD, stderr=subprocess.STDOUT, shell=True) + + # Let ACL know where to find CKW headers + env.Append(CPPPATH = CKW_INCLUDE_DIR) if not GetOption("help"): try: - compiler_ver = subprocess.check_output(env['CXX'].split() + ["-dumpversion"]).decode().strip() + if env['os'] == 'windows': + compiler_ver = subprocess.check_output("clang++ -dumpversion").decode().strip() + else: + compiler_ver = subprocess.check_output(env['CXX'].split() + ["-dumpversion"]).decode().strip() except OSError: print("ERROR: Compiler '%s' not found" % env['CXX']) Exit(1) @@ -276,7 +487,7 @@ if not GetOption("help"): print("GCC 6.2.1 or newer is required to compile armv8.2-a code") Exit(1) elif env['arch'] == 'arm64-v8a' and not version_at_least(compiler_ver, '4.9'): - print("GCC 4.9 or newer is required to compile NEON code for AArch64") + print("GCC 4.9 or newer is required to compile Arm® Neon™ code for AArch64") Exit(1) if version_at_least(compiler_ver, '6.1'): @@ -288,21 +499,48 @@ if not GetOption("help"): if not version_at_least(compiler_ver, '7.0.0') and env['os'] == 'bare_metal': env.Append(LINKFLAGS = ['-fstack-protector-strong']) -if env['data_type_support']: - if any(i in env['data_type_support'] for i in ['all', 'fp16']): - env.Append(CXXFLAGS = ['-DENABLE_FP16_KERNELS']) - if any(i in env['data_type_support'] for i in ['all', 'fp32']): - env.Append(CXXFLAGS = ['-DENABLE_FP32_KERNELS']) - if any(i in env['data_type_support'] for i in ['all', 'qasymm8']): - env.Append(CXXFLAGS = ['-DENABLE_QASYMM8_KERNELS']) - if any(i in env['data_type_support'] for i in ['all', 'qasymm8_signed']): - env.Append(CXXFLAGS = ['-DENABLE_QASYMM8_SIGNED_KERNELS']) - if any(i in env['data_type_support'] for i in ['all', 'qsymm16']): - env.Append(CXXFLAGS = ['-DENABLE_QSYMM16_KERNELS']) + # Add Android NDK toolchain specific flags + if 'clang++' in cpp_compiler and env['os'] == 'android': + # For NDK >= r21, clang 9 or above is used + if version_at_least(compiler_ver, '9.0.0'): + env['ndk_above_r21'] = True + + if env['openmp']: + env.Append(LINKFLAGS = ['-static-openmp']) + + # For NDK >= r23, clang 12 or above is used. This condition detects NDK < r23 + if not version_at_least(compiler_ver, '12.0.0'): + # System assembler is deprecated and integrated assembler is preferred since r23. + # However integrated assembler has always been suppressed for NDK < r23. + # Thus for backward compatibility, we include this flag only for NDK < r23 + env.Append(CXXFLAGS = ['-no-integrated-as']) + +if env['high_priority'] and env['build_config']: + print("The high priority library cannot be built in conjunction with a user-specified build configuration") + Exit(1) + +if not env['high_priority'] and not env['build_config']: + env.Append(CPPDEFINES = ['ARM_COMPUTE_GRAPH_ENABLED']) + +data_types = [] +data_layouts = [] + +# Set correct data types / layouts to build +if env['high_priority']: + data_types = ['all'] + data_layouts = ['all'] +elif env['build_config']: + data_types, data_layouts = read_build_config_json(env['build_config']) +else: + data_types = env['data_type_support'] + data_layouts = env['data_layout_support'] + +env = update_data_type_layout_flags(env, data_types, data_layouts) if env['standalone']: - env.Append(CXXFLAGS = ['-fPIC']) - env.Append(LINKFLAGS = ['-static-libgcc','-static-libstdc++']) + if not 'windows' in env['os']: + env.Append(CXXFLAGS = ['-fPIC']) + env.Append(LINKFLAGS = ['-static-libgcc','-static-libstdc++']) if env['Werror']: env.Append(CXXFLAGS = ['-Werror']) @@ -312,45 +550,91 @@ if env['os'] == 'android': env.Append(LINKFLAGS = ['-pie', '-static-libstdc++', '-ldl']) elif env['os'] == 'bare_metal': env.Append(LINKFLAGS = ['-static']) - env.Append(LINKFLAGS = ['-specs=rdimon.specs']) env.Append(CXXFLAGS = ['-fPIC']) + if env['specs_file'] == "": + env.Append(LINKFLAGS = ['-specs=rdimon.specs']) env.Append(CPPDEFINES = ['NO_MULTI_THREADING']) env.Append(CPPDEFINES = ['BARE_METAL']) if env['os'] == 'linux' and env['arch'] == 'armv7a': env.Append(CXXFLAGS = [ '-Wno-psabi' ]) +if env['os'] == 'windows': + env.Append(CXXFLAGS = [ '/std:c++14','/EHa']) + env.Append(CXXFLAGS = [ '-Wno-c++98-compat', '-Wno-covered-switch-default','-Wno-c++98-compat-pedantic']) + env.Append(CXXFLAGS = [ '-Wno-shorten-64-to-32', '-Wno-sign-conversion','-Wno-documentation']) + env.Append(CXXFLAGS = [ '-Wno-extra-semi-stmt', '-Wno-float-equal','-Wno-implicit-int-conversion']) + env.Append(CXXFLAGS = [ '-Wno-documentation-pedantic', '-Wno-extra-semi','-Wno-shadow-field-in-constructor']) + env.Append(CXXFLAGS = [ '-Wno-float-conversion', '-Wno-switch-enum','-Wno-comma']) + env.Append(CXXFLAGS = [ '-Wno-implicit-float-conversion', '-Wno-deprecated-declarations','-Wno-old-style-cast']) + env.Append(CXXFLAGS = [ '-Wno-zero-as-null-pointer-constant', '-Wno-inconsistent-missing-destructor-override']) + env.Append(CXXFLAGS = [ '-Wno-asm-operand-widths']) + + +if env['specs_file'] != "": + env.Append(LINKFLAGS = ['-specs='+env['specs_file']]) + +if env['neon']: + env.Append(CPPDEFINES = ['ARM_COMPUTE_CPU_ENABLED']) if env['opencl']: + env.Append(CPPDEFINES = ['ARM_COMPUTE_OPENCL_ENABLED']) if env['os'] in ['bare_metal'] or env['standalone']: print("Cannot link OpenCL statically, which is required for bare metal / standalone builds") Exit(1) -if env['gles_compute']: - if env['os'] in ['bare_metal'] or env['standalone']: - print("Cannot link OpenGLES statically, which is required for bare metal / standalone builds") - Exit(1) - -if env["os"] not in ["android", "bare_metal"] and (env['opencl'] or env['cppthreads']): +if env["os"] not in ["windows","android", "bare_metal"] and (env['opencl'] or env['cppthreads']): env.Append(LIBS = ['pthread']) -if env['opencl'] or env['gles_compute']: +if env['os'] == 'openbsd': + env.Append(LIBS = ['c']) + env.Append(CXXFLAGS = ['-fPIC']) + +if env['opencl']: if env['embed_kernels']: env.Append(CPPDEFINES = ['EMBEDDED_KERNELS']) + if env['compress_kernels']: + env.Append(CPPDEFINES = ['ARM_COMPUTE_COMPRESSED_KERNELS']) + env.Append(LIBS = ['z']) if env['debug']: env['asserts'] = True - env['logging'] = True - env.Append(CXXFLAGS = ['-O0','-g','-gdwarf-2']) + if not 'windows' in env['os']: + env.Append(CXXFLAGS = ['-O0','-g','-gdwarf-2']) + else: + env.Append(CXXFLAGS = ['-Z7','-MTd','-fms-compatibility','-fdelayed-template-parsing']) + env.Append(LINKFLAGS = ['-DEBUG']) + env.Append(CPPDEFINES = ['ARM_COMPUTE_DEBUG_ENABLED']) else: - env.Append(CXXFLAGS = ['-O3']) + if not 'windows' in env['os']: + env.Append(CXXFLAGS = ['-O3']) + else: + # on windows we use clang-cl which does not support the option -O3 + env.Append(CXXFLAGS = ['-O2']) if env['asserts']: env.Append(CPPDEFINES = ['ARM_COMPUTE_ASSERTS_ENABLED']) - env.Append(CXXFLAGS = ['-fstack-protector-strong']) + if not 'windows' in env['os']: + env.Append(CXXFLAGS = ['-fstack-protector-strong']) if env['logging']: env.Append(CPPDEFINES = ['ARM_COMPUTE_LOGGING_ENABLED']) +if env['address_sanitizer']: + if 'android' in env['os']: + env.Append(CXXFLAGS = ['-fsanitize=hwaddress']) + env.Append(LINKFLAGS = ['-fsanitize=hwaddress']) + else: + env.Append(CXXFLAGS = ['-fsanitize=address']) + env.Append(LINKFLAGS = ['-fsanitize=address']) + +if env['undefined_sanitizer']: + env.Append(CXXFLAGS = ['-fsanitize=undefined']) + env.Append(LINKFLAGS = ['-fsanitize=undefined']) + +if env['thread_sanitizer']: + env.Append(CXXFLAGS = ['-fsanitize=thread']) + env.Append(LINKFLAGS = ['-fsanitize=thread']) + env.Append(CPPPATH = ['#/include', "#"]) env.Append(CXXFLAGS = env['extra_cxx_flags']) env.Append(LINKFLAGS = env['extra_link_flags']) @@ -363,11 +647,12 @@ for dirname in os.listdir("./include"): Export('version_at_least') -if env['gles_compute'] and env['os'] != 'android': - env.Append(CPPPATH = ['#/include/linux']) - SConscript('./SConscript', variant_dir=build_path, duplicate=0) +if env['examples'] and (env['build_config'] or env['high_priority']): + print("WARNING: Building examples for selected operators not supported. Use examples=0") + Return() + if env['examples'] and env['exceptions']: if env['os'] == 'bare_metal' and env['arch'] == 'armv7a': print("WARNING: Building examples for bare metal and armv7a is not supported. Use examples=0") @@ -375,7 +660,18 @@ if env['examples'] and env['exceptions']: SConscript('./examples/SConscript', variant_dir='%s/examples' % build_path, duplicate=0) if env['exceptions']: + if env['build_config'] or env['high_priority']: + print("WARNING: Building tests for selected operators not supported") + Return() if env['os'] == 'bare_metal' and env['arch'] == 'armv7a': print("WARNING: Building tests for bare metal and armv7a is not supported") Return() SConscript('./tests/SConscript', variant_dir='%s/tests' % build_path, duplicate=0) + +# Unknown variables are not allowed +# Note: we must delay the call of UnknownVariables until after +# we have applied the Variables object to the construction environment +unknown = vars.UnknownVariables() +if unknown: + print("Unknown variables: %s" % " ".join(unknown.keys())) + Exit(1) |