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:
Andrew Kane
2024-04-14 19:30:41 -07:00
parent fe9a9a0d0f
commit 00308491d3
2 changed files with 10 additions and 2 deletions

View File

@@ -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)

View File

@@ -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;