mirror of
https://github.com/facebookresearch/faiss.git
synced 2025-04-20 08:31:54 +08:00
Merge branch 'main' into amx
This commit is contained in:
commit
7f61463877
62
.github/actions/build_cmake/action.yml
vendored
62
.github/actions/build_cmake/action.yml
vendored
@ -32,9 +32,20 @@ runs:
|
||||
conda update -y -q conda
|
||||
echo "$CONDA/bin" >> $GITHUB_PATH
|
||||
|
||||
# install base packages
|
||||
conda install -y -q -c conda-forge gxx_linux-64=11.2 sysroot_linux-64=2.28
|
||||
conda install -y -q python=3.11 cmake make swig mkl=2023 mkl-devel=2023 numpy scipy pytest
|
||||
conda install -y -q python=3.11 cmake make swig numpy scipy pytest
|
||||
|
||||
# install base packages for ARM64
|
||||
if [ "${{ runner.arch }}" = "ARM64" ]; then
|
||||
conda install -y -q -c conda-forge openblas gxx_linux-aarch64 sysroot_linux-aarch64
|
||||
fi
|
||||
|
||||
# install base packages for X86_64
|
||||
if [ "${{ runner.arch }}" = "X64" ]; then
|
||||
# TODO: unpin versions for gxx_linux-64 and sysroot_linux-64 and merge it with ARM64 below
|
||||
conda install -y -q -c conda-forge gxx_linux-64=11.2 sysroot_linux-64=2.28
|
||||
conda install -y -q mkl=2023 mkl-devel=2023
|
||||
fi
|
||||
|
||||
|
||||
# install CUDA packages
|
||||
if [ "${{ inputs.gpu }}" = "ON" ] && [ "${{ inputs.raft }}" = "OFF" ]; then
|
||||
@ -63,19 +74,36 @@ runs:
|
||||
run: |
|
||||
eval "$(conda shell.bash hook)"
|
||||
conda activate
|
||||
cmake -B build \
|
||||
-DBUILD_TESTING=ON \
|
||||
-DBUILD_SHARED_LIBS=ON \
|
||||
-DFAISS_ENABLE_DNNL=${{ inputs.dnnl }} \
|
||||
-DFAISS_ENABLE_GPU=${{ inputs.gpu }} \
|
||||
-DFAISS_ENABLE_RAFT=${{ inputs.raft }} \
|
||||
-DFAISS_OPT_LEVEL=${{ inputs.opt_level }} \
|
||||
-DFAISS_ENABLE_C_API=ON \
|
||||
-DPYTHON_EXECUTABLE=$CONDA/bin/python \
|
||||
-DCMAKE_BUILD_TYPE=Release \
|
||||
-DBLA_VENDOR=Intel10_64_dyn \
|
||||
-DCMAKE_CUDA_FLAGS="-gencode arch=compute_75,code=sm_75" \
|
||||
.
|
||||
|
||||
if [ "${{ runner.arch }}" = "X64" ]; then
|
||||
cmake -B build \
|
||||
-DBUILD_TESTING=ON \
|
||||
-DBUILD_SHARED_LIBS=ON \
|
||||
-DFAISS_ENABLE_DNNL=${{ inputs.dnnl }} \
|
||||
-DFAISS_ENABLE_GPU=${{ inputs.gpu }} \
|
||||
-DFAISS_ENABLE_RAFT=${{ inputs.raft }} \
|
||||
-DFAISS_OPT_LEVEL=${{ inputs.opt_level }} \
|
||||
-DFAISS_ENABLE_C_API=ON \
|
||||
-DPYTHON_EXECUTABLE=$CONDA/bin/python \
|
||||
-DCMAKE_BUILD_TYPE=Release \
|
||||
-DBLA_VENDOR=Intel10_64_dyn \
|
||||
-DCMAKE_CUDA_FLAGS="-gencode arch=compute_75,code=sm_75" \
|
||||
.
|
||||
elif [ "${{ runner.arch }}" = "ARM64" ]; then
|
||||
cmake -B build \
|
||||
-DBUILD_TESTING=ON \
|
||||
-DBUILD_SHARED_LIBS=ON \
|
||||
-DFAISS_ENABLE_GPU=${{ inputs.gpu }} \
|
||||
-DFAISS_ENABLE_RAFT=${{ inputs.raft }} \
|
||||
-DFAISS_OPT_LEVEL=${{ inputs.opt_level }} \
|
||||
-DFAISS_ENABLE_C_API=ON \
|
||||
-DPYTHON_EXECUTABLE=$CONDA/bin/python \
|
||||
-DCMAKE_BUILD_TYPE=Release \
|
||||
.
|
||||
else
|
||||
echo "Encountered unexpected platform ${{ runner.arch }}"
|
||||
exit 1
|
||||
fi
|
||||
make -k -C build -j$(nproc)
|
||||
- name: C++ tests
|
||||
shell: bash
|
||||
@ -111,5 +139,5 @@ runs:
|
||||
- name: Upload test results
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: test-results-${{ inputs.opt_level }}-${{ inputs.gpu }}-${{ inputs.raft }}
|
||||
name: test-results-${{ runner.arch }}-${{ inputs.opt_level }}-${{ inputs.gpu }}-${{ inputs.raft }}
|
||||
path: test-results
|
||||
|
18
.github/workflows/build.yml
vendored
18
.github/workflows/build.yml
vendored
@ -11,24 +11,12 @@ env:
|
||||
OMP_NUM_THREADS: '10'
|
||||
MKL_THREADING_LAYER: GNU
|
||||
jobs:
|
||||
# AMX-DNNL-cmake:
|
||||
# name: AMX DNNL (cmake)
|
||||
# runs-on: faiss-aws-m7i.large
|
||||
# steps:
|
||||
# - name: Checkout
|
||||
# uses: actions/checkout@v4
|
||||
# - uses: ./.github/actions/build_cmake
|
||||
# with:
|
||||
# dnnl: ON
|
||||
linux-x86_64-AVX512-cmake:
|
||||
name: Linux x86_64 AVX512 (cmake)
|
||||
continue-on-error: true # non-blocking mode for now test
|
||||
# needs: linux-x86_64-cmake
|
||||
AMX-DNNL-cmake:
|
||||
name: AMX DNNL (cmake)
|
||||
runs-on: faiss-aws-m7i.large
|
||||
steps:
|
||||
- name: Checkout
|
||||
continue-on-error: true # non-blocking mode for now
|
||||
uses: actions/checkout@v4
|
||||
- uses: ./.github/actions/build_cmake
|
||||
with:
|
||||
opt_level: avx512
|
||||
dnnl: ON
|
||||
|
@ -89,4 +89,4 @@ You can report bugs, ask questions, etc.
|
||||
|
||||
Faiss is MIT-licensed, refer to the [LICENSE file](https://github.com/facebookresearch/faiss/blob/main/LICENSE) in the top level directory.
|
||||
|
||||
Copyright © Meta Platforms, Inc. See the [Terms of Use](https://opensource.fb.com/legal/terms/) and [Privacy Policy](https://opensource.fb.com/legal/privacy/) for this project.
|
||||
Copyright © Meta Platforms, Inc.
|
||||
|
@ -30,6 +30,7 @@ set(FAISS_C_SRC
|
||||
index_io_c.cpp
|
||||
impl/AuxIndexStructures_c.cpp
|
||||
utils/distances_c.cpp
|
||||
utils/utils_c.cpp
|
||||
)
|
||||
add_library(faiss_c ${FAISS_C_SRC})
|
||||
target_link_libraries(faiss_c PRIVATE faiss)
|
||||
|
16
c_api/utils/utils_c.cpp
Normal file
16
c_api/utils/utils_c.cpp
Normal file
@ -0,0 +1,16 @@
|
||||
/**
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
// Copyright 2004-present Facebook. All Rights Reserved.
|
||||
// -*- c++ -*-
|
||||
|
||||
#include "utils_c.h"
|
||||
#include <faiss/Index.h>
|
||||
|
||||
const char* faiss_get_version() {
|
||||
return VERSION_STRING;
|
||||
}
|
27
c_api/utils/utils_c.h
Normal file
27
c_api/utils/utils_c.h
Normal file
@ -0,0 +1,27 @@
|
||||
/**
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
// Copyright 2004-present Facebook. All Rights Reserved.
|
||||
// -*- c -*-
|
||||
|
||||
#ifndef FAISS_UTILS_C_H
|
||||
#define FAISS_UTILS_C_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
const char* faiss_get_version();
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
@ -20,6 +20,18 @@
|
||||
#define FAISS_VERSION_MINOR 8
|
||||
#define FAISS_VERSION_PATCH 0
|
||||
|
||||
// Macro to combine the version components into a single string
|
||||
#ifndef FAISS_STRINGIFY
|
||||
#define FAISS_STRINGIFY(ARG) #ARG
|
||||
#endif
|
||||
#ifndef FAISS_TOSTRING
|
||||
#define FAISS_TOSTRING(ARG) FAISS_STRINGIFY(ARG)
|
||||
#endif
|
||||
#define VERSION_STRING \
|
||||
FAISS_TOSTRING(FAISS_VERSION_MAJOR) \
|
||||
"." FAISS_TOSTRING(FAISS_VERSION_MINOR) "." FAISS_TOSTRING( \
|
||||
FAISS_VERSION_PATCH)
|
||||
|
||||
/**
|
||||
* @namespace faiss
|
||||
*
|
||||
@ -38,8 +50,8 @@
|
||||
|
||||
namespace faiss {
|
||||
|
||||
/// Forward declarations see impl/AuxIndexStructures.h, impl/IDSelector.h and
|
||||
/// impl/DistanceComputer.h
|
||||
/// Forward declarations see impl/AuxIndexStructures.h, impl/IDSelector.h
|
||||
/// and impl/DistanceComputer.h
|
||||
struct IDSelector;
|
||||
struct RangeSearchResult;
|
||||
struct DistanceComputer;
|
||||
@ -56,7 +68,8 @@ struct SearchParameters {
|
||||
virtual ~SearchParameters() {}
|
||||
};
|
||||
|
||||
/** Abstract structure for an index, supports adding vectors and searching them.
|
||||
/** Abstract structure for an index, supports adding vectors and searching
|
||||
* them.
|
||||
*
|
||||
* All vectors provided at add or search time are 32-bit float arrays,
|
||||
* although the internal representation may vary.
|
||||
@ -154,7 +167,8 @@ struct Index {
|
||||
|
||||
/** return the indexes of the k vectors closest to the query x.
|
||||
*
|
||||
* This function is identical as search but only return labels of neighbors.
|
||||
* This function is identical as search but only return labels of
|
||||
* neighbors.
|
||||
* @param n number of vectors
|
||||
* @param x input vectors to search, size n * d
|
||||
* @param labels output labels of the NNs, size n*k
|
||||
@ -179,7 +193,8 @@ struct Index {
|
||||
*/
|
||||
virtual void reconstruct(idx_t key, float* recons) const;
|
||||
|
||||
/** Reconstruct several stored vectors (or an approximation if lossy coding)
|
||||
/** Reconstruct several stored vectors (or an approximation if lossy
|
||||
* coding)
|
||||
*
|
||||
* this function may not be defined for some indexes
|
||||
* @param n number of vectors to reconstruct
|
||||
|
@ -530,11 +530,12 @@ Index* parse_other_indexes(
|
||||
}
|
||||
|
||||
// IndexLSH
|
||||
if (match("LSH(r?)(t?)")) {
|
||||
bool rotate_data = sm[1].length() > 0;
|
||||
bool train_thresholds = sm[2].length() > 0;
|
||||
if (match("LSH([0-9]*)(r?)(t?)")) {
|
||||
int nbits = sm[1].length() > 0 ? std::stoi(sm[1].str()) : d;
|
||||
bool rotate_data = sm[2].length() > 0;
|
||||
bool train_thresholds = sm[3].length() > 0;
|
||||
FAISS_THROW_IF_NOT(metric == METRIC_L2);
|
||||
return new IndexLSH(d, d, rotate_data, train_thresholds);
|
||||
return new IndexLSH(d, nbits, rotate_data, train_thresholds);
|
||||
}
|
||||
|
||||
// IndexLattice
|
||||
|
@ -7,6 +7,7 @@
|
||||
|
||||
// -*- c++ -*-
|
||||
|
||||
#include <faiss/Index.h>
|
||||
#include <faiss/utils/utils.h>
|
||||
|
||||
#include <cassert>
|
||||
@ -129,6 +130,10 @@ std::string get_compile_options() {
|
||||
return options;
|
||||
}
|
||||
|
||||
std::string get_version() {
|
||||
return VERSION_STRING;
|
||||
}
|
||||
|
||||
#ifdef _MSC_VER
|
||||
double getmillisecs() {
|
||||
LARGE_INTEGER ts;
|
||||
|
@ -37,6 +37,9 @@ std::string get_compile_options();
|
||||
* Get some stats about the system
|
||||
**************************************************/
|
||||
|
||||
// Expose FAISS version as a string
|
||||
std::string get_version();
|
||||
|
||||
/// ms elapsed since some arbitrary epoch
|
||||
double getmillisecs();
|
||||
|
||||
|
@ -35,6 +35,7 @@ set(FAISS_TEST_SRC
|
||||
test_disable_pq_sdc_tables.cpp
|
||||
test_common_ivf_empty_index.cpp
|
||||
test_callback.cpp
|
||||
test_utils.cpp
|
||||
)
|
||||
|
||||
add_executable(faiss_test ${FAISS_TEST_SRC})
|
||||
|
@ -119,6 +119,12 @@ class TestFactory(unittest.TestCase):
|
||||
assert index.nlist == 65536 and index_nsg.nsg.R == 64
|
||||
assert index.pq.M == 2 and index.pq.nbits == 8
|
||||
|
||||
def test_factory_lsh(self):
|
||||
index = faiss.index_factory(128, 'LSHrt')
|
||||
self.assertEqual(index.nbits, 128)
|
||||
index = faiss.index_factory(128, 'LSH16rt')
|
||||
self.assertEqual(index.nbits, 16)
|
||||
|
||||
def test_factory_fast_scan(self):
|
||||
index = faiss.index_factory(56, "PQ28x4fs")
|
||||
self.assertEqual(index.bbs, 32)
|
||||
|
19
tests/test_utils.cpp
Normal file
19
tests/test_utils.cpp
Normal file
@ -0,0 +1,19 @@
|
||||
/**
|
||||
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include <faiss/Index.h>
|
||||
#include <faiss/utils/utils.h>
|
||||
|
||||
TEST(TestUtils, get_version) {
|
||||
std::string version = std::to_string(FAISS_VERSION_MAJOR) + "." +
|
||||
std::to_string(FAISS_VERSION_MINOR) + "." +
|
||||
std::to_string(FAISS_VERSION_PATCH);
|
||||
|
||||
EXPECT_EQ(version, faiss::get_version());
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user