diff --git a/src/ailego/math_batch/inner_product_distance_batch.h b/src/ailego/math_batch/inner_product_distance_batch.h index 6375482a2..19a5e4e96 100644 --- a/src/ailego/math_batch/inner_product_distance_batch.h +++ b/src/ailego/math_batch/inner_product_distance_batch.h @@ -55,6 +55,58 @@ struct InnerProductDistanceBatchImpl { } }; +template +struct MinusInnerProductDistanceBatchImpl { + using ValueType = typename std::remove_cv::type; + + // Keep the sign flip in the baseline-ISA caller. The dispatch translation + // unit is compiled for the highest available ISA so it can reference all + // optimized kernels; doing this work in an out-of-line specialization there + // can make Clang emit AVX-512 instructions before any runtime feature check. + static void compute_one_to_many( + const ValueType *query, const ValueType **ptrs, + std::array &prefetch_ptrs, size_t dim, + float *sums) { + InnerProductDistanceBatchImpl::compute_one_to_many( + query, ptrs, prefetch_ptrs, dim, sums); + for (size_t j = 0; j < BatchSize; ++j) { + sums[j] = -sums[j]; + } + } +}; + +template