Skip to content
Closed
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
72 changes: 72 additions & 0 deletions .github/workflows/build-linux-arm.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
# Copyright 2023 Intel Corporation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

name: Linux Build and Test on ARM

on:
push:
branches:
- main
pull_request:

permissions:
contents: read

# This allows a subsequently queued workflow run to interrupt previous runs
concurrency:
group: '${{ github.workflow }} @ ${{ github.event.pull_request.head.label || github.head_ref || github.ref }}'
cancel-in-progress: true

jobs:
build:
name: ${{ matrix.cxx }}, ${{ matrix.build_type }}
runs-on: ubuntu-22.04-arm
strategy:
matrix:
build_type: [RelWithDebugInfo]
cxx: [g++-11, g++-12, clang++-15]
include:
- cxx: g++-11
cc: gcc-11
- cxx: g++-12
cc: gcc-12
- cxx: clang++-15
cc: clang-15

steps:
- uses: actions/checkout@v4

- name: Configure build
working-directory: ${{ runner.temp }}
env:
CXX: ${{ matrix.cxx }}
CC: ${{ matrix.cc }}
TEMP_WORKSPACE: ${{ runner.temp }}
run: |
cmake -B${TEMP_WORKSPACE}/build -S${GITHUB_WORKSPACE} \
-DCMAKE_BUILD_TYPE=${{ matrix.build_type }} \
-DSVS_BUILD_BINARIES=YES \
-DSVS_BUILD_TESTS=YES \
-DSVS_BUILD_EXAMPLES=YES \
-DSVS_EXPERIMENTAL_LEANVEC=YES

- name: Build Tests and Utilities
working-directory: ${{ runner.temp }}/build
run: make -j$(nproc)

- name: Run tests
env:
CTEST_OUTPUT_ON_FAILURE: 1
working-directory: ${{ runner.temp }}/build/tests
run: ctest -C ${{ matrix.build_type }}
6 changes: 6 additions & 0 deletions .github/workflows/cibuildwheel.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,9 @@ jobs:
working-directory: ${{ runner.temp }}
run: python -m unittest discover -s ${GITHUB_WORKSPACE}/bindings/python

- name: Run examples
env:
PYTHONPATH: ${{ runner.temp }}/usr
CTEST_OUTPUT_ON_FAILURE: 1
working-directory: ${{ runner.temp }}
run: python -m unittest discover -p "example*.py" -s ${GITHUB_WORKSPACE}/examples/python
10 changes: 5 additions & 5 deletions examples/python/example_vamana.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,12 @@
# [imports]

DEBUG_MODE = False
def assert_equal(lhs, rhs, message: str = ""):
def assert_equal(lhs, rhs, message: str = "", epsilon = 0.05):
if DEBUG_MODE:
print(f"{message}: {lhs} == {rhs}")
else:
assert lhs == rhs, message
assert lhs < rhs + epsilon, message
assert lhs > rhs - epsilon, message

def run_test_float(index, queries, groundtruth):
expected = {
Expand Down Expand Up @@ -79,7 +80,6 @@ def run_test_build_two_level4_8(index, queries, groundtruth):
test_data_dir = None

def run():

# ###
# Generating test data
# ###
Expand Down Expand Up @@ -159,7 +159,7 @@ def run():
# Compare with the groundtruth.
recall = svs.k_recall_at(groundtruth, I, 10, 10)
print(f"Recall = {recall}")
assert(recall == 0.8288)
assert_equal(recall, 0.8288)
# [perform-queries]

# [search-window-size]
Expand Down Expand Up @@ -213,7 +213,7 @@ def run():
# Compare with the groundtruth.
recall = svs.k_recall_at(groundtruth, I, 10, 10)
print(f"Recall = {recall}")
assert(recall == 0.8288)
assert_equal(recall, 0.8288)
# [loading]

##### Begin Test
Expand Down
10 changes: 5 additions & 5 deletions examples/python/example_vamana_dynamic.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,12 @@
# [imports]

DEBUG_MODE = False
def assert_equal(lhs, rhs, message: str = ""):
def assert_equal(lhs, rhs, message: str = "", epsilon = 0.05):
if DEBUG_MODE:
print(f"{message}: {lhs} == {rhs}")
else:
assert lhs == rhs, message
assert lhs < rhs + epsilon, message
assert lhs > rhs - epsilon, message

def run_test_float(index, queries, groundtruth):
expected = {
Expand Down Expand Up @@ -118,7 +119,7 @@ def run():
# Compare with the groundtruth.
recall = svs.k_recall_at(groundtruth, I, 10, 10)
print(f"Recall = {recall}")
assert(recall == 0.8202)
assert_equal(recall, 0.8202)
# [perform-queries]

##### Begin Test
Expand Down Expand Up @@ -158,8 +159,7 @@ def run():
# Compare with the groundtruth.
recall = svs.k_recall_at(groundtruth, I, 10, 10)
print(f"Recall = {recall}")
assert(recall == 0.8202)

assert_equal(recall, 0.8202)

##### Begin Test
run_test_float(index, queries, groundtruth)
Expand Down
1 change: 0 additions & 1 deletion include/svs/core/distance/cosine.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
#include <iostream>
#include <memory>
#include <type_traits>
#include <x86intrin.h>

namespace svs::distance {
// Forward declare implementation to allow entry point to be near the top.
Expand Down
1 change: 0 additions & 1 deletion include/svs/core/distance/euclidean.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
#include <memory>
#include <span>
#include <type_traits>
#include <x86intrin.h>

// Implementation Notes regarding Intel(R) AVX Extentions
// Top most entry in the bulleted list underneath each type pair <T,U> is the preferred
Expand Down
1 change: 0 additions & 1 deletion include/svs/core/distance/inner_product.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
#include <iostream>
#include <memory>
#include <type_traits>
#include <x86intrin.h>

namespace svs::distance {
// Forward declare implementation to allow entry point to be near the top.
Expand Down
4 changes: 4 additions & 0 deletions include/svs/core/distance/simd_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

#pragma once

#if defined(__i386__) || defined(__x86_64__)

#include <array>
#include <limits>
#include <type_traits>
Expand Down Expand Up @@ -369,3 +371,5 @@ template <> struct ConvertForVNNI<int16_t, 32> {

} // namespace simd
} // namespace svs

#endif // __i386__ || __x86_64__
2 changes: 1 addition & 1 deletion include/svs/lib/memory.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ template <typename T> struct Allocator {
}

constexpr void deallocate(value_type* ptr, size_t count) noexcept {
::operator delete(ptr, count);
::operator delete(static_cast<void*>(ptr), sizeof(T) * count, std::align_val_t(alignof(T)));
}

// Intercept zero-argument construction to do default initialization.
Expand Down
2 changes: 1 addition & 1 deletion include/svs/lib/prefetch.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ template <typename T> void prefetch_l0(const T* ptr) {
}
#else
// Do nothing if prefetch is not-available.
template <typename T> void prefetch_l0(const T* ptr) {}
template <typename T> void prefetch_l0([[maybe_unused]] const T* ptr) {}
#endif

const size_t CACHELINE_BYTES = 64;
Expand Down
8 changes: 7 additions & 1 deletion include/svs/lib/spinlock.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,13 @@
namespace svs {

namespace detail {
inline void pause() { __builtin_ia32_pause(); }
inline void pause() {
#if defined(__i386__) || defined(__x86_64__)
__builtin_ia32_pause();
#elif defined(__aarch64__)
asm volatile ("yield" ::: "memory");
#endif
}
} // namespace detail

///
Expand Down
3 changes: 2 additions & 1 deletion include/svs/lib/threads/threadlocal.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@ template <typename T, size_t Alignment = CACHE_LINE_BYTES> struct AlignedAllocat
}

void deallocate(value_type* ptr, size_t count) noexcept {
::operator delete(ptr, count, std::align_val_t{alignment});
size_t bytes = alignment * lib::div_round_up(sizeof(T) * count, alignment);
::operator delete(static_cast<void*>(ptr), bytes, std::align_val_t{alignment});
}
};

Expand Down
4 changes: 4 additions & 0 deletions tests/svs/core/distances/simd_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
* limitations under the License.
*/

#if defined(__i386__) || defined(__x86_64__)

#include <cstdint>
#include <type_traits>

Expand Down Expand Up @@ -61,3 +63,5 @@ CATCH_TEST_CASE("Masks", "[distance]") {
CATCH_REQUIRE(svs::create_mask<16>(svs::lib::MaybeStatic<100>()) == 0xF);
CATCH_REQUIRE(svs::create_mask<16>(svs::lib::MaybeStatic<16>()) == 0xFFFF);
}

#endif // defined(__i386__) || defined(__x86_64__)
Loading