Skip to content

Commit 30343b3

Browse files
committed
ci: scope clang-tidy PR and filter compile-db files
1 parent f5aedce commit 30343b3

File tree

2 files changed

+72
-24
lines changed

2 files changed

+72
-24
lines changed

.github/workflows/clang_tidy.yml

Lines changed: 60 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -67,17 +67,70 @@ jobs:
6767
**/*.cc
6868
**/*.cpp
6969
**/*.cxx
70-
**/*.h
71-
**/*.hpp
7270
!thirdparty/**
7371
!build/**
7472
separator: "\n"
7573

76-
- name: Run clang-tidy
74+
- name: Filter changed files to compile database entries
75+
id: tidy_files
7776
if: steps.changed_files.outputs.any_changed == 'true'
77+
run: |
78+
python3 - <<'PY'
79+
import json
80+
import os
81+
from pathlib import Path
82+
83+
changed = [line.strip() for line in """${{ steps.changed_files.outputs.all_changed_files }}""".splitlines() if line.strip()]
84+
compile_db_path = Path("build/compile_commands.json")
85+
with compile_db_path.open("r", encoding="utf-8") as f:
86+
compile_db = json.load(f)
87+
88+
compile_entries = set()
89+
for entry in compile_db:
90+
file_path = entry.get("file")
91+
if not file_path:
92+
continue
93+
normalized = os.path.normpath(file_path).replace("\\", "/")
94+
compile_entries.add(normalized)
95+
96+
selected = []
97+
skipped = []
98+
cwd = Path.cwd()
99+
for file_path in changed:
100+
if not Path(file_path).is_file():
101+
skipped.append(f"{file_path} (missing)")
102+
continue
103+
104+
abs_normalized = os.path.normpath(str((cwd / file_path).resolve())).replace("\\", "/")
105+
rel_normalized = os.path.normpath(file_path).replace("\\", "/")
106+
107+
if abs_normalized in compile_entries or rel_normalized in compile_entries:
108+
selected.append(file_path)
109+
else:
110+
skipped.append(f"{file_path} (no compile_commands entry)")
111+
112+
output_path = os.environ["GITHUB_OUTPUT"]
113+
with open(output_path, "a", encoding="utf-8") as out:
114+
out.write(f"any_tidy_files={'true' if selected else 'false'}\n")
115+
out.write("all_tidy_files<<EOF\n")
116+
out.write("\n".join(selected))
117+
out.write("\nEOF\n")
118+
out.write("skipped_files<<EOF\n")
119+
out.write("\n".join(skipped))
120+
out.write("\nEOF\n")
121+
PY
122+
123+
- name: Show skipped files
124+
if: steps.changed_files.outputs.any_changed == 'true' && steps.tidy_files.outputs.skipped_files != ''
125+
run: |
126+
echo "Skipping files:"
127+
printf '%s\n' "${{ steps.tidy_files.outputs.skipped_files }}"
128+
129+
- name: Run clang-tidy
130+
if: steps.tidy_files.outputs.any_tidy_files == 'true'
78131
run: |
79132
mapfile -t changed_files <<'EOF'
80-
${{ steps.changed_files.outputs.all_changed_files }}
133+
${{ steps.tidy_files.outputs.all_tidy_files }}
81134
EOF
82135
83136
for file in "${changed_files[@]}"; do
@@ -87,7 +140,7 @@ jobs:
87140
fi
88141
done
89142
90-
- name: No changed C/C++ files
91-
if: steps.changed_files.outputs.any_changed != 'true'
143+
- name: No clang-tidy files to analyze
144+
if: steps.changed_files.outputs.any_changed != 'true' || steps.tidy_files.outputs.any_tidy_files != 'true'
92145
run: |
93-
echo "No changed C/C++ files matched clang-tidy patterns."
146+
echo "No changed source files with compile_commands entries matched clang-tidy patterns."

tests/ailego/math/euclidean_distance_matrix_fp16_test.cc

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
// limitations under the License.
1414

1515
#include <functional>
16-
#include <cstdint>
1716
#include <random>
1817
#include <string>
1918
#include <thread>
@@ -136,8 +135,7 @@ TEST(DistanceMatrix, SquaredEuclidean_General) {
136135

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

142140
const size_t batch_size = M;
143141
const size_t query_size = N;
@@ -176,15 +174,13 @@ void TestEuclideanMatrix(void) {
176174

177175
for (size_t i = 0; i < batch_size * query_size; ++i) {
178176
// EXPECT_FLOAT_EQ(result1[i], result2[i]);
179-
EXPECT_TRUE(MathHelper::IsAlmostEqual(
180-
result1[i], result2[i], kFp16MatrixUlpTolerance));
177+
EXPECT_TRUE(MathHelper::IsAlmostEqual(result1[i], result2[i], 10000));
181178
}
182179
}
183180

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

189185
const size_t batch_size = M;
190186
const size_t query_size = N;
@@ -223,8 +219,7 @@ void TestSquaredEuclideanMatrix(void) {
223219

224220
for (size_t i = 0; i < batch_size * query_size; ++i) {
225221
// EXPECT_FLOAT_EQ(result1[i], result2[i]);
226-
EXPECT_TRUE(MathHelper::IsAlmostEqual(
227-
result1[i], result2[i], kFp16MatrixUlpTolerance));
222+
EXPECT_TRUE(MathHelper::IsAlmostEqual(result1[i], result2[i], 10000));
228223
}
229224
}
230225

@@ -559,7 +554,7 @@ void EuclideanBenchmark(void) {
559554

560555
std::cout << "# (" << IntelIntrinsics() << ") FP16 " << dimension << "d, "
561556
<< batch_size << " * " << query_size << " * " << block_size
562-
<< '\n';
557+
<< std::endl;
563558

564559
// 1 Batched Euclidean
565560
elapsed_time.reset();
@@ -575,7 +570,7 @@ void EuclideanBenchmark(void) {
575570
}
576571
}
577572
std::cout << "* 1 Batched Euclidean (us) \t" << elapsed_time.micro_seconds()
578-
<< '\n';
573+
<< std::endl;
579574

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

591586
// Unbatched Euclidean
592587
elapsed_time.reset();
@@ -605,7 +600,7 @@ void EuclideanBenchmark(void) {
605600
}
606601
}
607602
std::cout << "* Unbatched Euclidean (us) \t" << elapsed_time.micro_seconds()
608-
<< '\n';
603+
<< std::endl;
609604
}
610605

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

644639
std::cout << "# (" << IntelIntrinsics() << ") FP16 " << dimension << "d, "
645640
<< batch_size << " * " << query_size << " * " << block_size
646-
<< '\n';
641+
<< std::endl;
647642

648643
// 1 Batched Euclidean
649644
elapsed_time.reset();
@@ -659,7 +654,7 @@ void SquaredEuclideanBenchmark(void) {
659654
}
660655
}
661656
std::cout << "* 1 Batched SquaredEuclidean (us) \t"
662-
<< elapsed_time.micro_seconds() << '\n';
657+
<< elapsed_time.micro_seconds() << std::endl;
663658

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

675670
// Unbatched Euclidean
676671
elapsed_time.reset();
@@ -689,7 +684,7 @@ void SquaredEuclideanBenchmark(void) {
689684
}
690685
}
691686
std::cout << "* Unbatched SquaredEuclidean (us) \t"
692-
<< elapsed_time.micro_seconds() << '\n';
687+
<< elapsed_time.micro_seconds() << std::endl;
693688
}
694689

695690
TEST(DistanceMatrix, DISABLED_Euclidean_Benchmark) {

0 commit comments

Comments
 (0)