Elffuss BraidHub

kikocis/kleidiai public

main · 33.0 KiBRawPermalink
1#
2# SPDX-FileCopyrightText: Copyright 2024-2026 Arm Limited and/or its affiliates <open-source-office@arm.com>
3#
4# SPDX-License-Identifier: Apache-2.0
5#
6# Summary:
7# Run builds using different compilers, runs unit & example tests, performs static analysis,
8# gathers multi-variant coverage and publishes HTML/JUnit/Cobertura reports.
9# Purpose and scope:
10# - Provide public-facing CI validating portability and feature coverage of the library.
11# - Ensure all warnings are treated as errors across compilers.
12# - Model negative/positive feature scenarios (illegal instruction paths, SME variants).
13# - Collect code coverage across distinct environments & feature sets.
14# - Offer reproducible pre-commit formatting / lint checks.
15# Main jobs (high-level):
16# - build-* : compile library/tests/examples with different toolchains.
17# - test-* : execute unit tests (sharded), examples, FVP feature model tests, clang-tidy.
18# - coverage-* : produce per-variant JSON coverage traces.
19# - coverage : aggregate traces into Cobertura + HTML.
20# - pages : publish coverage reports via Pages.
21# Usage notes:
22# - FVP jobs simulate CPU feature sets; failures (Illegal instruction) are expected in negative tests.
23# - CI caching policy switches to pull-push on default branch to warm shared caches.
24#
25
26# Base template: .standard-rules
27# Purpose: Common rules & timeout setting
28.standard-rules:
29 timeout: 30m
30 rules:
31 # Run a job for merge requests
32 - if: $CI_PIPELINE_SOURCE == 'merge_request_event'
33 # Run a job for default (main) branch
34 - if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
35 variables:
36 CACHE_POLICY: pull-push
37 # Run a job for protected tags (release and rc ones)
38 - if: $CI_COMMIT_TAG && $CI_COMMIT_REF_PROTECTED == "true"
39
40# Base template: .stable-rules
41# Purpose: Run top-level project checks only when core project files change in MRs,
42# and always on default branch/protected tags.
43.stable-rules:
44 timeout: 30m
45 rules:
46 - if: $CI_PIPELINE_SOURCE == 'merge_request_event'
47 changes: &stable_changes
48 - .gitlab/ci/kleidiai.yml
49 - "*"
50 - ".*"
51 - benchmark/**/*
52 - cmake/**/*
53 - docker/**/*
54 - docs/**/*
55 - examples/**/*
56 - kai/**/*
57 - LICENSES/**/*
58 - test/**/*
59 - third_party/**/*
60 - tools/**/*
61 - if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
62 variables:
63 CACHE_POLICY: pull-push
64 - if: $CI_COMMIT_TAG && $CI_COMMIT_REF_PROTECTED == "true"
65
66# Base template: .main-branch-verification-rules
67# Purpose: Common opt-out rules for jobs validating main branch state
68.main-branch-verification-rules:
69 rules: &main_branch_verification_rules
70 - if: >
71 $DISABLE_MAIN_BRANCH_VERIFICATION_JOBS != "true" &&
72 $CI_PIPELINE_SOURCE == 'merge_request_event' &&
73 $CI_MERGE_REQUEST_TARGET_BRANCH_NAME != 'main'
74 when: never
75 - if: >
76 $DISABLE_MAIN_BRANCH_VERIFICATION_JOBS != "true" &&
77 $CI_PIPELINE_SOURCE == 'merge_request_event' &&
78 $CI_MERGE_REQUEST_TARGET_BRANCH_NAME == 'main'
79 changes: *stable_changes
80 - if: >
81 $DISABLE_MAIN_BRANCH_VERIFICATION_JOBS != "true" &&
82 $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
83 variables:
84 CACHE_POLICY: pull-push
85 - if: >
86 $DISABLE_MAIN_BRANCH_VERIFICATION_JOBS != "true" &&
87 $CI_COMMIT_TAG &&
88 $CI_COMMIT_REF_PROTECTED == "true"
89
90# Purpose: Build library tests.
91build-clang:
92 extends:
93 - .stable-rules
94 stage: build
95 script:
96 # Enforce strict warning-as-error policy
97 - cmake -G Ninja -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ -DCMAKE_CXX_FLAGS="-Werror" -DCMAKE_C_FLAGS="-Werror" -DCMAKE_BUILD_TYPE=Release -DKLEIDIAI_BUILD_TESTS=ON -DKLEIDIAI_BUILD_BENCHMARK=ON -S . -B ${CI_JOB_NAME_SLUG}
98 # Parallel build capped to reserved CPUs.
99 - cmake --build ${CI_JOB_NAME_SLUG} -j${PARALLEL_JOBS} --verbose
100 artifacts:
101 expire_in: 1 day
102 paths:
103 - ${CI_JOB_NAME_SLUG}/kleidiai_test
104 - ${CI_JOB_NAME_SLUG}/kleidiai_benchmark
105
106# Purpose: Build library tests.
107build-gcc:
108 extends:
109 - .stable-rules
110 stage: build
111 script:
112 # Enforce strict warning-as-error policy
113 - cmake -G Ninja -DCMAKE_C_COMPILER=gcc -DCMAKE_CXX_COMPILER=g++ -DCMAKE_CXX_FLAGS="-Werror" -DCMAKE_C_FLAGS="-Werror" -DCMAKE_BUILD_TYPE=Release -DKLEIDIAI_BUILD_TESTS=ON -DKLEIDIAI_BUILD_BENCHMARK=ON -S . -B ${CI_JOB_NAME_SLUG}
114 # Parallel build capped to reserved CPUs with verbose
115 - cmake --build ${CI_JOB_NAME_SLUG} -j${PARALLEL_JOBS} --verbose
116 artifacts:
117 expire_in: 1 day
118 paths:
119 - ${CI_JOB_NAME_SLUG}/kleidiai_test
120 - ${CI_JOB_NAME_SLUG}/kleidiai_benchmark
121
122# Purpose: Build library tests.
123build-gcc-bazel:
124 extends:
125 - .stable-rules
126 stage: build
127 variables:
128 # Cache Bazelisk files in local folder
129 BAZELISK_HOME: '.cache/bazelisk'
130 cache:
131 - key: cache-bazelisk
132 paths:
133 - $BAZELISK_HOME
134 policy: $CACHE_POLICY
135 script:
136 # Ensure deterministic build state.
137 - bazelisk clean
138 # Enforce strict warning-as-error policy, cap parallel build and continues to gather full failure set
139 - bazelisk build -c opt --copt="-Werror" --cxxopt="-Werror" --jobs=${PARALLEL_JOBS} -k --subcommands --verbose_failures --curses=no //...
140 # Copy build artifacts to separate folder
141 - mkdir -p ${CI_JOB_NAME_SLUG} && cp bazel-bin/test/kleidiai_test ${CI_JOB_NAME_SLUG}/
142 artifacts:
143 expire_in: 1 day
144 paths:
145 - ${CI_JOB_NAME_SLUG}/kleidiai_test
146
147# Purpose: Build library tests
148build-clang-bazel:
149 extends:
150 - .stable-rules
151 stage: build
152 variables:
153 # Cache Bazelisk files in local folder
154 BAZELISK_HOME: '.cache/bazelisk'
155 cache:
156 - key: cache-bazelisk
157 paths:
158 - $BAZELISK_HOME
159 policy: $CACHE_POLICY
160 script:
161 # Ensure deterministic build state.
162 - bazelisk clean
163 # Enforce strict warning-as-error policy, cap parallel build and continues to gather full failure set.
164 # Also disable explicit layering_check feature supported by the compiler
165 - CC=clang bazelisk build -c opt --copt="-Werror" --cxxopt="-Werror" --jobs=${PARALLEL_JOBS} -k --subcommands --verbose_failures --compiler=clang --features=no-layering_check --curses=no //...
166 # Copy build artifacts to separate folder
167 - mkdir -p ${CI_JOB_NAME_SLUG} && cp bazel-bin/test/kleidiai_test ${CI_JOB_NAME_SLUG}/
168 artifacts:
169 expire_in: 1 day
170 paths:
171 - ${CI_JOB_NAME_SLUG}/kleidiai_test
172
173# Purpose: Build examples
174build-examples:
175 stage: build
176 extends:
177 - .stable-rules
178 script:
179 - mkdir -p build
180 - |
181 for EXAMPLE in `ls examples -1`; do
182 # Validate that each example has a build script
183 if [ -f examples/${EXAMPLE}/CMakeLists.txt ]; then
184 echo "-----------------------------------------------------------"
185 echo "Build examples/${EXAMPLE}"
186 echo "-----------------------------------------------------------"
187 mkdir -p build_${EXAMPLE}
188 cmake -G Ninja -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ -DCMAKE_CXX_FLAGS="-Werror" -DCMAKE_C_FLAGS="-Werror" -DCMAKE_BUILD_TYPE=Release -S examples/$EXAMPLE -B build_${EXAMPLE}
189 cmake --build build_${EXAMPLE} -j${PARALLEL_JOBS} --verbose
190 # Store in top level build/ folder, assuming output binary name is same as folder
191 cp build_${EXAMPLE}/${EXAMPLE} build/
192 else
193 # Guard against missing build config.
194 echo "No build file found for ${EXAMPLE}"
195 exit 1
196 fi
197 done
198 artifacts:
199 expire_in: 1 day
200 paths:
201 - build
202
203# Purpose: Run non-SME examples; skip SME variants (handled in dedicated job) and log output.
204test-examples:
205 stage: test
206 extends:
207 - .stable-rules
208 needs:
209 - build-examples
210 script:
211 - |
212 for EXAMPLE in `ls build -1`; do
213 # Skip SME examples (run separately).
214 [[ $EXAMPLE == *sme* ]] && continue
215 echo "-----------------------------------------------------------"
216 echo "Run ${EXAMPLE}"
217 echo "-----------------------------------------------------------"
218 # Run and preserve separate log
219 build/${EXAMPLE} | tee -a example_${EXAMPLE}.log
220 done
221 artifacts:
222 expire_in: 1 day
223 paths:
224 - "example_*.log"
225
226# Purpose: clang-tidy static analysis of library C/C++ sources.
227test-clang-tidy:
228 extends:
229 - .stable-rules
230 stage: test
231 needs: []
232 script:
233 # Build and generate compilation_database.json for proper flags propagation to post processing tools
234 - cmake -G Ninja -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ -DCMAKE_CXX_FLAGS="-Werror" -DCMAKE_C_FLAGS="-Werror" -DCMAKE_BUILD_TYPE=Release -DKLEIDIAI_BUILD_TESTS=ON -DKLEIDIAI_BUILD_BENCHMARK=ON -DCMAKE_EXPORT_COMPILE_COMMANDS=ON -B build/${CI_JOB_NAME_SLUG}
235 # Only test the main library with C/C++ files.
236 - clang-tidy --header-filter ".*" --warnings-as-errors "*" -p build/${CI_JOB_NAME_SLUG} $(find kai -type f \( -name \*.c -o -name \*.cpp \))
237
238# Purpose: Verify that all micro-kernels are registered for benchmarking.
239test-verify-benchmark-registration:
240 extends:
241 - .stable-rules
242 stage: test
243 needs: []
244 rules: *main_branch_verification_rules
245 script:
246 - python3 tools/check_benchmark_microkernels.py
247
248# Purpose: Verify that all micro-kernels are documented in docs/microkernel_tables.md.
249test-verify-microkernel-tables:
250 extends:
251 - .stable-rules
252 stage: test
253 needs: []
254 rules: *main_branch_verification_rules
255 script:
256 - python3 tools/check_microkernel_tables.py
257
258# Purpose: Verify that all micro-kernels have correct names.
259test-verify-microkernel-names:
260 extends:
261 - .stable-rules
262 stage: test
263 needs: []
264 rules: *main_branch_verification_rules
265 script:
266 - python3 tools/check_microkernel_names.py
267 - python3 tools/check_microkernel_names.py --generate-documentation docs/microkernel_names.md
268 - |
269 if [ -n "$(git status --porcelain -- docs/microkernel_names.md)" ]; then
270 echo "docs/microkernel_names.md is out of date."
271 echo "Run:"
272 echo " python3 tools/check_microkernel_names.py --generate-documentation docs/microkernel_names.md"
273 echo "and commit the result whenever tools/naming/rules.py is updated."
274 git diff -- docs/microkernel_names.md
275 exit 1
276 fi
277
278# Purpose: Verify that all micro-kernel headers contain include directives for used symbols.
279test-verify-microkernel-header-includes:
280 extends:
281 - .stable-rules
282 stage: test
283 needs: []
284 rules: *main_branch_verification_rules
285 script:
286 - python3 tools/check_microkernel_header_includes.py
287
288# Purpose: Build current sources against tests/benchmarks from latest semver tag to detect API breakage.
289test-api-compat:
290 extends:
291 - .stable-rules
292 stage: test
293 needs: []
294 rules: *main_branch_verification_rules
295 script:
296 - ./tools/check_api_compat.py
297
298# Purpose: Run pre-commit hooks (formatting, linting) with cached tool downloads.
299pre-commit-hooks:
300 variables:
301 PRE_COMMIT_HOME: '.cache/pre-commit'
302 extends:
303 - .standard-rules
304 stage: build
305 # Cache downloaded pre-commit checkers
306 cache:
307 - key: cache-pre-commit
308 paths:
309 - $PRE_COMMIT_HOME
310 policy: $CACHE_POLICY
311 script:
312 - PRE_COMMIT_HOME=$PRE_COMMIT_HOME pre-commit run --all-files
313
314# Purpose: Validate MR metadata used as the squash/merge commit message.
315test-verify-squash-commit-message:
316 stage: test
317 needs: []
318 rules:
319 - if: $CI_PIPELINE_SOURCE == 'merge_request_event'
320 script:
321 - python3 tools/check_squash_commit_message.py
322
323# Purpose: Manual gate job to record external pipeline status.
324test-remote:
325 # Part of the pipeline is executed in a separate system.
326 #
327 # When the remote pipeline has been completed, this job is triggered automatically
328 # with the information about the remote pipeline including whether it's passed or failed.
329 rules:
330 # Run the job only for a public pipeline
331 - if: $CI_PIPELINE_SOURCE == 'merge_request_event' && $CI_SERVER_HOST == 'gitlab.arm.com'
332 # Longer timeout than rest of jobs to account for external system load
333 timeout: 1h
334 stage: test
335 needs: []
336 when: manual
337 allow_failure: false
338 variables:
339 REMOTE_PIPELINE_ID: 0
340 REMOTE_PIPELINE_PASSED: ""
341 REMOTE_PIPELINE_MESSAGE: ""
342 script:
343 - echo "REMOTE_PIPELINE_ID=${REMOTE_PIPELINE_ID}" |& tee remote_result.txt
344 - echo "REMOTE_PIPELINE_PASSED=${REMOTE_PIPELINE_PASSED}" |& tee -a remote_result.txt
345 - echo "REMOTE_PIPELINE_MESSAGE=${REMOTE_PIPELINE_MESSAGE}" |& tee -a remote_result.txt
346 - echo "${REMOTE_PIPELINE_PASSED}" | grep -q "true"
347 artifacts:
348 when: always
349 expire_in: 1 day
350 paths:
351 - remote_result.txt
352
353# Script anchor: run-unit-tests
354# Purpose: Sharded GoogleTest execution producing multiple XML reports to be below CI limits.
355# Input variables:
356# * UT_VARIANT_NAME - base name used to find path to unit test binaries and generate report name
357# * UT_PARALLEL - number of separate executions, default 4 since 100MB / 30MB = 3.(3) and rounded up
358# * UT_BINARY_PATH - path to folder with unit test binaries, default is ./build-${UT_VARIANT_NAME}/
359# * UT_REPORT_PATH - prefix to unit test report file path, default is ./kleidiai_results-${UT_VARIANT_NAME}
360# * UT_EXTRA_ARGS - extra arguments for test binary, default is none
361.run-unit-tests: &run-unit-tests
362 - echo "Run unit test from ${UT_BINARY_PATH:-./build-${UT_VARIANT_NAME}}"
363 - export GTEST_TOTAL_SHARDS=${UT_PARALLEL:-4}
364 - |
365 : "${KAI_TEST_BUFFER_POLICY:?KAI_TEST_BUFFER_POLICY must be set}"
366 echo "KAI_TEST_BUFFER_POLICY=${KAI_TEST_BUFFER_POLICY}"
367 export ASAN_OPTIONS="${ASAN_OPTIONS:+${ASAN_OPTIONS}:}halt_on_error=1:print_stacktrace=1"
368 export UBSAN_OPTIONS="${UBSAN_OPTIONS:+${UBSAN_OPTIONS}:}halt_on_error=1:print_stacktrace=1"
369 printf 'section_start:%s:test_environment[collapsed=true]\r\e[0KTest environment\n' "$(date +%s)"
370 echo "uname=$(uname -a)"
371 echo "cc=$(command -v cc || true)"
372 cc --version | head -5 || true
373 echo "cxx=$(command -v c++ || true)"
374 c++ --version | head -5 || true
375 echo "ASAN_OPTIONS=${ASAN_OPTIONS:-}"
376 echo "UBSAN_OPTIONS=${UBSAN_OPTIONS:-}"
377 printf 'section_end:%s:test_environment\r\e[0K\n' "$(date +%s)"
378 {
379 echo "job=${CI_JOB_NAME:-}"
380 echo "job_slug=${CI_JOB_NAME_SLUG:-}"
381 echo "commit=${CI_COMMIT_SHA:-}"
382 echo "seed=${GLOBAL_TEST_SEED:-42}"
383 echo "total_shards=${GTEST_TOTAL_SHARDS}"
384 echo "binary_path=${UT_BINARY_PATH:-./build-${UT_VARIANT_NAME}}/kleidiai_test"
385 echo "buffer_policy=${KAI_TEST_BUFFER_POLICY}"
386 echo "extra_args=${UT_EXTRA_ARGS:-}"
387 echo "quiet=${KLEIDIAI_TEST_CI_QUIET:-1}"
388 }
389 - |
390 for GTEST_SHARD_INDEX in `seq 0 $((GTEST_TOTAL_SHARDS - 1))` ; do
391 # Export index variable to child process
392 export GTEST_SHARD_INDEX
393 TEST_STDOUT_FILENAME="${UT_REPORT_PATH:-kleidiai_results-${UT_VARIANT_NAME}}${GTEST_SHARD_INDEX}.log"
394 echo "Running iteration $GTEST_SHARD_INDEX of $GTEST_TOTAL_SHARDS"
395 set +e
396 KLEIDIAI_TEST_CI_QUIET=${KLEIDIAI_TEST_CI_QUIET:-1} ${UT_BINARY_PATH:-./build-${UT_VARIANT_NAME}}/kleidiai_test --gtest_brief=1 --gtest_output=xml:${UT_REPORT_PATH:-kleidiai_results-${UT_VARIANT_NAME}}${GTEST_SHARD_INDEX}.xml --gtest_random_seed=${GLOBAL_TEST_SEED:-42} ${UT_EXTRA_ARGS:-} > "${TEST_STDOUT_FILENAME}" 2>&1
397 TEST_EXIT_CODE=$?
398 set -e
399 grep -E '^\[==========\]|^\[ PASSED \]|^\[ FAILED \]|^\[ SKIPPED \]|^Test seed|^[[:space:]]+[0-9]+ - ' "${TEST_STDOUT_FILENAME}" || true
400 if [ "${TEST_EXIT_CODE}" -ne 0 ]; then
401 if [ -f tools/ci/summarise_gtest.py ]; then
402 python3 tools/ci/summarise_gtest.py "${UT_REPORT_PATH:-kleidiai_results-${UT_VARIANT_NAME}}${GTEST_SHARD_INDEX}.xml" || true
403 else
404 echo "JUnit summary unavailable: tools/ci/summarise_gtest.py not found"
405 fi
406 echo "Test shard failed; last 200 output lines from ${TEST_STDOUT_FILENAME}:"
407 tail -200 "${TEST_STDOUT_FILENAME}" || true
408 exit "${TEST_EXIT_CODE}"
409 fi
410 done
411
412# Purpose: Sharded unit tests for each build provider.
413test-linux-aarch64:
414 extends:
415 - .stable-rules
416 stage: test
417 parallel:
418 matrix:
419 # All current build jobs
420 - BUILD_JOB_PROVIDER: [ clang, gcc, clang-bazel, gcc-bazel ]
421 needs:
422 # A CI system limitation does not allow usage of matrix variables to avoid fetching unnecessary artifacts.
423 # So make sure to fetch artifacts from all jobs required.
424 - build-gcc
425 - build-gcc-bazel
426 - build-clang
427 - build-clang-bazel
428 script:
429 # Explicitly configure overflow protection for public unit tests.
430 # The shared unit-test runner requires this variable to be set.
431 - |
432 export KAI_TEST_BUFFER_POLICY=PROTECT_OVERFLOW
433 UT_VARIANT_NAME=$BUILD_JOB_PROVIDER
434 UT_REPORT_PATH=kleidiai_test_results-${BUILD_JOB_PROVIDER}
435 # Export UT_REPORT_PATH to CI env to use in artifacts
436 echo "UT_REPORT_PATH=$UT_REPORT_PATH" >> $GITLAB_ENV
437 - *run-unit-tests
438 artifacts:
439 when: always
440 expire_in: 1 day
441 paths:
442 - ${UT_REPORT_PATH}*.xml
443 - ${UT_REPORT_PATH}*.log
444 reports:
445 junit: ${UT_REPORT_PATH}*.xml
446
447# Purpose: Specialization of test-linux-aarch64 to run only SVE 256-bit VL unit test subset
448test-linux-aarch64-sve256:
449 extends:
450 - test-linux-aarch64
451 variables:
452 # Generation 7 is the instance with SVE VL 256
453 KUBERNETES_NODE_SELECTOR_INSTANCE_GENERATION: "karpenter.k8s.aws/instance-generation=7"
454 # Run only SVE unit tests
455 GTEST_FILTER: "*_sve_*"
456
457# Base template: .test-linux-aarch64-fvp
458# Purpose: Common FVP unit-test runner for feature-specific tests.
459.test-linux-aarch64-fvp:
460 extends:
461 - .stable-rules
462 stage: test
463 parallel:
464 matrix:
465 - BUILD_JOB_PROVIDER: [ clang, gcc, clang-bazel, gcc-bazel ]
466 needs:
467 - build-gcc
468 - build-gcc-bazel
469 - build-clang
470 - build-clang-bazel
471 variables:
472 # Long test requires more stable node
473 KUBERNETES_NODE_SELECTOR_TYPE: "karpenter.sh/capacity-type=on-demand"
474 FVP_TEST_EXECUTABLE: "./build-${BUILD_JOB_PROVIDER}/kleidiai_test --gtest_brief=1 --gtest_output=xml:kleidiai_test_results-${BUILD_JOB_PROVIDER}.xml --gtest_random_seed=${GLOBAL_TEST_SEED:-42}"
475 script:
476 - ./tools/fvp.sh ${FVP_TEST_EXECUTABLE}
477 artifacts:
478 when: always
479 expire_in: 1 day
480 paths:
481 - kleidiai_test_results-${BUILD_JOB_PROVIDER}.xml
482 reports:
483 junit: kleidiai_test_results-${BUILD_JOB_PROVIDER}.xml
484
485# Purpose: FVP feature tests with disabled SVE/SVE2 but enabled SME/SME2
486# Disabled at the moment due to huge amount of SME/SME2 kernels
487.test-linux-aarch64-fvp-nosve:
488 extends:
489 - .test-linux-aarch64-fvp
490 variables:
491 # Disable SVE/SVE2, but keep SME/SME2
492 FVP_MODEL_EXTRA: "-C cluster0.sve.has_sve2=0 -C cluster0.sve.sme_only=1"
493
494# Purpose: FVP SVE2.1 unit tests.
495test-linux-aarch64-sve2p1-fvp:
496 extends:
497 - .test-linux-aarch64-fvp
498 timeout: 1h
499 variables:
500 # Enable SVE2.1 support explicitly for this feature-specific FVP run.
501 FVP_MODEL_EXTRA: "-C cluster0.sve.has_sve2=1 -C cluster0.sve.sve2_version=1"
502 # Run only SVE2.1 unit tests.
503 GTEST_FILTER: "*sve2p1*"
504 FVP_TEST_EXECUTABLE: "KLEIDIAI_TEST_CI_QUIET=1 ./build-${BUILD_JOB_PROVIDER}/kleidiai_test --gtest_brief=1 --test_size small --gtest_output=xml:kleidiai_test_results-${BUILD_JOB_PROVIDER}.xml --gtest_random_seed=${GLOBAL_TEST_SEED:-42}"
505 script:
506 - ./tools/fvp.sh -- "${FVP_TEST_EXECUTABLE}" | tee output.txt
507 - "grep -qE 'Features\\s+:.*sve2p1' output.txt"
508 artifacts:
509 when: always
510 expire_in: 1 day
511 paths:
512 - kleidiai_test_results-${BUILD_JOB_PROVIDER}.xml
513 - output.txt
514 reports:
515 junit: kleidiai_test_results-${BUILD_JOB_PROVIDER}.xml
516
517# Purpose: FVP v8-only model; expect Illegal instruction for examples; validates CPU feature detection path.
518test-linux-aarch64-v8only-fvp:
519 extends:
520 - .stable-rules
521 stage: test
522 needs:
523 - build-clang
524 - build-examples
525 script:
526 # Make sure to match disabled V8 and V9 version to enabled in tools/fvp.sh, otherwise the test would fail
527 - >
528 export FVP_MODEL_EXTRA="
529 -C cluster0.has_arm_v8-1=0
530 -C cluster0.has_arm_v8-2=0
531 -C cluster0.has_arm_v8-3=0
532 -C cluster0.has_arm_v8-4=0
533 -C cluster0.has_arm_v8-5=0
534 -C cluster0.has_arm_v8-6=0
535 -C cluster0.has_arm_v8-7=0
536 -C cluster0.has_arm_v8-8=0
537 -C cluster0.has_arm_v8-9=0
538 -C cluster0.has_arm_v9-0=0
539 -C cluster0.has_arm_v9-1=0
540 -C cluster0.has_arm_v9-2=0
541 -C cluster0.has_arm_v9-3=0
542 -C cluster0.has_arm_v9-4=0
543 -C cluster0.has_arm_v9-5=0
544 -C cluster0.has_arm_v9-6=0
545 -C cluster0.has_sve=0"
546 # Generate test script with negative and positive tests
547 - |
548 echo -e "#\!/bin/bash -ex" > run_tests.sh
549 echo "echo Perform a negative test with illegal instructions" >> run_tests.sh
550 find build -type f -perm -a=x -print0 | \
551 while read -d '' EXAMPLE; do
552 echo -e "echo \"Run '${EXAMPLE}'\"" >> run_tests.sh
553 echo -e "./'${EXAMPLE}' || true" >> run_tests.sh # Allow failure (expected crash).
554 done
555 echo "echo Perform a positive test with CPU feature detection" >> run_tests.sh
556 echo "KLEIDIAI_TEST_CI_QUIET=1 ./build-clang/kleidiai_test --gtest_brief=1 --gtest_random_seed=\${GLOBAL_TEST_SEED:-42} || exit 1" >> run_tests.sh # Must succeed.
557 # Dump content for debugging purposes
558 - |
559 echo "Test script content:"
560 cat run_tests.sh
561 # Execute test script in FVP and capture output for feature assertions
562 - chmod a+x run_tests.sh
563 - ./tools/fvp.sh ./run_tests.sh | tee output.txt
564 # Verify that no extra features enabled and CPU variant is v8.0
565 - "grep -qE 'Features\\s+: fp asimd evtstrm cpuid' output.txt"
566 - "grep -qE 'CPU variant\\s+: 0' output.txt"
567 # Verify that all examples crashed with Illegal instruction (negative path coverage)
568 - test $(grep -cE "Illegal instruction\s+./'build/" output.txt) -eq $(ls -1 build | wc -l | tr -d ' ')
569
570# Purpose: FVP with only SME enabled (SME2 disabled); SME example runs.
571test-linux-aarch64-sme1only-fvp:
572 extends:
573 - .stable-rules
574 timeout: 1h
575 stage: test
576 needs:
577 - build-clang
578 - build-examples
579 script:
580 # Disable SME2 in FVP
581 - >
582 export FVP_MODEL_EXTRA="
583 -C cluster0.sve.has_sme2=0
584 -C cluster0.sve.sme2_version=0" # Disable SME2.
585 # Generate test script
586 - |
587 echo -e "#\!/bin/bash -ex" > run_tests.sh
588 echo "echo Run SME examples" >> run_tests.sh
589 # Find any SME examples and execute them
590 find build -type f -perm -a=x \( -name \*_sme -o -name \*_sme_\* \) -print0 | \
591 while read -d '' EXAMPLE; do
592 echo -e "echo \"Run '${EXAMPLE}'\"" >> run_tests.sh
593 echo -e "./'${EXAMPLE}' || exit 1" >> run_tests.sh
594 done
595 # Dump content for debugging purposes
596 - |
597 echo "Test script content:"
598 cat run_tests.sh
599 - chmod a+x run_tests.sh
600 # Execute test script in FVP and capture output for feature assertions
601 - FVP_TEST_EXECUTABLE="./run_tests.sh"
602 - ./tools/fvp.sh ${FVP_TEST_EXECUTABLE} | tee output.txt
603 # Verify that SME2 is not available
604 - "grep -qv 'sme2' output.txt"
605 artifacts:
606 when: always
607 expire_in: 1 day
608 paths:
609 - output.txt
610
611# Purpose: Execute all SME examples under FVP; consolidate output into single log.
612test-examples-sme-fvp:
613 extends:
614 - .stable-rules
615 stage: test
616 needs:
617 - build-examples
618 script:
619 # Generate test script with negative and positive tests
620 - |
621 echo -e "#\!/bin/bash -ex" > run_tests.sh
622 find build -type f -perm -a=x -name \*_sme\* -print0 | \
623 while read -d '' EXAMPLE; do
624 echo "echo ---------------------------------------------------" >> run_tests.sh
625 echo "echo Run '${EXAMPLE}'" >> run_tests.sh
626 echo "echo ---------------------------------------------------" >> run_tests.sh
627 echo "./'${EXAMPLE}' | tee -a example.log" >> run_tests.sh
628 done
629 # Dump content for debugging purposes
630 - |
631 echo "Test script content:"
632 cat run_tests.sh
633 # Execute test script in FVP and capture output for feature assertions
634 - chmod a+x run_tests.sh
635 - ./tools/fvp.sh ./run_tests.sh
636 artifacts:
637 when: always
638 expire_in: 1 day
639 paths:
640 - example.log
641
642# Purpose: Resolve and lock gcovr version for consistent coverage reporting.
643resolve-gcovr:
644 extends: .stable-rules
645 stage: analyze
646 needs: []
647 variables:
648 PIP_CACHE_DIR: ".cache/pip3"
649 cache:
650 - key: "cache-pip3"
651 paths:
652 - $PIP_CACHE_DIR
653 policy: $CACHE_POLICY
654 script:
655 # Install latest gcovr once, then record the exact version
656 - python3 -m pip install --cache-dir=$PIP_CACHE_DIR --user -U --break-system-packages gcovr
657 - export PATH="$(python3 -m site --user-base)/bin:${PATH}"
658 - GCOVR_VERSION=$(gcovr --version | awk 'NR==1 {print $2; exit}')
659 - echo "GCOVR_VERSION=${GCOVR_VERSION}" | tee gcovr.env
660 artifacts:
661 paths:
662 - gcovr.env
663
664# Base template: .gcovr-install
665# Purpose: Install cached gcovr version from resolve-gcovr job.
666.gcovr-install:
667 variables:
668 PIP_CACHE_DIR: ".cache/pip3"
669 cache:
670 - key: "cache-pip3"
671 paths:
672 - $PIP_CACHE_DIR
673 policy: $CACHE_POLICY
674 before_script:
675 # Prefer Homebrew python3.13 -> 3.10 on macOS, otherwise keep python3 on PATH
676 - |
677 PYTHON_BIN="python3"
678 if [ "$(uname)" = "Darwin" ]; then
679 export PATH="/opt/homebrew/bin:/usr/local/bin:${PATH}"
680 for ver in 3.13 3.12 3.11 3.10; do
681 if [ -x "/opt/homebrew/bin/python${ver}" ]; then
682 PYTHON_BIN="/opt/homebrew/bin/python${ver}"
683 break
684 fi
685 done
686 fi
687 # Ensure the selected python is present on PATH.
688 if ! command -v "${PYTHON_BIN}" >/dev/null 2>&1; then
689 echo "Missing ${PYTHON_BIN} on PATH" >&2
690 exit 1
691 fi
692 # Enforce minimum python version required by gcovr tooling.
693 if ! "$PYTHON_BIN" -c 'import sys; sys.exit(0 if sys.version_info >= (3, 10) else 1)'; then
694 echo "Python ${PYTHON_BIN} is too old; need >= 3.10" >&2
695 exit 1
696 fi
697 echo "Using python: ${PYTHON_BIN}"
698 "$PYTHON_BIN" -V
699
700 # Load the locked GCOVR_VERSION from resolve-gcovr
701 - |
702 if [ -f gcovr.env ]; then
703 set -a
704 . gcovr.env
705 set +a
706 echo "Using gcovr ${GCOVR_VERSION} from resolve-gcovr"
707 else
708 echo "gcovr.env not found; ensure resolve-gcovr is listed in needs." >&2
709 exit 1
710 fi
711
712 # Install pip + gcovr==$GCOVR_VERSION
713 - |
714 if "$PYTHON_BIN" -m pip help install 2>&1 | grep -q -- "--break-system-packages"; then
715 PIP_BREAK_SYSTEM_PACKAGES_FLAG="--break-system-packages"
716 else
717 PIP_BREAK_SYSTEM_PACKAGES_FLAG=""
718 fi
719 $PYTHON_BIN -m pip install --cache-dir=$PIP_CACHE_DIR --user -U ${PIP_BREAK_SYSTEM_PACKAGES_FLAG} pip
720 $PYTHON_BIN -m pip install --cache-dir=$PIP_CACHE_DIR --user ${PIP_BREAK_SYSTEM_PACKAGES_FLAG} "gcovr==${GCOVR_VERSION}"
721 - export PATH="$("$PYTHON_BIN" -m site --user-base)/bin:${PATH}"
722
723 # Sanity check the installed gcovr version
724 - |
725 (
726 set -euo pipefail
727 INSTALLED_GCOVR_VERSION=$(gcovr --version | awk 'NR==1 {print $2; exit}')
728 echo "gcovr ${INSTALLED_GCOVR_VERSION}"
729 if [ "${INSTALLED_GCOVR_VERSION}" != "${GCOVR_VERSION}" ]; then
730 echo "Expected gcovr ${GCOVR_VERSION} but found ${INSTALLED_GCOVR_VERSION}" >&2
731 exit 1
732 fi
733 )
734
735# Base template: .coverage-base
736# Purpose: Instrumented build & diversified benchmark/test execution producing per-job JSON coverage trace.
737.coverage-base:
738 extends:
739 - .stable-rules
740 needs: []
741 variables:
742 GCOV_EXECUTABLE: ""
743 script:
744 # Configure and build with coverage instrumentation
745 - cmake -G Ninja -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++
746 -DCMAKE_CXX_FLAGS="-Werror --coverage" -DCMAKE_C_FLAGS="-Werror --coverage" -DCMAKE_BUILD_TYPE=Release
747 -DKLEIDIAI_BUILD_TESTS=ON -DKLEIDIAI_BUILD_BENCHMARK=ON
748 ${CMAKE_EXTRA_FLAGS}
749 -S . -B ${CI_JOB_NAME_SLUG}
750 - cmake --build ${CI_JOB_NAME_SLUG} -j${PARALLEL_JOBS} --verbose
751 # Run kleidiai_test to generate coverage report for unit tests
752 - KLEIDIAI_TEST_CI_QUIET=${KLEIDIAI_TEST_CI_QUIET:-1} ./${CI_JOB_NAME_SLUG}/kleidiai_test --gtest_brief=1 --gtest_random_seed=${GLOBAL_TEST_SEED:-42}
753 # Run combined benchmark for all subcommands (backwards compatibility, matmul, imatmul, dwconv)
754 - |
755 declare -a BENCHMARKS=(
756 "" "--benchmark_dry_run=true -m 1 -n 30 -k 64"
757 "matmul" "--benchmark_dry_run=true -m 1 -n 30 -k 64"
758 "pack_matmul" "--benchmark_dry_run=true -m 1 -n 30 -k 64"
759 "imatmul" "--benchmark_dry_run=true -m 1 -n 30 -c 4 -l 15"
760 "dwconv" "--benchmark_dry_run=true --input_height 32 --input_width 32 --channels 64 --padding 1,1,1,1"
761 )
762 for ((i=0; i<${#BENCHMARKS[@]}; i+=2)); do
763 KT="${BENCHMARKS[i]}"
764 ARGS="${BENCHMARKS[i+1]}"
765 # Run benchmark
766 if [ -z "$KT" ]; then
767 ./${CI_JOB_NAME_SLUG}/kleidiai_benchmark $ARGS > /dev/null 2>&1
768 ./${CI_JOB_NAME_SLUG}/kleidiai_benchmark --benchmark_list_tests > /dev/null 2>&1
769 ./${CI_JOB_NAME_SLUG}/kleidiai_benchmark > /dev/null 2>&1 || true
770 else
771 ./${CI_JOB_NAME_SLUG}/kleidiai_benchmark $KT $ARGS > /dev/null 2>&1
772 ./${CI_JOB_NAME_SLUG}/kleidiai_benchmark $KT --benchmark_list_tests > /dev/null 2>&1
773 ./${CI_JOB_NAME_SLUG}/kleidiai_benchmark $KT > /dev/null 2>&1 || true
774 fi
775 done
776 # Generate gcovr configuration tuned to exclude build dir, unreachable branches, and assertion macros.
777 - mkdir -p build/coverage
778 - |
779 echo -e "
780 root=${PWD}
781 exclude=${PWD}/${CI_JOB_NAME_SLUG}
782 gcov-ignore-parse-errors=suspicious_hits.warn
783 gcov-executable=$GCOV_EXECUTABLE
784 exclude-unreachable-branches=yes
785 exclude-lines-by-pattern=.*KAI_(?:ASSERT|ASSUME|ERROR).*
786 exclude-branches-by-pattern=.*KAI_(?:ASSERT|ASSUME).*" > build/gcovr.cfg
787 # Post-process generated coverage report into JSON for later aggregation.
788 - gcovr --json=build/coverage/${CI_JOB_NAME_SLUG}.json -j ${PARALLEL_JOBS} --config build/gcovr.cfg --merge-mode-functions=merge-use-line-min
789 artifacts:
790 expire_in: 1 day
791 paths:
792 - build/coverage/${CI_JOB_NAME_SLUG}.json
793
794# Purpose: Coverage generation using llvm-cov gcov with cached gcovr install.
795coverage-linux:
796 extends:
797 - .coverage-base
798 - .gcovr-install
799 stage: analyze
800 needs:
801 - resolve-gcovr
802 variables:
803 GCOV_EXECUTABLE: "llvm-cov gcov"
804
805# Purpose: SVE256 coverage variant (focus on *_sve_* tests) to extend line/function coverage set.
806coverage-linux-sve256:
807 extends:
808 - coverage-linux
809 variables:
810 # Use instance with SVE VL 256
811 KUBERNETES_NODE_SELECTOR_INSTANCE_GENERATION: "karpenter.k8s.aws/instance-generation=7"
812 GTEST_FILTER: "*_sve_*"
813
814# Purpose: Coverage build for SME/SME2 architecture.
815coverage-clang:
816 extends:
817 - .coverage-base
818 - .gcovr-install
819 stage: analyze
820 needs:
821 - resolve-gcovr
822 tags:
823 - apple_silicon
824 variables:
825 GCOV_EXECUTABLE: "xcrun llvm-cov gcov"
826 CMAKE_EXTRA_FLAGS: "-DKLEIDIAI_INTERNAL_EXTRA_ARCH='+sme'"
827
828# Purpose: Aggregate all JSON coverage traces into Cobertura & HTML reports for publication.
829coverage:
830 extends:
831 - .stable-rules
832 - .gcovr-install
833 stage: deploy
834 needs:
835 - resolve-gcovr
836 - coverage-linux
837 - coverage-linux-sve256
838 - coverage-clang
839 tags:
840 - apple_silicon
841 script:
842 # Generage Cobertura and HTML reports merging coverage across variants,
843 # where each variant artifact should be stored in JSON file at build/coverage/
844 # Merge different reports with merge-lines and separate function coverage with same name.
845 # It's required to handle different build/OS options properly.
846 - mkdir -p build/html/coverage
847 - gcovr --json-add-tracefile "build/coverage/*.json" --print-summary
848 --cobertura=build/coverage.xml --html-details=build/html/coverage/coverage_report.html
849 --html-title="KleidiAI Coverage Report" --merge-mode-functions=separate --merge-lines
850 -j ${PARALLEL_JOBS}
851 # Publish line coverage metric for pipeline reports
852 coverage: '/^lines:\s+(\d+.\d)%\s+/'
853 artifacts:
854 name: ${CI_JOB_NAME}-${CI_COMMIT_REF_NAME}-${CI_COMMIT_SHA}
855 expire_in: 1 day
856 reports:
857 # Publish coverage report for MR visualisation
858 coverage_report:
859 coverage_format: cobertura
860 path: build/coverage.xml
861 paths:
862 - build
863
864# Purpose: Publish coverage HTML via Pages (index auto-redirects to detailed report).
865pages:
866 rules:
867 - if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
868 timeout: 30m
869 stage: deploy
870 tags:
871 - apple_silicon
872 needs:
873 - coverage
874 script:
875 # Generate simple redirect page
876 - |
877 echo '
878 <!DOCTYPE html>
879 <html>
880 <head>
881 <meta http-equiv="refresh" content="5; url=coverage/coverage_report.html" />
882 <title>Redirecting...</title>
883 </head>
884 <body>
885 <p>If you are not redirected soon, <a href="coverage/coverage_report.html">click here</a>.</p>
886 </body>
887 </html>' > build/html/index.html
888 artifacts:
889 paths:
890 - build/html
891 publish: build/html