Skip to content
Merged
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
49 changes: 48 additions & 1 deletion .clang-tidy
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,54 @@ Checks: >
modernize-use-equals-default,
modernize-use-equals-delete,
modernize-redundant-void-arg,
readability-identifier-naming,
WarningsAsErrors: "*"
HeaderFilterRegex: "^(src|tests|tools)/(?!db/sqlengine/antlr/gen/|db/index/column/fts_column/gen/|include/zvec/ailego/encoding/json/mod_json\\.h).*"
HeaderFilterRegex: "(^|/)(src|tests|tools)/"
FormatStyle: none
SystemHeaders: false
CheckOptions:
# Type-like identifiers use CamelCase (Google style). STL-compatible
# container aliases (iterator, value_type, *_t ...) are exempted.
readability-identifier-naming.NamespaceCase: lower_case
readability-identifier-naming.ClassCase: CamelCase
readability-identifier-naming.ClassIgnoredRegexp: '(const_)?(iterator|reverse_iterator)'
readability-identifier-naming.StructCase: CamelCase
readability-identifier-naming.StructIgnoredRegexp: '(const_)?(iterator|reverse_iterator)'
readability-identifier-naming.UnionCase: CamelCase
readability-identifier-naming.EnumCase: CamelCase
readability-identifier-naming.TypedefCase: CamelCase
readability-identifier-naming.TypedefIgnoredRegexp: '(_.*|[a-z][a-z0-9_]*|.*_t|.*_type|(const_)?(iterator|reverse_iterator|pointer|reference))'
readability-identifier-naming.TypeAliasCase: CamelCase
readability-identifier-naming.TypeAliasIgnoredRegexp: '(_.*|[a-z][a-z0-9_]*|.*_t|.*_type|(const_)?(iterator|reverse_iterator|pointer|reference))'
# Member functions use snake_case. Static/free/global functions may use
# snake_case or CamelCase. A leading underscore (private-method convention)
# or trailing underscore (keyword avoidance, e.g. delete_) is allowed.
readability-identifier-naming.MethodCase: lower_case
readability-identifier-naming.MethodIgnoredRegexp: '_*[a-z][a-z0-9_]*'
readability-identifier-naming.ClassMethodCase: lower_case
readability-identifier-naming.ClassMethodIgnoredRegexp: '(_*[a-z][a-z0-9_]*|[A-Z][A-Za-z0-9]*)'
readability-identifier-naming.FunctionCase: lower_case
readability-identifier-naming.FunctionIgnoredRegexp: '(_*[a-z][a-z0-9_]*|[A-Z][A-Za-z0-9]*)'
readability-identifier-naming.GlobalFunctionCase: lower_case
readability-identifier-naming.GlobalFunctionIgnoredRegexp: '(_*[a-z][a-z0-9_]*|[A-Z][A-Za-z0-9]*)'
# Data members use snake_case; a trailing underscore is allowed but not required.
readability-identifier-naming.MemberCase: lower_case
readability-identifier-naming.MemberIgnoredRegexp: '_*[a-z][a-z0-9]*(_[a-z0-9]+)*_*'
readability-identifier-naming.ConstantMemberCase: lower_case
readability-identifier-naming.ConstantMemberIgnoredRegexp: '_*[a-z][a-z0-9]*(_[a-z0-9]+)*_*'
# Static data members follow the same snake_case rule as non-static members.
readability-identifier-naming.ClassMemberCase: lower_case
readability-identifier-naming.ClassMemberIgnoredRegexp: '_*[a-z][a-z0-9]*(_[a-z0-9]+)*_*'
# Local variables and parameters use snake_case.
readability-identifier-naming.LocalVariableCase: lower_case
readability-identifier-naming.ParameterCase: lower_case
# Constants keep the existing mixed conventions (kCamelCase / UPPER_CASE /
# snake_case) and are intentionally not enforced.
readability-identifier-naming.ConstantCase: aNy_CasE
readability-identifier-naming.LocalConstantCase: aNy_CasE
readability-identifier-naming.StaticConstantCase: aNy_CasE
readability-identifier-naming.ClassConstantCase: aNy_CasE
readability-identifier-naming.GlobalConstantCase: aNy_CasE
readability-identifier-naming.ConstexprVariableCase: aNy_CasE
readability-identifier-naming.GlobalVariableCase: aNy_CasE
readability-identifier-naming.StaticVariableCase: aNy_CasE
34 changes: 29 additions & 5 deletions .github/workflows/clang_tidy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,17 @@ jobs:
selected = []
skipped = []

# Auto-generated code is exempt from clang-tidy and must not be edited.
generated_dir_markers = (
"src/db/sqlengine/antlr/gen/",
"src/db/index/column/fts_column/gen/",
)

for rel_path in changed:
norm_rel = rel_path.replace(os.sep, "/")
if any(marker in norm_rel for marker in generated_dir_markers):
skipped.append(f"{rel_path} (generated file, exempt from clang-tidy)")
continue
abs_path = os.path.normpath(str((cwd / rel_path).resolve()))
if abs_path in compile_entries:
selected.append(rel_path)
Expand Down Expand Up @@ -176,12 +186,26 @@ jobs:
failed=0
for f in "$log_dir"/*.log; do
[ -e "$f" ] || break
failed=1
src=$(head -1 "$f")
echo ""
echo "::group::clang-tidy errors: $src"
tail -n +2 "$f"
echo "::endgroup::"
# Diagnostics originating in generated headers (antlr/gen,
# fts_column/gen) can leak in via #include from non-generated main
# files. Those files are exempt and must not be edited, so drop such
# blocks; a log only counts as a failure if real diagnostics remain.
body=$(tail -n +2 "$f" | awk '
/^[^[:space:]].*:[0-9]+:[0-9]+: (warning|error|note):/ {
path = $0
sub(/:[0-9]+:[0-9]+:.*/, "", path)
skip = (path ~ /(antlr\/gen\/|fts_column\/gen\/)/) ? 1 : 0
}
{ if (!skip) print }
')
if printf '%s\n' "$body" | grep -qE ': (warning|error):'; then
failed=1
echo ""
echo "::group::clang-tidy errors: $src"
printf '%s\n' "$body"
echo "::endgroup::"
fi
done

rm -rf "$log_dir"
Expand Down
32 changes: 16 additions & 16 deletions src/ailego/algorithm/integer_quantizer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ static inline void ExpandCandidateDistribution(
*/
static inline size_t ComputeThreshold(const std::vector<uint32_t> &hist,
const size_t target_bins) {
std::vector<float> P_distribution(hist.size());
std::vector<float> p_distribution(hist.size());
size_t zero_point_index = hist.size() / 2;

size_t start_bin = target_bins / 2;
Expand All @@ -147,19 +147,19 @@ static inline size_t ComputeThreshold(const std::vector<uint32_t> &hist,
//! for each zero-axised quantization range: [-threshold, threshold], search
//! the best solution
for (size_t threshold = start_bin; threshold <= end_bin; ++threshold) {
P_distribution.resize(threshold * 2);
p_distribution.resize(threshold * 2);
auto p_hist = &hist[zero_point_index - threshold];
for (size_t i = 0; i != P_distribution.size(); ++i) {
P_distribution[i] = static_cast<float>(p_hist[i]);
for (size_t i = 0; i != p_distribution.size(); ++i) {
p_distribution[i] = static_cast<float>(p_hist[i]);
}

negative_outliers_count -= hist[zero_point_index - threshold];
positive_outliers_count -= hist[zero_point_index + threshold - 1];
P_distribution[0] += negative_outliers_count;
P_distribution[P_distribution.size() - 1] += positive_outliers_count;
p_distribution[0] += negative_outliers_count;
p_distribution[p_distribution.size() - 1] += positive_outliers_count;

//! Quantize the bins in range [-threshold, threshold] to target_bins
std::vector<float> Q_distribution(target_bins, 0);
std::vector<float> q_distribution(target_bins, 0);
float merged_cnt = static_cast<float>(threshold * 2) / target_bins;
size_t left_boundary = zero_point_index - threshold;
for (size_t i = 0; i < target_bins; ++i) {
Expand All @@ -168,28 +168,28 @@ static inline size_t ComputeThreshold(const std::vector<uint32_t> &hist,
const size_t start_ceil = static_cast<size_t>(std::ceil(start));
const size_t end_floor = static_cast<size_t>(std::floor(end));
if (left_boundary + start_ceil > 0) {
Q_distribution[i] +=
q_distribution[i] +=
((float)start_ceil - start) * hist[left_boundary + start_ceil - 1];
}
if (left_boundary + end_floor < hist.size()) {
Q_distribution[i] +=
q_distribution[i] +=
(end - (float)end_floor) * hist[left_boundary + end_floor];
}

for (size_t j = start_ceil; j < end_floor; j++) {
Q_distribution[i] += hist[left_boundary + j];
q_distribution[i] += hist[left_boundary + j];
}
}
std::vector<float> Q_expand_distribution;
ExpandCandidateDistribution(hist, Q_distribution, threshold,
&Q_expand_distribution);
std::vector<float> q_expand_distribution;
ExpandCandidateDistribution(hist, q_distribution, threshold,
&q_expand_distribution);

//! Compute Kullback-Leibler Divergence, normalize the smooth the data
//! first. Ref: http://hanj.cs.illinois.edu/cs412/bk3/KL-divergence.pdf
MakeSmooth(P_distribution);
MakeSmooth(Q_expand_distribution);
MakeSmooth(p_distribution);
MakeSmooth(q_expand_distribution);
double divergence =
ComputeKlDivergence(P_distribution, Q_expand_distribution);
ComputeKlDivergence(p_distribution, q_expand_distribution);

if (divergence < min_divergence) {
min_divergence = divergence;
Expand Down
4 changes: 4 additions & 0 deletions src/ailego/encoding/json/mod_json.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.

// NOLINTBEGIN

#include <float.h>
#include <stdio.h>
#include <stdlib.h>
Expand Down Expand Up @@ -3589,3 +3591,5 @@ mod_json_string_t *mod_json_dump(mod_json_value_t *val) {
}
return str;
}

// NOLINTEND
3 changes: 3 additions & 0 deletions src/ailego/internal/cpu_features.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ namespace internal {

/*! Cpu Features
*/
// NOLINTBEGIN(readability-identifier-naming): identifiers mirror CPUID feature
// mnemonics (SSE4_1, AVX512_VNNI, L1_ECX ...) and stay in hardware casing.
class CpuFeatures {
public:
//! 16-bit FP conversions
Expand Down Expand Up @@ -376,6 +378,7 @@ class CpuFeatures {
};
static StaticFlags static_flags_;
};
// NOLINTEND(readability-identifier-naming)

} // namespace internal
} // namespace ailego
Expand Down
5 changes: 5 additions & 0 deletions src/ailego/io/iouring_def.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,9 @@
// Struct definitions (copied verbatim from <linux/io_uring.h>)
// ---------------------------------------------------------------------------

// NOLINTBEGIN(readability-identifier-naming): types below are copied verbatim
// from the Linux kernel ABI (<linux/io_uring.h>) and must keep their names.

// Submission queue entry — 64 bytes.
struct io_uring_sqe {
uint8_t opcode; // type of operation for this sqe
Expand Down Expand Up @@ -219,4 +222,6 @@ static inline void io_uring_prep_write(struct io_uring_sqe *sqe, int fd,
// End: struct and constant definitions from <linux/io_uring.h>
// ---------------------------------------------------------------------------

// NOLINTEND(readability-identifier-naming)

#endif // __linux__
5 changes: 5 additions & 0 deletions src/ailego/io/libaio_def.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@

#if (defined(__linux) || defined(__linux__)) && !defined(__ANDROID__)

// NOLINTBEGIN(readability-identifier-naming): types below are copied verbatim
// from the Linux kernel ABI (<libaio.h>) and must keep their upstream names.

struct sockaddr;
struct iovec;

Expand Down Expand Up @@ -187,4 +190,6 @@ static inline void io_prep_pread(struct iocb *iocb, int fd, void *buf,
// End: type and struct definitions from <libaio.h>
// ---------------------------------------------------------------------------

// NOLINTEND(readability-identifier-naming)

#endif // __linux__
6 changes: 3 additions & 3 deletions src/ailego/io/libaio_loader.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@ class LibAioLoader {
aio_submit_fn io_submit;
aio_getevents_fn io_getevents;

LibAioLoader(const LibAioLoader &) = delete;
LibAioLoader &operator=(const LibAioLoader &) = delete;

private:
LibAioLoader()
: io_setup(nullptr),
Expand All @@ -91,9 +94,6 @@ class LibAioLoader {
}
}

LibAioLoader(const LibAioLoader &) = delete;
LibAioLoader &operator=(const LibAioLoader &) = delete;

void try_load() {
// On Ubuntu 24.04 the libaio package was renamed with the t64 suffix
// (64-bit time_t transition), so probe both spellings.
Expand Down
1 change: 1 addition & 0 deletions src/ailego/math/cosine_distance_matrix.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ struct CosineDistanceMatrix<
float *out) {
ailego_assert(m && q && dim && out);

// NOLINTNEXTLINE(bugprone-sizeof-expression): intentional byte-width ratio
constexpr size_t extra_dim = sizeof(float) / sizeof(ValueType);
size_t d = dim - extra_dim;

Expand Down
3 changes: 3 additions & 0 deletions src/ailego/math/matrix_utility.i
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

#include <zvec/ailego/internal/platform.h>

// NOLINTBEGIN(readability-identifier-naming): SIMD intrinsic helpers use the
// deliberate Operation_TYPE_WIDTH convention (e.g. HorizontalMax_FP32_V128).
namespace zvec {
namespace ailego {

Expand Down Expand Up @@ -263,3 +265,4 @@ static inline float HorizontalAdd_FP16_V512(__m512h v) {

} // namespace ailego
} // namespace zvec
// NOLINTEND(readability-identifier-naming)
9 changes: 5 additions & 4 deletions src/ailego/math_batch/cosine_distance_batch.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
#include <zvec/ailego/utility/type_helper.h>
#include "inner_product_distance_batch.h"

namespace zvec::ailego::DistanceBatch {
namespace zvec::ailego::distance_batch {


template <typename T, size_t BatchSize, size_t PrefetchStep, typename = void>
Expand All @@ -34,11 +34,12 @@ struct CosineDistanceBatch {
static inline void ComputeBatch(const ValueType **vecs,
const ValueType *query, size_t num_vecs,
size_t dim, float *results) {
// NOLINTNEXTLINE(bugprone-sizeof-expression): intentional byte-width ratio
constexpr size_t extra_dim = sizeof(float) / sizeof(ValueType);
size_t _dim = dim - extra_dim;
size_t data_dim = dim - extra_dim;

InnerProductDistanceBatch<ValueType, BatchSize, PrefetchStep>::ComputeBatch(
vecs, query, num_vecs, _dim, results);
vecs, query, num_vecs, data_dim, results);

for (size_t i = 0; i < num_vecs; ++i) {
results[i] = 1 - results[i];
Expand All @@ -55,4 +56,4 @@ struct CosineDistanceBatch {
};


} // namespace zvec::ailego::DistanceBatch
} // namespace zvec::ailego::distance_batch
10 changes: 5 additions & 5 deletions src/ailego/math_batch/distance_batch.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ template <
template <typename, size_t, size_t, typename = void> class DistanceType,
typename ValueType, size_t BatchSize, size_t PrefetchStep, typename = void>
struct BaseDistance {
static inline void _ComputeBatch(const ValueType **m, const ValueType *q,
static inline void compute_batch(const ValueType **m, const ValueType *q,
size_t num, size_t dim, float *out) {
for (size_t i = 0; i < num; ++i) {
DistanceType<ValueType, 1, 1>::Compute(m[i], q, dim, out + i);
Expand All @@ -39,27 +39,27 @@ struct BaseDistance {
const void ** /*extra_values*/) {
if constexpr (std::is_same_v<DistanceType<ValueType, 1, 1>,
CosineDistanceMatrix<ValueType, 1, 1>>) {
return DistanceBatch::CosineDistanceBatch<
return distance_batch::CosineDistanceBatch<
ValueType, BatchSize, PrefetchStep>::ComputeBatch(m, q, num, dim,
out);
}

if constexpr (std::is_same_v<DistanceType<ValueType, 1, 1>,
EuclideanDistanceMatrix<ValueType, 1, 1>>) {
return DistanceBatch::EuclideanDistanceBatch<
return distance_batch::EuclideanDistanceBatch<
ValueType, BatchSize, PrefetchStep>::ComputeBatch(m, q, num, dim,
out);
}

if constexpr (std::is_same_v<
DistanceType<ValueType, 1, 1>,
SquaredEuclideanDistanceMatrix<ValueType, 1, 1>>) {
return DistanceBatch::SquaredEuclideanDistanceBatch<
return distance_batch::SquaredEuclideanDistanceBatch<
ValueType, BatchSize, PrefetchStep>::ComputeBatch(m, q, num, dim, out,
nullptr);
}

_ComputeBatch(m, q, num, dim, out);
compute_batch(m, q, num, dim, out);
}
};

Expand Down
4 changes: 2 additions & 2 deletions src/ailego/math_batch/euclidean_distance_batch.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
#include <zvec/ailego/math_batch/utils.h>
#include <zvec/ailego/utility/type_helper.h>

namespace zvec::ailego::DistanceBatch {
namespace zvec::ailego::distance_batch {

// SquaredEuclideanDistanceBatch
template <typename T, size_t BatchSize, size_t PrefetchStep, typename = void>
Expand Down Expand Up @@ -141,4 +141,4 @@ struct SquaredEuclideanDistanceBatchImpl<float, 12> {
size_t dim, float *sums);
};

} // namespace zvec::ailego::DistanceBatch
} // namespace zvec::ailego::distance_batch
4 changes: 2 additions & 2 deletions src/ailego/math_batch/euclidean_distance_batch_dispatch.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
#include <zvec/ailego/utility/type_helper.h>
#include "euclidean_distance_batch.h"

namespace zvec::ailego::DistanceBatch {
namespace zvec::ailego::distance_batch {

#if defined(__AVX512FP16__)
void compute_one_to_many_squared_euclidean_avx512fp16_fp16_1(
Expand Down Expand Up @@ -188,4 +188,4 @@ void SquaredEuclideanDistanceBatchImpl<ailego::Float16, 12>::
// dim, sums);
// }

} // namespace zvec::ailego::DistanceBatch
} // namespace zvec::ailego::distance_batch
Loading
Loading