mirror of
https://github.com/pgvector/pgvector.git
synced 2026-06-06 05:51:21 +08:00
Added CPU dispatching for distance functions on Linux x86-64 - closes #311
Co-authored-by: Arda Aytekin <arda.aytekin@microsoft.com>
This commit is contained in:
@@ -7,6 +7,7 @@
|
||||
- Added `hamming_distance` function
|
||||
- Added `jaccard_distance` function
|
||||
- Added `subvector` function
|
||||
- Added CPU dispatching for distance functions on Linux x86-64
|
||||
- Updated comparison operators to support vectors with different dimensions
|
||||
|
||||
## 0.6.2 (2024-03-18)
|
||||
|
||||
11
src/vector.c
11
src/vector.c
@@ -33,6 +33,13 @@
|
||||
#define STATE_DIMS(x) (ARR_DIMS(x)[0] - 1)
|
||||
#define CreateStateDatums(dim) palloc(sizeof(Datum) * (dim + 1))
|
||||
|
||||
/* target_clones requires glibc */
|
||||
#if defined(__x86_64__) && defined(__gnu_linux__) && defined(__has_attribute) && __has_attribute(target_clones) && !defined(__FMA__)
|
||||
#define VECTOR_DISPATCH __attribute__((target_clones("default", "fma")))
|
||||
#else
|
||||
#define VECTOR_DISPATCH
|
||||
#endif
|
||||
|
||||
PG_MODULE_MAGIC;
|
||||
|
||||
/*
|
||||
@@ -557,7 +564,7 @@ halfvec_to_vector(PG_FUNCTION_ARGS)
|
||||
PG_RETURN_POINTER(result);
|
||||
}
|
||||
|
||||
static float
|
||||
VECTOR_DISPATCH static float
|
||||
VectorL2SquaredDistance(int dim, float *ax, float *bx)
|
||||
{
|
||||
float distance = 0.0;
|
||||
@@ -604,7 +611,7 @@ vector_l2_squared_distance(PG_FUNCTION_ARGS)
|
||||
PG_RETURN_FLOAT8((double) VectorL2SquaredDistance(a->dim, a->x, b->x));
|
||||
}
|
||||
|
||||
static float
|
||||
VECTOR_DISPATCH static float
|
||||
VectorInnerProduct(int dim, float *ax, float *bx)
|
||||
{
|
||||
float distance = 0.0;
|
||||
|
||||
Reference in New Issue
Block a user