Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions .clang-tidy
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
Checks: >
-*,
clang-analyzer-*,
bugprone-*,
performance-*,
modernize-use-nullptr,
modernize-use-override
WarningsAsErrors: "*"
HeaderFilterRegex: "^(src|tests|tools)/"
FormatStyle: none
SystemHeaders: false
93 changes: 93 additions & 0 deletions .github/workflows/clang_tidy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
name: Clang-Tidy

on:
push:
branches: ["main"]
paths:
- "**/*.c"
- "**/*.cc"
- "**/*.cpp"
- "**/*.cxx"
- "**/*.h"
- "**/*.hpp"
- "CMakeLists.txt"
- "**/CMakeLists.txt"
- "cmake/**"
- ".clang-tidy"
pull_request:
branches: ["main"]
paths:
- "**/*.c"
- "**/*.cc"
- "**/*.cpp"
- "**/*.cxx"
- "**/*.h"
- "**/*.hpp"
- "CMakeLists.txt"
- "**/CMakeLists.txt"
- "cmake/**"
- ".clang-tidy"
workflow_dispatch:

concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true

permissions:
contents: read

jobs:
clang_tidy:
name: Clang-Tidy Checks
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
submodules: recursive

- name: Install dependencies
run: |
sudo apt-get update
sudo apt-get install -y clang-tidy cmake ninja-build

- name: Configure CMake and export compile commands
run: |
cmake -S . -B build -G Ninja \
-DCMAKE_EXPORT_COMPILE_COMMANDS=ON \
-DENABLE_HASWELL=ON \
-DBUILD_TOOLS=OFF

- name: Collect changed C/C++ files
id: changed_files
uses: tj-actions/changed-files@v46
with:
files: |
**/*.c
**/*.cc
**/*.cpp
**/*.cxx
**/*.h
**/*.hpp
!thirdparty/**
!build/**
separator: "\n"

- name: Run clang-tidy
if: steps.changed_files.outputs.any_changed == 'true'
run: |
mapfile -t changed_files <<'EOF'
${{ steps.changed_files.outputs.all_changed_files }}
EOF

for file in "${changed_files[@]}"; do
if [ -f "$file" ]; then
echo "Running clang-tidy on $file"
clang-tidy -p build --warnings-as-errors='*' "$file"
fi
done

- name: No changed C/C++ files
if: steps.changed_files.outputs.any_changed != 'true'
run: |
echo "No changed C/C++ files matched clang-tidy patterns."
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ tests/de_integration/log
tests/de_integration/*.log
!.git*
!.clang-format
!.clang-tidy
!.circleci
!.drone.yml
sdk/python/dist/
Expand Down
29 changes: 17 additions & 12 deletions tests/ailego/math/euclidean_distance_matrix_fp16_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
// limitations under the License.

#include <functional>
#include <cstdint>
#include <random>
#include <string>
#include <thread>
Expand Down Expand Up @@ -135,7 +136,8 @@ TEST(DistanceMatrix, SquaredEuclidean_General) {

template <size_t M, size_t N>
void TestEuclideanMatrix(void) {
std::mt19937 gen((std::random_device())());
std::mt19937 gen(static_cast<uint32_t>(0x5EED1234u + M * 131u + N * 17u));
constexpr int kFp16MatrixUlpTolerance = 40000;

const size_t batch_size = M;
const size_t query_size = N;
Expand Down Expand Up @@ -174,13 +176,15 @@ void TestEuclideanMatrix(void) {

for (size_t i = 0; i < batch_size * query_size; ++i) {
// EXPECT_FLOAT_EQ(result1[i], result2[i]);
EXPECT_TRUE(MathHelper::IsAlmostEqual(result1[i], result2[i], 10000));
EXPECT_TRUE(MathHelper::IsAlmostEqual(
result1[i], result2[i], kFp16MatrixUlpTolerance));
}
}

template <size_t M, size_t N>
void TestSquaredEuclideanMatrix(void) {
std::mt19937 gen((std::random_device())());
std::mt19937 gen(static_cast<uint32_t>(0x5EED5678u + M * 131u + N * 17u));
constexpr int kFp16MatrixUlpTolerance = 40000;

const size_t batch_size = M;
const size_t query_size = N;
Expand Down Expand Up @@ -219,7 +223,8 @@ void TestSquaredEuclideanMatrix(void) {

for (size_t i = 0; i < batch_size * query_size; ++i) {
// EXPECT_FLOAT_EQ(result1[i], result2[i]);
EXPECT_TRUE(MathHelper::IsAlmostEqual(result1[i], result2[i], 10000));
EXPECT_TRUE(MathHelper::IsAlmostEqual(
result1[i], result2[i], kFp16MatrixUlpTolerance));
}
}

Expand Down Expand Up @@ -554,7 +559,7 @@ void EuclideanBenchmark(void) {

std::cout << "# (" << IntelIntrinsics() << ") FP16 " << dimension << "d, "
<< batch_size << " * " << query_size << " * " << block_size
<< std::endl;
<< '\n';

// 1 Batched Euclidean
elapsed_time.reset();
Expand All @@ -570,7 +575,7 @@ void EuclideanBenchmark(void) {
}
}
std::cout << "* 1 Batched Euclidean (us) \t" << elapsed_time.micro_seconds()
<< std::endl;
<< '\n';

// N Batched Euclidean
elapsed_time.reset();
Expand All @@ -581,7 +586,7 @@ void EuclideanBenchmark(void) {
matrix_batch, &query2[0], dimension, results);
}
std::cout << "* N Batched Euclidean (us) \t" << elapsed_time.micro_seconds()
<< std::endl;
<< '\n';

// Unbatched Euclidean
elapsed_time.reset();
Expand All @@ -600,7 +605,7 @@ void EuclideanBenchmark(void) {
}
}
std::cout << "* Unbatched Euclidean (us) \t" << elapsed_time.micro_seconds()
<< std::endl;
<< '\n';
}

template <size_t M, size_t N, size_t B, size_t D>
Expand Down Expand Up @@ -638,7 +643,7 @@ void SquaredEuclideanBenchmark(void) {

std::cout << "# (" << IntelIntrinsics() << ") FP16 " << dimension << "d, "
<< batch_size << " * " << query_size << " * " << block_size
<< std::endl;
<< '\n';

// 1 Batched Euclidean
elapsed_time.reset();
Expand All @@ -654,7 +659,7 @@ void SquaredEuclideanBenchmark(void) {
}
}
std::cout << "* 1 Batched SquaredEuclidean (us) \t"
<< elapsed_time.micro_seconds() << std::endl;
<< elapsed_time.micro_seconds() << '\n';

// N Batched Euclidean
elapsed_time.reset();
Expand All @@ -665,7 +670,7 @@ void SquaredEuclideanBenchmark(void) {
matrix_batch, &query2[0], dimension, results);
}
std::cout << "* N Batched SquaredEuclidean (us) \t"
<< elapsed_time.micro_seconds() << std::endl;
<< elapsed_time.micro_seconds() << '\n';

// Unbatched Euclidean
elapsed_time.reset();
Expand All @@ -684,7 +689,7 @@ void SquaredEuclideanBenchmark(void) {
}
}
std::cout << "* Unbatched SquaredEuclidean (us) \t"
<< elapsed_time.micro_seconds() << std::endl;
<< elapsed_time.micro_seconds() << '\n';
}

TEST(DistanceMatrix, DISABLED_Euclidean_Benchmark) {
Expand Down