diff --git a/.devcontainer/coverage.sh b/.devcontainer/coverage.sh index 84f6b4eae60be09b31331df6f5be7192a8c98dc7..d1d11c156946e5f67710ab82b729a876762af9de 100755 --- a/.devcontainer/coverage.sh +++ b/.devcontainer/coverage.sh @@ -1,13 +1,14 @@ #!/usr/bin/env bash -# SPDX-FileCopyrightText: 2024 Arm Limited and/or its affiliates +# SPDX-FileCopyrightText: 2024 - 2025 Arm Limited and/or its affiliates # # SPDX-License-Identifier: Apache-2.0 set -eu BUILD_ID="kleidicv-coverage" \ -CMAKE_CXX_FLAGS="--target=aarch64-linux-gnu --coverage" \ +COVERAGE="ON" \ +CMAKE_CXX_FLAGS="--target=aarch64-linux-gnu" \ CMAKE_EXE_LINKER_FLAGS="--rtlib=compiler-rt -static -fuse-ld=lld" \ EXTRA_CMAKE_ARGS="-DKLEIDICV_ENABLE_SME2=ON -DKLEIDICV_LIMIT_SME2_TO_SELECTED_ALGORITHMS=OFF -DKLEIDICV_LIMIT_SVE2_TO_SELECTED_ALGORITHMS=OFF" \ ./scripts/build.sh kleidicv-test diff --git a/.vscode/tasks.json b/.vscode/tasks.json index 69421be06f50a5ed3d78d1a2d965d5a8c49f5062..7fad36f64e554c07ac7899bec50b10efc8e383a1 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -7,7 +7,8 @@ "command": "${workspaceFolder}/scripts/build.sh", "problemMatcher": "$gcc", "args": [ - "kleidicv-test" + "kleidicv-test", + "kleidicv-c-example" ], "options": { "env": { @@ -48,7 +49,8 @@ "command": "${workspaceFolder}/scripts/build.sh", "problemMatcher": "$gcc", "args": [ - "kleidicv-test" + "kleidicv-test", + "kleidicv-c-example" ], "options": { "env": { diff --git a/.vscode/tasks.json.license b/.vscode/tasks.json.license index 468a897514d59f788a4c297fdde6fe2905fc57d3..3a94c3ffaaf3ed9ca55c9e9578bad8938b32fc24 100644 --- a/.vscode/tasks.json.license +++ b/.vscode/tasks.json.license @@ -1,3 +1,3 @@ -SPDX-FileCopyrightText: 2024 Arm Limited and/or its affiliates +SPDX-FileCopyrightText: 2024 - 2025 Arm Limited and/or its affiliates SPDX-License-Identifier: Apache-2.0 diff --git a/CMakeLists.txt b/CMakeLists.txt index 01208d679f3b8bc61eb8fc4e16d8d496df21f2ba..a96d8bbad921f1d64c836904540d8bda954d7a7f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,4 +1,4 @@ -# SPDX-FileCopyrightText: 2023 - 2024 Arm Limited and/or its affiliates +# SPDX-FileCopyrightText: 2023 - 2025 Arm Limited and/or its affiliates # # SPDX-License-Identifier: Apache-2.0 @@ -8,5 +8,6 @@ project("KleidiCV" CXX) add_subdirectory(kleidicv) add_subdirectory(kleidicv_thread) +add_subdirectory(examples/C) add_subdirectory(test) add_subdirectory(benchmark) diff --git a/examples/C/CMakeLists.txt b/examples/C/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..1e18c0c6c56422533becd03c55a45a9da284dab7 --- /dev/null +++ b/examples/C/CMakeLists.txt @@ -0,0 +1,35 @@ +# SPDX-FileCopyrightText: 2025 Arm Limited and/or its affiliates +# +# SPDX-License-Identifier: Apache-2.0 + +cmake_minimum_required(VERSION 3.16) + +project("KleidiCV C example") + +add_executable( + kleidicv-c-example + main.c +) + +target_include_directories( + kleidicv-c-example + PRIVATE + ${CMAKE_CURRENT_SOURCE_DIR}/../../kleidicv/include + ${CMAKE_CURRENT_BINARY_DIR}/../../kleidicv/include +) + +# Trying to link without the C++ runtime. Should work in case of gcc and clang. +list(REMOVE_ITEM CMAKE_CXX_IMPLICIT_LINK_LIBRARIES stdc++ c++) +set_target_properties( + kleidicv-c-example + PROPERTIES + LINKER_LANGUAGE "C" +) + +# Linking the whole KleidiCV library to check whether any cpp runtime feature is used. +target_link_libraries( + kleidicv-c-example + -Wl,--whole-archive + kleidicv + -Wl,--no-whole-archive +) diff --git a/examples/C/main.c b/examples/C/main.c new file mode 100644 index 0000000000000000000000000000000000000000..f4711af5734e720bbbcc4a5b4cc5f545783801d8 --- /dev/null +++ b/examples/C/main.c @@ -0,0 +1,23 @@ +// SPDX-FileCopyrightText: 2025 Arm Limited and/or its affiliates +// +// SPDX-License-Identifier: Apache-2.0 + +#include +#include + +#include "kleidicv/kleidicv.h" + +int main(void) { + uint8_t a[4] = {1, 2, 3, 4}; + uint8_t b[4] = {5, 6, 7, 8}; + uint8_t c[4] = {0, 0, 0, 0}; + + kleidicv_saturating_add_u8(a, sizeof(a[0]), b, sizeof(b[0]), c, sizeof(c[0]), + 4, 1); + + for (size_t i = 0; i < (sizeof(a) / sizeof(a[0])); i++) { + printf("%hhu + %hhu = %hhu\n", a[i], b[i], c[i]); + } + + return 0; +} diff --git a/kleidicv/include/kleidicv/kleidicv.h b/kleidicv/include/kleidicv/kleidicv.h index 6cdc742425f6c025e582107c1ad109455b944f1b..e9fd1505851076895fc39af1d8fcb3957208cd79 100644 --- a/kleidicv/include/kleidicv/kleidicv.h +++ b/kleidicv/include/kleidicv/kleidicv.h @@ -23,6 +23,10 @@ #ifndef KLEIDICV_H #define KLEIDICV_H +#ifndef __cplusplus +#include +#endif + #include "kleidicv/config.h" #include "kleidicv/ctypes.h" diff --git a/scripts/build.sh b/scripts/build.sh index d57df9f31937a0980d1527ba3b5b7e676b975937..92be84f604b01b04993f88fff4d601a7268a1594 100755 --- a/scripts/build.sh +++ b/scripts/build.sh @@ -1,15 +1,15 @@ #!/usr/bin/env bash -# -# SPDX-FileCopyrightText: 2023 - 2024 Arm Limited and/or its affiliates + +# SPDX-FileCopyrightText: 2023 - 2025 Arm Limited and/or its affiliates # # SPDX-License-Identifier: Apache-2.0 -# + # Builds a given target. # # The build artifacts are placed in the `build` directory. # # Arguments: -# 1: Target to build. Defaults to 'kleidicv'. +# Targets to build. Defaults to 'kleidicv'. # # To target Android devices the following command can be used: # BUILD_ID=android \ @@ -59,7 +59,7 @@ SCRIPT_PATH="$(realpath "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)")" : "${EXTRA_CMAKE_ARGS:=}" : "${SOURCE_PATH:="$(realpath "${SCRIPT_PATH}"/../)"}" -IFS=' ' read -r -a CMAKE_TARGETS <<< "${1:-kleidicv}" +IFS=' ' read -r -a CMAKE_TARGETS <<< "${@:-kleidicv}" IFS=' ' read -r -a EXTRA_CMAKE_ARGS_ARRAY <<< "${EXTRA_CMAKE_ARGS}" # ------------------------------------------------------------------------------ diff --git a/scripts/ci.sh b/scripts/ci.sh index a48b29aa73f3f4b9383658b9b8dcf8a0c887e24f..b2c8928d85905686e65f84d76c36c3e5c0b0671e 100755 --- a/scripts/ci.sh +++ b/scripts/ci.sh @@ -1,6 +1,6 @@ #!/usr/bin/env bash -# SPDX-FileCopyrightText: 2024 Arm Limited and/or its affiliates +# SPDX-FileCopyrightText: 2024 - 2025 Arm Limited and/or its affiliates # # SPDX-License-Identifier: Apache-2.0 @@ -42,7 +42,7 @@ cmake -S . -B build/ci/clang -G Ninja \ -DCMAKE_COMPILE_WARNING_AS_ERROR=ON \ -DCMAKE_CXX_CLANG_TIDY=clang-tidy-20 \ -DCMAKE_CXX_FLAGS="--target=aarch64-linux-gnu --coverage" \ - -DCMAKE_EXE_LINKER_FLAGS="--rtlib=compiler-rt -static -fuse-ld=lld" \ + -DCMAKE_EXE_LINKER_FLAGS="--rtlib=compiler-rt -static -fuse-ld=lld --coverage" \ -DKLEIDICV_ENABLE_SME2=ON \ -DKLEIDICV_LIMIT_SME2_TO_SELECTED_ALGORITHMS=OFF \ -DKLEIDICV_LIMIT_SVE2_TO_SELECTED_ALGORITHMS=OFF \ diff --git a/scripts/format.sh b/scripts/format.sh index df56b4647a7af1351f7d16d527d21414234ddda1..b3e55a31b8ebdef4b31a74d27ea58b0a8198370f 100755 --- a/scripts/format.sh +++ b/scripts/format.sh @@ -1,6 +1,6 @@ #!/usr/bin/env bash -# SPDX-FileCopyrightText: 2023 - 2024 Arm Limited and/or its affiliates +# SPDX-FileCopyrightText: 2023 - 2025 Arm Limited and/or its affiliates # # SPDX-License-Identifier: Apache-2.0 @@ -35,7 +35,8 @@ SOURCES="$(find \ "${KLEIDICV_ROOT_PATH}/kleidicv_thread" \ "${KLEIDICV_ROOT_PATH}/test" \ "${KLEIDICV_ROOT_PATH}/conformity/opencv" \ - \( -name \*.cpp -o -name \*.h -o -name \*.h.in \) \ + "${KLEIDICV_ROOT_PATH}/examples" \ + \( -name \*.cpp -o -name \*.c -o -name \*.h -o -name \*.h.in \) \ -print)" if [[ "${CHECK_ONLY}" == "ON" ]]; then