From f2722dc396c829c208f9318489af8417ba643f00 Mon Sep 17 00:00:00 2001 From: Jakub Sujak Date: Tue, 9 Apr 2024 12:23:18 +0100 Subject: [PATCH 1/3] Add KleidiAI project skeleton This first commit includes: * Configuration files. * Build files. * Test framework setup. Signed-off-by: Georgios Pinitas Signed-off-by: Jakub Sujak --- .clang-format | 16 ++++ .clang-tidy | 26 ++++++ .cmakelintrc | 6 ++ .editorconfig | 20 +++++ .gitignore | 122 ++++++++++++++++++++++++++ .pre-commit-config.yaml | 63 +++++++++++++ CMakeLists.txt | 62 +++++++++++++ cmake/FetchGTest.cmake | 20 +++++ test/sample.cpp | 8 ++ tools/pre-commit/signedoff_checker.py | 98 +++++++++++++++++++++ tools/python-requirements.txt | 7 ++ 11 files changed, 448 insertions(+) create mode 100644 .clang-format create mode 100644 .clang-tidy create mode 100644 .cmakelintrc create mode 100644 .editorconfig create mode 100644 .gitignore create mode 100644 .pre-commit-config.yaml create mode 100644 CMakeLists.txt create mode 100644 cmake/FetchGTest.cmake create mode 100644 test/sample.cpp create mode 100644 tools/pre-commit/signedoff_checker.py create mode 100644 tools/python-requirements.txt diff --git a/.clang-format b/.clang-format new file mode 100644 index 00000000..77266d27 --- /dev/null +++ b/.clang-format @@ -0,0 +1,16 @@ +# +# SPDX-FileCopyrightText: Copyright 2024 Arm Limited and/or its affiliates +# +# SPDX-License-Identifier: Apache-2.0 +# +--- +Language: Cpp +BasedOnStyle: LLVM +ColumnLimit: 120 + +AccessModifierOffset: -4 +AlignAfterOpenBracket: AlwaysBreak +AllowShortFunctionsOnASingleLine: None +DerivePointerAlignment: false +IndentWidth: 4 +PointerAlignment: Left diff --git a/.clang-tidy b/.clang-tidy new file mode 100644 index 00000000..7cff2942 --- /dev/null +++ b/.clang-tidy @@ -0,0 +1,26 @@ +# +# SPDX-FileCopyrightText: Copyright 2024 Arm Limited and/or its affiliates +# +# SPDX-License-Identifier: Apache-2.0 +# +--- +Checks: ' +-*, +bugprone-*, +cert-*, +clang-analyzer-*, +clang-diagnostic-*, +cppcoreguidelines-*, +google-*, +llvm-*, +-llvm-include-order, +misc-*, +modernize-*, +-modernize-use-trailing-return-type, +performance-*, +readability-*, +-readability-identifier-length, +-readability-magic-numbers, +-readability-function-cognitive-complexity, +' +... diff --git a/.cmakelintrc b/.cmakelintrc new file mode 100644 index 00000000..b48dbfbc --- /dev/null +++ b/.cmakelintrc @@ -0,0 +1,6 @@ +# +# SPDX-FileCopyrightText: Copyright 2024 Arm Limited and/or its affiliates +# +# SPDX-License-Identifier: Apache-2.0 +# +filter=-linelength diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 00000000..4a4f2ce6 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,20 @@ +# +# SPDX-FileCopyrightText: Copyright 2024 Arm Limited and/or its affiliates +# +# SPDX-License-Identifier: Apache-2.0 +# + +# Indicates this is the top-level EditorConfig. +root = true + +# Apply these settings to all files. +[*] +charset = utf-8 +end_of_line = lf +indent_size = 4 +indent_style = space +insert_final_newline = true +trim_trailing_whitespace = true + +[*.{json,yaml}] +indent_size = 2 diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000..4b6b113a --- /dev/null +++ b/.gitignore @@ -0,0 +1,122 @@ +# +# SPDX-FileCopyrightText: Copyright 2024 Arm Limited and/or its affiliates +# +# SPDX-License-Identifier: Apache-2.0 +# + +### Editor and IDE files +.vscode/* +.history/ +*.vsix + +.idea/* +*.iml +out +gen + +# Emacs +\#*\# +/.emacs.desktop +/.emacs.desktop.lock +*.elc +auto-save-list +tramp +.\#* + +.cache + +# directory configuration +.dir-locals.el + +# projectiles files +.projectile + +# Vim +Session.vim +Sessionx.vim + +# Auto-generated tag files +tags + +### C/C++ +# Prerequisites +*.d + +# Compiled Object files +*.slo +*.lo +*.o +*.obj +*.ko +*.elf + +# Linker output +*.ilk +*.map +*.exp + +# Precompiled Headers +*.gch +*.pch + +# Compiled Dynamic libraries +*.so +*.so.* +*.dylib +*.dll + +# Compiled Static libraries +*.lai +*.la +*.a +*.lib + +# Executables +*.exe +*.out +*.app + +### CMake +CMakeLists.txt.user +CMakeCache.txt +CMakeFiles +CMakeScripts +Testing +Makefile +cmake_install.cmake +install_manifest.txt +compile_commands.json +CTestTestfile.cmake +_deps + +# Build directory +cmake-build-*/ +build/ + +### Debug files +*.dSYM/ +*.su +*.idb +*.pdb + +### Python +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] +*$py.class + +# Environments +.env +.venv +env/ +venv/ +ENV/ +env.bak/ +venv.bak/ + +# Cython debug symbols +cython_debug/ + +### System +*~ +.DS_Store diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 00000000..1981b815 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,63 @@ +# +# SPDX-FileCopyrightText: Copyright 2024 Arm Limited and/or its affiliates +# +# SPDX-License-Identifier: Apache-2.0 +# + +default_install_hook_types: [ pre-commit, pre-push ] +fail_fast: false +repos: + - repo: https://github.com/fsfe/reuse-tool + rev: v3.0.1 + hooks: + - id: reuse + stages: [ commit ] + - repo: https://github.com/pre-commit/pre-commit-hooks + rev: v4.5.0 + hooks: + - id: check-added-large-files + args: [ '--maxkb=100' ] + stages: [ commit ] + - id: check-yaml + stages: [ commit ] + - repo: https://github.com/editorconfig-checker/editorconfig-checker.python + rev: 2.7.3 + hooks: + - id: editorconfig-checker + alias: ec + - repo: https://github.com/pre-commit/mirrors-clang-format + rev: v17.0.6 + hooks: + - id: clang-format + stages: [ commit ] + - repo: https://github.com/cmake-lint/cmake-lint + rev: 1.4.2 + hooks: + - id: cmakelint + stages: [ commit ] + - repo: https://github.com/executablebooks/mdformat + rev: 0.7.17 + hooks: + - id: mdformat + stages: [ commit ] + - repo: https://github.com/asottile/reorder-python-imports + rev: v3.12.0 + hooks: + - id: reorder-python-imports + stages: [ commit ] + - repo: https://github.com/psf/black + rev: 24.2.0 + hooks: + - id: black + stages: [ commit ] + - repo: local + hooks: + - id: signed-off-checker + alias: signed-off-checker + name: Signed-off Checker + entry: python tools/pre-commit/signedoff_checker.py + language: python + language_version: python3 + description: Ensures that latest commit has been signed-off with `--signoff`. + pass_filenames: false + stages: [ push ] diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 00000000..d45d5070 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,62 @@ +# +# SPDX-FileCopyrightText: Copyright 2024 Arm Limited and/or its affiliates +# +# SPDX-License-Identifier: Apache-2.0 +# +cmake_minimum_required(VERSION 3.18) + +project(KleidiAI + VERSION 0.0.1 + LANGUAGES C CXX ASM +) + +set(CMAKE_C_STANDARD 99) +set(CMAKE_C_STANDARD_REQUIRED ON) +set(CMAKE_C_EXTENSIONS OFF) + +set(CMAKE_CXX_STANDARD 17) +set(CMAKE_CXX_STANDARD_REQUIRED OFF) +set(CMAKE_CXX_EXTENSIONS OFF) + +list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake") +include(FetchGTest) + +option(KLEIDIAI_BUILD_TESTS "Build unit tests." ON) +option(KLEIDIAI_ENABLE_CLANG_TIDY "Build with Clang-Tidy checks." OFF) + +if(KLEIDIAI_ENABLE_CLANG_TIDY) + set(CMAKE_C_CLANG_TIDY "clang-tidy") + set(CMAKE_CXX_CLANG_TIDY "clang-tidy") +endif() + +set(KLEIDIAI_WARNING_FLAGS + "-Wall" + "-Wctor-dtor-privacy" + "-Wdisabled-optimization" + "-Weffc++" + "-Werror" + "-Wextra" + "-Wformat-security" + "-Wformat=2" + "-Winit-self" + "-Wno-ignored-attributes" + "-Wno-misleading-indentation" + "-Wno-overlength-strings" + "-Woverloaded-virtual" + "-Wsign-promo" + "-Wstrict-overflow=2" + "-Wswitch-default" +) + +if(KLEIDIAI_BUILD_TESTS) + enable_testing() + include(GoogleTest) + + add_executable(kleidiai_test test/sample.cpp) + target_compile_options(kleidiai_test PRIVATE ${KLEIDIAI_WARNING_FLAGS}) + target_link_libraries(kleidiai_test PRIVATE GTest::gtest_main) + + # Cross-compiling is a common use case which creates a conflict if DISCOVERY_MODE is set to POST_BUILD (by default) + # since the host platform does not match the target. Setting the mode to PRE_TEST avoids this conflict. + gtest_discover_tests(kleidiai_test DISCOVERY_MODE PRE_TEST) +endif() diff --git a/cmake/FetchGTest.cmake b/cmake/FetchGTest.cmake new file mode 100644 index 00000000..0ca94412 --- /dev/null +++ b/cmake/FetchGTest.cmake @@ -0,0 +1,20 @@ +# +# SPDX-FileCopyrightText: Copyright 2024 Arm Limited and/or its affiliates +# +# SPDX-License-Identifier: Apache-2.0 +# +include(FetchContent) + +# Set timestamp of extracted contents to time of extraction. +if(POLICY CMP0135) + cmake_policy(SET CMP0135 NEW) +endif() + +fetchcontent_declare(googletest + GIT_REPOSITORY https://github.com/google/googletest.git + GIT_TAG v1.14.0 +) + +set(gtest_force_shared_crt ON CACHE BOOL "" FORCE) + +fetchcontent_makeavailable(googletest) diff --git a/test/sample.cpp b/test/sample.cpp new file mode 100644 index 00000000..85680ea3 --- /dev/null +++ b/test/sample.cpp @@ -0,0 +1,8 @@ +// +// SPDX-FileCopyrightText: Copyright 2024 Arm Limited and/or its affiliates +// +// SPDX-License-Identifier: Apache-2.0 +// +#include + +TEST(SampleSuite, SampleTest) { EXPECT_EQ(1 + 2, 3); } diff --git a/tools/pre-commit/signedoff_checker.py b/tools/pre-commit/signedoff_checker.py new file mode 100644 index 00000000..4b917309 --- /dev/null +++ b/tools/pre-commit/signedoff_checker.py @@ -0,0 +1,98 @@ +#!/usr/bin/env python3 +# +# SPDX-FileCopyrightText: Copyright 2024 Arm Limited and/or its affiliates +# +# SPDX-License-Identifier: Apache-2.0 +# +""" Checks that a patch has been signed-off """ +import argparse +import logging +import os +import subprocess +import sys + +logger = logging.getLogger("SignedOff Checker") + + +class SignedOffByChecker: + """ + A class that checks if a patch has been signed-off. + + Parameters + ---------- + dir : 'str' (optional) + the directory to run the checker on and check the latest patch + Default: . + """ + + def __init__(self, dir=".") -> None: + self.dir = os.path.abspath(dir) + logger.debug(f"SignedOffBy checker is set up to run on {self.dir}") + + def run(self) -> None: + """Runs the checker. + + Raises + ------ + ValueError + If the checker fails to execute + """ + retval = 0 + logger.debug(f"Running SignOff checker on '{self.dir}'") + try: + os.chdir(self.dir) + cmd = ["git", "show", "-s", "--format=%B", "HEAD"] + commit_msg = subprocess.check_output(cmd).decode("utf-8") + if "Signed-off-by:" not in commit_msg: + logger.error( + f"Patch not signed-off (Could not find 'Signed-off-by:' in the commit message). Use: git commit -s" + ) + retval = -1 + else: + logger.info("Patch has been signed-off!") + except (subprocess.CalledProcessError, FileNotFoundError) as e: + logger.error(f"SignedOff checker failed with {e}") + retval = -1 + + if retval != 0: + raise ValueError("SignedOffBy checker failed!") + + +def parse_arguments(): + parser = argparse.ArgumentParser() + parser.add_argument( + "--dir", + "-d", + help="Folder to execute the checker in. Default: .", + type=str, + default=".", + ) + parser.add_argument( + "--debug", + "-D", + help="Enable debug information. Default: False", + action="store_true", + default=False, + ) + args = parser.parse_args() + + return args + + +def run_signedoff_checker(args): + logging.basicConfig(level=logging.DEBUG if args.debug else logging.INFO) + logger.debug(f"Arguments passed: {str(args.__dict__)}") + + retval = 0 + try: + checker = SignedOffByChecker(args.dir) + checker.run() + except ValueError as e: + logger.error("Exception caught in SignedOffBy checker: %s" % e) + retval = 1 + + return retval + + +if __name__ == "__main__": + sys.exit(run_signedoff_checker(parse_arguments())) diff --git a/tools/python-requirements.txt b/tools/python-requirements.txt new file mode 100644 index 00000000..9518a6de --- /dev/null +++ b/tools/python-requirements.txt @@ -0,0 +1,7 @@ +# +# SPDX-FileCopyrightText: Copyright 2024 Arm Limited and/or its affiliates +# +# SPDX-License-Identifier: Apache-2.0 +# +pre-commit +reuse -- GitLab From 6f293cbf4d1a6bc32c3874177959a7661aa0b2d7 Mon Sep 17 00:00:00 2001 From: Jakub Sujak Date: Tue, 9 Apr 2024 13:52:23 +0100 Subject: [PATCH 2/3] Ignore indent sizes in LICENSES directory Signed-off-by: Jakub Sujak --- .editorconfig | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.editorconfig b/.editorconfig index 4a4f2ce6..183566b3 100644 --- a/.editorconfig +++ b/.editorconfig @@ -16,5 +16,10 @@ indent_style = space insert_final_newline = true trim_trailing_whitespace = true +# Override settings. [*.{json,yaml}] indent_size = 2 + +# Override settings. +[LICENSES/*] +indent_size = unset -- GitLab From 1a1467e29d205e234c3bd888e9127de8f41c90d3 Mon Sep 17 00:00:00 2001 From: Jakub Sujak Date: Tue, 9 Apr 2024 13:54:20 +0100 Subject: [PATCH 3/3] Reformat test according to clang-format Signed-off-by: Jakub Sujak --- test/sample.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/test/sample.cpp b/test/sample.cpp index 85680ea3..d8e63383 100644 --- a/test/sample.cpp +++ b/test/sample.cpp @@ -5,4 +5,6 @@ // #include -TEST(SampleSuite, SampleTest) { EXPECT_EQ(1 + 2, 3); } +TEST(SampleSuite, SampleTest) { + EXPECT_EQ(1 + 2, 3); +} -- GitLab