Compare commits

..

8 Commits

Author SHA1 Message Date
Andrew Kane
ffc0d46f5b Test always 2024-04-07 22:54:09 -07:00
Andrew Kane
1f6ad15962 Added OPTFLAGS 2024-04-07 22:40:06 -07:00
Andrew Kane
a60bb9c15c Test 2024-04-07 22:36:57 -07:00
Andrew Kane
8a7f5d14b8 Fixed 2024-04-07 22:31:23 -07:00
Andrew Kane
28367c8f30 Test SIMD 2024-04-07 22:15:32 -07:00
Andrew Kane
06309f5d07 Updated comments [skip ci] 2024-04-07 21:55:44 -07:00
Andrew Kane
39b8bd1816 Switched to storeu [skip ci] 2024-04-07 21:04:59 -07:00
Andrew Kane
925aa4e048 Added SIMD version of L2 distance 2024-04-07 20:22:19 -07:00
3 changed files with 150 additions and 5 deletions

View File

@@ -1,6 +1,120 @@
name: build
on: [push, pull_request]
jobs:
ubuntu:
runs-on: ${{ matrix.os }}
if: ${{ !startsWith(github.ref_name, 'mac') && !startsWith(github.ref_name, 'windows') }}
strategy:
fail-fast: false
matrix:
include:
- postgres: 17
os: ubuntu-22.04
- postgres: 16
os: ubuntu-22.04
- postgres: 15
os: ubuntu-22.04
- postgres: 14
os: ubuntu-22.04
- postgres: 13
os: ubuntu-20.04
- postgres: 12
os: ubuntu-20.04
steps:
- uses: actions/checkout@v4
- uses: ankane/setup-postgres@v1
with:
postgres-version: ${{ matrix.postgres }}
dev-files: true
- 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: make installcheck
- if: ${{ failure() }}
run: cat regression.diffs
- run: |
sudo apt-get update
sudo apt-get install libipc-run-perl
- run: make prove_installcheck
mac:
runs-on: ${{ matrix.os }}
if: ${{ !startsWith(github.ref_name, 'windows') }}
strategy:
fail-fast: false
matrix:
include:
- postgres: 16
os: macos-14
- postgres: 14
os: macos-12
steps:
- uses: actions/checkout@v4
- uses: ankane/setup-postgres@v1
with:
postgres-version: ${{ matrix.postgres }}
- run: make
env:
PG_CFLAGS: -DUSE_ASSERT_CHECKING -Wall -Wextra -Werror -Wno-unused-parameter
- run: make install
- run: make installcheck
- if: ${{ failure() }}
run: cat regression.diffs
# Homebrew Postgres does not enable TAP tests, so need to download
- run: |
brew install cpanm
cpanm --notest IPC::Run
wget -q https://github.com/postgres/postgres/archive/refs/tags/$TAG.tar.gz
tar xf $TAG.tar.gz
mv postgres-$TAG postgres
env:
TAG: ${{ matrix.postgres == 16 && 'REL_16_2' || 'REL_14_11' }}
- run: make prove_installcheck PROVE_FLAGS="-I ./postgres/src/test/perl -I ./test/perl"
env:
PERL5LIB: /Users/runner/perl5/lib/perl5
- run: make clean && $(brew --prefix llvm@15)/bin/scan-build --status-bugs make
env:
PG_CFLAGS: -DUSE_ASSERT_CHECKING
windows:
runs-on: windows-latest
if: ${{ !startsWith(github.ref_name, 'mac') }}
steps:
- uses: actions/checkout@v4
- uses: ankane/setup-postgres@v1
with:
postgres-version: 14
- run: |
call "C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Auxiliary\Build\vcvars64.bat" && ^
cd %TEMP% && ^
nmake /NOLOGO /F Makefile.win && ^
nmake /NOLOGO /F Makefile.win install && ^
nmake /NOLOGO /F Makefile.win installcheck && ^
nmake /NOLOGO /F Makefile.win clean && ^
nmake /NOLOGO /F Makefile.win uninstall
shell: cmd
i386:
if: ${{ !startsWith(github.ref_name, 'mac') && !startsWith(github.ref_name, 'windows') }}
runs-on: ubuntu-latest
container:
image: debian:12
options: --platform linux/386
steps:
- run: apt-get update && apt-get install -y build-essential git libipc-run-perl postgresql-15 postgresql-server-dev-15 sudo
- run: service postgresql start
- run: |
git clone https://github.com/${{ github.repository }}.git pgvector
cd pgvector
git fetch origin ${{ github.ref }}
git reset --hard FETCH_HEAD
make
make install
chown -R postgres .
sudo -u postgres make installcheck
sudo -u postgres make prove_installcheck
env:
PG_CFLAGS: -DUSE_ASSERT_CHECKING -Wall -Wextra -Werror -Wno-unused-parameter -Wno-sign-compare
valgrind:
if: ${{ !startsWith(github.ref_name, 'mac') && !startsWith(github.ref_name, 'windows') }}
runs-on: ubuntu-latest

View File

@@ -103,7 +103,8 @@ pq_sendhalf(StringInfo buf, half h)
float
HalfToFloat4(half num)
{
#if defined(F16C_SUPPORT)
#if defined(F16C_SUPPORT) && !defined(_MSC_VER)
/* TODO Use instrinsics for Windows */
return _cvtsh_ss(num);
#elif defined(FLT16_SUPPORT)
return (float) num;
@@ -190,7 +191,8 @@ HalfToFloat4(half num)
half
Float4ToHalfUnchecked(float num)
{
#if defined(F16C_SUPPORT)
#if defined(F16C_SUPPORT) && !defined(_MSC_VER)
/* TODO Use instrinsics for Windows */
return _cvtss_sh(num, 0);
#elif defined(FLT16_SUPPORT)
return (_Float16) num;
@@ -810,6 +812,34 @@ l2_distance_squared_internal(HalfVector * a, HalfVector * b)
half *bx = b->x;
float distance = 0.0;
#if defined(F16C_SUPPORT) && defined(__FMA__)
int i;
float s[8];
int count = (a->dim / 8) * 8;
__m256 dist = _mm256_setzero_ps();
for (i = 0; i < count; i += 8)
{
__m128i axi = _mm_loadu_si128((__m128i *) (ax + i));
__m128i bxi = _mm_loadu_si128((__m128i *) (bx + i));
__m256 axs = _mm256_cvtph_ps(axi);
__m256 bxs = _mm256_cvtph_ps(bxi);
__m256 diff = _mm256_sub_ps(axs, bxs);
dist = _mm256_fmadd_ps(diff, diff, dist);
}
_mm256_storeu_ps(s, dist);
distance = s[0] + s[1] + s[2] + s[3] + s[4] + s[5] + s[6] + s[7];
for (; i < a->dim; i++)
{
float diff = HalfToFloat4(ax[i]) - HalfToFloat4(bx[i]);
distance += diff * diff;
}
#else
/* Auto-vectorized */
for (int i = 0; i < a->dim; i++)
{
@@ -817,6 +847,7 @@ l2_distance_squared_internal(HalfVector * a, HalfVector * b)
distance += diff * diff;
}
#endif
return (double) distance;
}
@@ -877,7 +908,7 @@ inner_product_internal(HalfVector * a, HalfVector * b)
dist = _mm256_fmadd_ps(axs, bxs, dist);
}
_mm256_store_ps(s, dist);
_mm256_storeu_ps(s, dist);
distance = s[0] + s[1] + s[2] + s[3] + s[4] + s[5] + s[6] + s[7];

View File

@@ -7,7 +7,8 @@
#include "vector.h"
#if defined(__F16C__)
/* F16C has better performance than _Float16 (on x86-64) */
#if defined(__F16C__) || defined(_MSC_VER)
#define F16C_SUPPORT
#elif defined(__FLT16_MAX__)
#define FLT16_SUPPORT
@@ -17,7 +18,6 @@
#define half _Float16
#define HALF_MAX FLT16_MAX
#else
/* TODO #pragma message("")? */
#define half uint16
#define HALF_MAX 65504
#endif