mirror of
https://github.com/pgvector/pgvector.git
synced 2026-07-22 20:15:46 +08:00
Compare commits
3 Commits
v0.8.0
...
half-dispa
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e9d5a0b1aa | ||
|
|
52a81b3b9d | ||
|
|
c5372e493b |
@@ -19,6 +19,7 @@
|
|||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
float (*HalfvecL2SquaredDistance) (int dim, half * ax, half * bx);
|
float (*HalfvecL2SquaredDistance) (int dim, half * ax, half * bx);
|
||||||
float (*HalfvecInnerProduct) (int dim, half * ax, half * bx);
|
float (*HalfvecInnerProduct) (int dim, half * ax, half * bx);
|
||||||
double (*HalfvecCosineSimilarity) (int dim, half * ax, half * bx);
|
double (*HalfvecCosineSimilarity) (int dim, half * ax, half * bx);
|
||||||
@@ -193,12 +194,19 @@ HalfvecCosineSimilarityF16cFma(int dim, half * ax, half * bx)
|
|||||||
|
|
||||||
#ifdef HALFVEC_DISPATCH
|
#ifdef HALFVEC_DISPATCH
|
||||||
#define CPU_FEATURE_FMA (1 << 12)
|
#define CPU_FEATURE_FMA (1 << 12)
|
||||||
|
#define CPU_FEATURE_OSXSAVE (1 << 27)
|
||||||
|
#define CPU_FEATURE_AVX (1 << 28)
|
||||||
#define CPU_FEATURE_F16C (1 << 29)
|
#define CPU_FEATURE_F16C (1 << 29)
|
||||||
|
|
||||||
static bool
|
#ifdef _MSC_VER
|
||||||
|
#define TARGET_XSAVE
|
||||||
|
#else
|
||||||
|
#define TARGET_XSAVE __attribute__((target("xsave")))
|
||||||
|
#endif
|
||||||
|
|
||||||
|
TARGET_XSAVE static bool
|
||||||
SupportsCpuFeature(unsigned int feature)
|
SupportsCpuFeature(unsigned int feature)
|
||||||
{
|
{
|
||||||
/* TODO Fix check */
|
|
||||||
unsigned int exx[4] = {0, 0, 0, 0};
|
unsigned int exx[4] = {0, 0, 0, 0};
|
||||||
|
|
||||||
#if defined(HAVE__GET_CPUID)
|
#if defined(HAVE__GET_CPUID)
|
||||||
@@ -207,6 +215,12 @@ SupportsCpuFeature(unsigned int feature)
|
|||||||
__cpuid(exx, 1);
|
__cpuid(exx, 1);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
if ((exx[2] & CPU_FEATURE_OSXSAVE) != CPU_FEATURE_OSXSAVE)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if ((_xgetbv(0) & 6) != 6)
|
||||||
|
return false;
|
||||||
|
|
||||||
return (exx[2] & feature) == feature;
|
return (exx[2] & feature) == feature;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@@ -223,7 +237,7 @@ HalfvecInit(void)
|
|||||||
HalfvecCosineSimilarity = HalfvecCosineSimilarityDefault;
|
HalfvecCosineSimilarity = HalfvecCosineSimilarityDefault;
|
||||||
|
|
||||||
#ifdef HALFVEC_DISPATCH
|
#ifdef HALFVEC_DISPATCH
|
||||||
if (SupportsCpuFeature(CPU_FEATURE_FMA | CPU_FEATURE_F16C))
|
if (SupportsCpuFeature(CPU_FEATURE_AVX | CPU_FEATURE_FMA | CPU_FEATURE_F16C))
|
||||||
{
|
{
|
||||||
HalfvecL2SquaredDistance = HalfvecL2SquaredDistanceF16cFma;
|
HalfvecL2SquaredDistance = HalfvecL2SquaredDistanceF16cFma;
|
||||||
HalfvecInnerProduct = HalfvecInnerProductF16cFma;
|
HalfvecInnerProduct = HalfvecInnerProductF16cFma;
|
||||||
|
|||||||
Reference in New Issue
Block a user