From b0727bedf6a48d3511d837d09a6da3ac29d2f1f5 Mon Sep 17 00:00:00 2001 From: Ash Vardanian <1983160+ashvardanian@users.noreply.github.com> Date: Fri, 1 Nov 2024 22:28:53 +0000 Subject: [PATCH 1/3] Fix: Implicit `dot_i8` & `dot_u8` declaration --- include/simsimd/simsimd.h | 4 ++++ scripts/test.c | 6 +++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/include/simsimd/simsimd.h b/include/simsimd/simsimd.h index b55767a4..c004212e 100644 --- a/include/simsimd/simsimd.h +++ b/include/simsimd/simsimd.h @@ -1301,6 +1301,10 @@ SIMSIMD_DYNAMIC int simsimd_uses_sierra(void); * @note The dot product is zero if and only if the two vectors are orthogonal. * @note Defined only for floating-point and integer data types. */ +SIMSIMD_DYNAMIC void simsimd_dot_i8(simsimd_i8_t const *a, simsimd_i8_t const *b, simsimd_size_t n, + simsimd_distance_t *d); +SIMSIMD_DYNAMIC void simsimd_dot_u8(simsimd_u8_t const *a, simsimd_u8_t const *b, simsimd_size_t n, + simsimd_distance_t *d); SIMSIMD_DYNAMIC void simsimd_dot_f16(simsimd_f16_t const *a, simsimd_f16_t const *b, simsimd_size_t n, simsimd_distance_t *d); SIMSIMD_DYNAMIC void simsimd_dot_bf16(simsimd_bf16_t const *a, simsimd_bf16_t const *b, simsimd_size_t n, diff --git a/scripts/test.c b/scripts/test.c index 827d8dae..0f740817 100644 --- a/scripts/test.c +++ b/scripts/test.c @@ -91,11 +91,13 @@ void test_distance_from_itself(void) { simsimd_f16_t f16s[1536]; simsimd_bf16_t bf16s[1536]; simsimd_i8_t i8s[1536]; + simsimd_u8_t u8s[1536]; simsimd_b8_t b8s[1536 / 8]; // 8 bits per word simsimd_distance_t distance; // Cosine distance between two vectors simsimd_cos_i8(i8s, i8s, 1536, &distance); + simsimd_cos_u8(u8s, u8s, 1536, &distance); simsimd_cos_f16(f16s, f16s, 1536, &distance); simsimd_cos_bf16(bf16s, bf16s, 1536, &distance); simsimd_cos_f32(f32s, f32s, 1536, &distance); @@ -103,12 +105,15 @@ void test_distance_from_itself(void) { // Euclidean distance between two vectors simsimd_l2sq_i8(i8s, i8s, 1536, &distance); + simsimd_l2sq_u8(u8s, u8s, 1536, &distance); simsimd_l2sq_f16(f16s, f16s, 1536, &distance); simsimd_l2sq_bf16(bf16s, bf16s, 1536, &distance); simsimd_l2sq_f32(f32s, f32s, 1536, &distance); simsimd_l2sq_f64(f64s, f64s, 1536, &distance); // Inner product between two vectors + simsimd_dot_i8(i8s, i8s, 1536, &distance); + simsimd_dot_u8(u8s, u8s, 1536, &distance); simsimd_dot_f16(f16s, f16s, 1536, &distance); simsimd_dot_bf16(bf16s, bf16s, 1536, &distance); simsimd_dot_f32(f32s, f32s, 1536, &distance); @@ -117,7 +122,6 @@ void test_distance_from_itself(void) { // Complex inner product between two vectors simsimd_dot_f16c(f16s, f16s, 1536, &distance); simsimd_dot_bf16c(bf16s, bf16s, 1536, &distance); - // simsimd_dot_bf16c(bf16s, bf16s, 1536, &distance); simsimd_dot_f32c(f32s, f32s, 1536, &distance); simsimd_dot_f64c(f64s, f64s, 1536, &distance); From a4a257fa5f15ae76728d0204553b544ab73fdd98 Mon Sep 17 00:00:00 2001 From: Ash Vardanian <1983160+ashvardanian@users.noreply.github.com> Date: Fri, 1 Nov 2024 22:34:36 +0000 Subject: [PATCH 2/3] Fix: `SEGFAULT` in C tests --- .github/workflows/prerelease.yml | 20 +++++++++ scripts/test.c | 76 ++++++++++++++++---------------- 2 files changed, 58 insertions(+), 38 deletions(-) diff --git a/.github/workflows/prerelease.yml b/.github/workflows/prerelease.yml index b8b75b67..66173609 100644 --- a/.github/workflows/prerelease.yml +++ b/.github/workflows/prerelease.yml @@ -43,6 +43,26 @@ jobs: include/simsimd/simsimd.h:^#define SIMSIMD_VERSION_PATCH (\d+) dry-run: "true" + test_c: + name: Test C + runs-on: ubuntu-24.04 + steps: + - uses: actions/checkout@v4 + - run: git submodule update --init --recursive + + - name: Install dependencies + run: | + sudo apt update + sudo apt install -y cmake build-essential libjemalloc-dev libomp-dev libopenblas-dev + + - name: Build locally + run: | + cmake -D CMAKE_BUILD_TYPE=Release -D SIMSIMD_BUILD_TESTS=1 -D SIMSIMD_BUILD_BENCHMARKS=1 -D SIMSIMD_BUILD_BENCHMARKS_WITH_CBLAS=1 -B build_release + cmake --build build_release --config Release + + - name: Test + run: build_release/simsimd_test_run_time + test_python: name: Test Python ${{ matrix.python-version }} on ${{ matrix.architecture }} ${{ matrix.os }} runs-on: ${{ matrix.os }} diff --git a/scripts/test.c b/scripts/test.c index 0f740817..b8302cf5 100644 --- a/scripts/test.c +++ b/scripts/test.c @@ -92,62 +92,62 @@ void test_distance_from_itself(void) { simsimd_bf16_t bf16s[1536]; simsimd_i8_t i8s[1536]; simsimd_u8_t u8s[1536]; - simsimd_b8_t b8s[1536 / 8]; // 8 bits per word - simsimd_distance_t distance; + simsimd_b8_t b8s[1536 / 8]; // 8 bits per word + simsimd_distance_t distance[2]; // For complex dot-products we need two values // Cosine distance between two vectors - simsimd_cos_i8(i8s, i8s, 1536, &distance); - simsimd_cos_u8(u8s, u8s, 1536, &distance); - simsimd_cos_f16(f16s, f16s, 1536, &distance); - simsimd_cos_bf16(bf16s, bf16s, 1536, &distance); - simsimd_cos_f32(f32s, f32s, 1536, &distance); - simsimd_cos_f64(f64s, f64s, 1536, &distance); + simsimd_cos_i8(i8s, i8s, 1536, &distance[0]); + simsimd_cos_u8(u8s, u8s, 1536, &distance[0]); + simsimd_cos_f16(f16s, f16s, 1536, &distance[0]); + simsimd_cos_bf16(bf16s, bf16s, 1536, &distance[0]); + simsimd_cos_f32(f32s, f32s, 1536, &distance[0]); + simsimd_cos_f64(f64s, f64s, 1536, &distance[0]); // Euclidean distance between two vectors - simsimd_l2sq_i8(i8s, i8s, 1536, &distance); - simsimd_l2sq_u8(u8s, u8s, 1536, &distance); - simsimd_l2sq_f16(f16s, f16s, 1536, &distance); - simsimd_l2sq_bf16(bf16s, bf16s, 1536, &distance); - simsimd_l2sq_f32(f32s, f32s, 1536, &distance); - simsimd_l2sq_f64(f64s, f64s, 1536, &distance); + simsimd_l2sq_i8(i8s, i8s, 1536, &distance[0]); + simsimd_l2sq_u8(u8s, u8s, 1536, &distance[0]); + simsimd_l2sq_f16(f16s, f16s, 1536, &distance[0]); + simsimd_l2sq_bf16(bf16s, bf16s, 1536, &distance[0]); + simsimd_l2sq_f32(f32s, f32s, 1536, &distance[0]); + simsimd_l2sq_f64(f64s, f64s, 1536, &distance[0]); // Inner product between two vectors - simsimd_dot_i8(i8s, i8s, 1536, &distance); - simsimd_dot_u8(u8s, u8s, 1536, &distance); - simsimd_dot_f16(f16s, f16s, 1536, &distance); - simsimd_dot_bf16(bf16s, bf16s, 1536, &distance); - simsimd_dot_f32(f32s, f32s, 1536, &distance); - simsimd_dot_f64(f64s, f64s, 1536, &distance); + simsimd_dot_i8(i8s, i8s, 1536, &distance[0]); + simsimd_dot_u8(u8s, u8s, 1536, &distance[0]); + simsimd_dot_f16(f16s, f16s, 1536, &distance[0]); + simsimd_dot_bf16(bf16s, bf16s, 1536, &distance[0]); + simsimd_dot_f32(f32s, f32s, 1536, &distance[0]); + simsimd_dot_f64(f64s, f64s, 1536, &distance[0]); // Complex inner product between two vectors - simsimd_dot_f16c(f16s, f16s, 1536, &distance); - simsimd_dot_bf16c(bf16s, bf16s, 1536, &distance); - simsimd_dot_f32c(f32s, f32s, 1536, &distance); - simsimd_dot_f64c(f64s, f64s, 1536, &distance); + simsimd_dot_f16c(f16s, f16s, 1536, &distance[0]); + simsimd_dot_bf16c(bf16s, bf16s, 1536, &distance[0]); + simsimd_dot_f32c(f32s, f32s, 1536, &distance[0]); + simsimd_dot_f64c(f64s, f64s, 1536, &distance[0]); // Complex conjugate inner product between two vectors - simsimd_vdot_f16c(f16s, f16s, 1536, &distance); - simsimd_vdot_bf16c(bf16s, bf16s, 1536, &distance); - simsimd_vdot_f32c(f32s, f32s, 1536, &distance); - simsimd_vdot_f64c(f64s, f64s, 1536, &distance); + simsimd_vdot_f16c(f16s, f16s, 1536, &distance[0]); + simsimd_vdot_bf16c(bf16s, bf16s, 1536, &distance[0]); + simsimd_vdot_f32c(f32s, f32s, 1536, &distance[0]); + simsimd_vdot_f64c(f64s, f64s, 1536, &distance[0]); // Hamming distance between two vectors - simsimd_hamming_b8(b8s, b8s, 1536 / 8, &distance); + simsimd_hamming_b8(b8s, b8s, 1536 / 8, &distance[0]); // Jaccard distance between two vectors - simsimd_jaccard_b8(b8s, b8s, 1536 / 8, &distance); + simsimd_jaccard_b8(b8s, b8s, 1536 / 8, &distance[0]); // Jensen-Shannon divergence between two vectors - simsimd_js_f16(f16s, f16s, 1536, &distance); - simsimd_js_bf16(bf16s, bf16s, 1536, &distance); - simsimd_js_f32(f32s, f32s, 1536, &distance); - simsimd_js_f64(f64s, f64s, 1536, &distance); + simsimd_js_f16(f16s, f16s, 1536, &distance[0]); + simsimd_js_bf16(bf16s, bf16s, 1536, &distance[0]); + simsimd_js_f32(f32s, f32s, 1536, &distance[0]); + simsimd_js_f64(f64s, f64s, 1536, &distance[0]); // Kullback-Leibler divergence between two vectors - simsimd_kl_f16(f16s, f16s, 1536, &distance); - simsimd_kl_bf16(bf16s, bf16s, 1536, &distance); - simsimd_kl_f32(f32s, f32s, 1536, &distance); - simsimd_kl_f64(f64s, f64s, 1536, &distance); + simsimd_kl_f16(f16s, f16s, 1536, &distance[0]); + simsimd_kl_bf16(bf16s, bf16s, 1536, &distance[0]); + simsimd_kl_f32(f32s, f32s, 1536, &distance[0]); + simsimd_kl_f64(f64s, f64s, 1536, &distance[0]); } int main(int argc, char **argv) { From 4fd3d24ba048b4035a76060bdd7c291b2cdd3c06 Mon Sep 17 00:00:00 2001 From: Ash Vardanian <1983160+ashvardanian@users.noreply.github.com> Date: Fri, 1 Nov 2024 22:38:48 +0000 Subject: [PATCH 3/3] Make: Run pre-release CI on any `main-*` branches --- .github/workflows/prerelease.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/prerelease.yml b/.github/workflows/prerelease.yml index 66173609..7e2a8c54 100644 --- a/.github/workflows/prerelease.yml +++ b/.github/workflows/prerelease.yml @@ -2,9 +2,9 @@ name: Pre-Release on: push: - branches: ["main-dev"] + branches: ["main-*"] pull_request: - branches: ["main-dev"] + branches: ["main-*"] env: BUILD_TYPE: Release