Skip to content
Open
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
32 changes: 32 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,38 @@ jobs:
sudo apt-get update
sudo apt-get install libipc-run-perl
- run: make prove_installcheck
ubuntu_spr:
runs-on: ubuntu-24.04
if: ${{ !startsWith(github.ref_name, 'mac') && !startsWith(github.ref_name, 'windows') }}
steps:
- uses: actions/checkout@v4
- name: Install Intel SDE
run: |
curl -o /tmp/sde.tar.xz https://downloadmirror.intel.com/831748/sde-external-9.44.0-2024-08-22-lin.tar.xz
mkdir /tmp/sde && tar -xvf /tmp/sde.tar.xz -C /tmp/sde/
sudo mv /tmp/sde/* /opt/sde && sudo ln -s /opt/sde/sde64 /usr/bin/sde
- name: Install Postgres
run: |
sudo apt-get install postgresql-16
sudo apt-get install postgresql-server-dev-16
sudo systemctl stop postgresql
pgdir=$(pg_config --bindir)
pgdata=/tmp/postgres_data
mkdir $pgdata
$pgdir/initdb -D $pgdata --username=$USER
sudo chmod 777 /var/run/postgresql/
sde -spr -mix -- $pgdir/pg_ctl -D $pgdata start
- run: make
env:
PG_CFLAGS: -DUSE_ASSERT_CHECKING -Wall -Wextra -Werror -Wno-unused-parameter -Wno-sign-compare
- run: |
export PG_CONFIG=`which pg_config`
sudo --preserve-env=PG_CONFIG make install
- run: sde -spr -mix -- make installcheck
- if: ${{ failure() }}
run: cat regression.diffs
- name: Report AVX512 FP16 FMA instruction count
run: cat sde*.txt | grep -E "FMA.*PH"
mac:
runs-on: ${{ matrix.os }}
if: ${{ !startsWith(github.ref_name, 'windows') }}
Expand Down
6 changes: 6 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ MODULE_big = vector
DATA = $(wildcard sql/*--*--*.sql)
DATA_built = sql/$(EXTENSION)--$(EXTVERSION).sql
OBJS = src/bitutils.o src/bitvec.o src/halfutils.o src/halfvec.o src/hnsw.o src/hnswbuild.o src/hnswinsert.o src/hnswscan.o src/hnswutils.o src/hnswvacuum.o src/ivfbuild.o src/ivfflat.o src/ivfinsert.o src/ivfkmeans.o src/ivfscan.o src/ivfutils.o src/ivfvacuum.o src/sparsevec.o src/vector.o
ifneq ($(USE_AVX512), 0)
OBJS += src/halfutils_avx512.o
endif
HEADERS = src/halfvec.h src/sparsevec.h src/vector.h

TESTS = $(wildcard test/sql/*.sql)
Expand All @@ -31,6 +34,9 @@ endif
# - GCC (needs -ftree-vectorize OR -O3) - https://gcc.gnu.org/projects/tree-ssa/vectorization.html
# - Clang (could use pragma instead) - https://llvm.org/docs/Vectorizers.html
PG_CFLAGS += $(OPTFLAGS) -ftree-vectorize -fassociative-math -fno-signed-zeros -fno-trapping-math
ifneq ($(USE_AVX512), 0)
PG_CFLAGS += -DUSE_AVX512
endif

# Debug GCC auto-vectorization
# PG_CFLAGS += -fopt-info-vec
Expand Down
22 changes: 22 additions & 0 deletions src/halfutils.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

#ifdef HALFVEC_DISPATCH
#include <immintrin.h>
#include "halfutils_avx512.h"

#if defined(USE__GET_CPUID)
#include <cpuid.h>
Expand All @@ -24,6 +25,8 @@ float (*HalfvecInnerProduct) (int dim, half * ax, half * bx);
double (*HalfvecCosineSimilarity) (int dim, half * ax, half * bx);
float (*HalfvecL1Distance) (int dim, half * ax, half * bx);

void (*Float4ToHalfVector) (Vector * vec, HalfVector * result);

static float
HalfvecL2SquaredDistanceDefault(int dim, half * ax, half * bx)
{
Expand Down Expand Up @@ -237,6 +240,13 @@ HalfvecL1DistanceF16c(int dim, half * ax, half * bx)
}
#endif

static void
Float4ToHalfVectorDefault(Vector * vec, HalfVector * result) {
for (int i = 0; i < vec->dim; i++)
result->x[i] = Float4ToHalf(vec->x[i]);
}


#ifdef HALFVEC_DISPATCH
#define CPU_FEATURE_FMA (1 << 12)
#define CPU_FEATURE_OSXSAVE (1 << 27)
Expand Down Expand Up @@ -284,6 +294,7 @@ HalfvecInit(void)
HalfvecInnerProduct = HalfvecInnerProductDefault;
HalfvecCosineSimilarity = HalfvecCosineSimilarityDefault;
HalfvecL1Distance = HalfvecL1DistanceDefault;
Float4ToHalfVector = Float4ToHalfVectorDefault;

#ifdef HALFVEC_DISPATCH
if (SupportsCpuFeature(CPU_FEATURE_AVX | CPU_FEATURE_F16C | CPU_FEATURE_FMA))
Expand All @@ -294,5 +305,16 @@ HalfvecInit(void)
/* Does not require FMA, but keep logic simple */
HalfvecL1Distance = HalfvecL1DistanceF16c;
}

#if defined(USE_AVX512) && defined(HAVE_AVX512FP16)
if (SupportsAvx512Fp16())
{
HalfvecL2SquaredDistance = HalfvecL2SquaredDistanceAvx512;
HalfvecInnerProduct = HalfvecInnerProductAvx512;
HalfvecCosineSimilarity = HalfvecCosineSimilarityAvx512;
HalfvecL1Distance = HalfvecL1DistanceAvx512;
Float4ToHalfVector = Float4ToHalfVectorAvx512;
}
#endif
#endif
}
3 changes: 3 additions & 0 deletions src/halfutils.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

#include "common/shortest_dec.h"
#include "halfvec.h"
#include "vector.h"

#ifdef F16C_SUPPORT
#include <immintrin.h>
Expand All @@ -15,6 +16,8 @@ extern float (*HalfvecInnerProduct) (int dim, half * ax, half * bx);
extern double (*HalfvecCosineSimilarity) (int dim, half * ax, half * bx);
extern float (*HalfvecL1Distance) (int dim, half * ax, half * bx);

extern void (*Float4ToHalfVector) (Vector * vec, HalfVector * result);

void HalfvecInit(void);

/*
Expand Down
Loading
Loading