文件 simdlib_neon.h

namespace faiss

使用许多变体的 k-means 聚类实现。

版权所有 (c) Facebook, Inc. 及其附属公司。

此源代码已获得 MIT 许可证的许可,该许可证位于此源树的根目录中的 LICENSE 文件中。

IDSelector 旨在定义要处理的向量子集(用于删除或作为搜索的子集)

PQ4 SIMD 压缩和累加函数

基本内核使用 bbs = nb * 2 * 16 向量累加 nq 查询向量,并生成该向量的输出矩阵。对于 nq * nb <= 4 很有用,否则寄存器溢出变得太大。

这些函数的实现分布在 3 个 cpp 文件中,以减少并行编译时间。模板被显式实例化。

此文件包含用于计算距离的内核的回调。

在整个库中,向量以 float * 指针的形式提供。当在批处理中一起处理(添加/搜索)多个向量时,大多数算法都可以优化。在这种情况下,它们作为矩阵传入。当大小为 d 的 n 个向量作为 float * x 提供时,向量 i 的分量 j 为

x[ i * d + j ]

其中 0 <= i < n 且 0 <= j < d。换句话说,矩阵总是紧凑的。指定矩阵的大小时,我们称其为 n*d 矩阵,这意味着行主存储。

I/O 函数可以读取/写入到文件名、文件句柄或抽象介质的对象。

读取函数返回应该用 delete 释放的对象。这些对象中的所有引用都归该对象所有。

倒排列表的定义 + 实现该接口的一些常用类。

由于 IVF(倒排文件)索引对于大规模用例非常有用,因此我们将与它们相关的一些函数分组到这个小型库中。大多数函数既适用于 IndexIVF,也适用于嵌入在 IndexPreTransform 中的 IndexIVF。

此文件实现了 L2 和内积之外的额外指标

实现了一些神经网络层,主要用于支持 QINCo

定义一些将转换应用于一组向量的对象。通常这些是预处理步骤。

struct simd16uint16 : public faiss::simd256bit, public faiss::simd256bit, public faiss::simd256bit
#include <simdlib_avx2.h>
struct simd32uint8 : public faiss::simd256bit, public faiss::simd256bit, public faiss::simd256bit
struct simd8uint32 : public faiss::simd256bit, public faiss::simd256bit, public faiss::simd256bit
#include <simdlib_avx2.h>
struct simd8float32 : public faiss::simd256bit, public faiss::simd256bit, public faiss::simd256bit
namespace detail
namespace simdlib

类型定义

template<typename T>
using remove_cv_ref_t = typename std::remove_reference<typename std::remove_cv<T>::type>::type

函数

static inline uint8x16x2_t reinterpret_u8(const uint8x16x2_t &v)
static inline uint8x16x2_t reinterpret_u8(const uint16x8x2_t &v)
static inline uint8x16x2_t reinterpret_u8(const uint32x4x2_t &v)
static inline uint8x16x2_t reinterpret_u8(const float32x4x2_t &v)
static inline uint16x8x2_t reinterpret_u16(const uint8x16x2_t &v)
static inline uint16x8x2_t reinterpret_u16(const uint16x8x2_t &v)
static inline uint16x8x2_t reinterpret_u16(const uint32x4x2_t &v)
static inline uint16x8x2_t reinterpret_u16(const float32x4x2_t &v)
static inline uint32x4x2_t reinterpret_u32(const uint8x16x2_t &v)
static inline uint32x4x2_t reinterpret_u32(const uint16x8x2_t &v)
static inline uint32x4x2_t reinterpret_u32(const uint32x4x2_t &v)
static inline uint32x4x2_t reinterpret_u32(const float32x4x2_t &v)
static inline float32x4x2_t reinterpret_f32(const uint8x16x2_t &v)
static inline float32x4x2_t reinterpret_f32(const uint16x8x2_t &v)
static inline float32x4x2_t reinterpret_f32(const uint32x4x2_t &v)
static inline float32x4x2_t reinterpret_f32(const float32x4x2_t &v)
static inline ::uint16x8_t vdupq_n_u16(std::uint16_t v)
static inline ::uint8x16_t vdupq_n_u8(std::uint8_t v)
static inline void bin(const char (&bytes)[32], char bits[257])
template<typename T, size_t N, typename S>
static inline void bin(const S &simd, char bits[257])
template<typename S>
static inline std::string bin(const S &simd)
template<typename D, typename T>
static inline set1_impl<remove_cv_ref_t<D>, T> set1(D &d, T t)
template<typename T, size_t N, typename S>
static inline std::string elements_to_string(const char *fmt, const S &simd)
template<typename T>
static inline unary_func_impl<remove_cv_ref_t<T>, remove_cv_ref_t<T>> unary_func(const T &a)
template<typename T, typename U>
static inline unary_func_impl<remove_cv_ref_t<T>, remove_cv_ref_t<U>> unary_func(const U &a)
template<typename T>
static inline binary_func_impl<remove_cv_ref_t<T>, remove_cv_ref_t<T>> binary_func(const T &a, const T &b)
template<typename T, typename U>
static inline binary_func_impl<remove_cv_ref_t<T>, remove_cv_ref_t<U>> binary_func(const U &a, const U &b)
static inline uint16_t vmovmask_u8(const uint8x16_t &v)
template<uint16x8_t (*F)(uint16x8_t, uint16x8_t)>
static inline uint32_t cmp_xe32(const uint16x8x2_t &d0, const uint16x8x2_t &d1, const uint16x8x2_t &thr)
template<std::uint8_t Shift>
static inline uint16x8_t vshlq(uint16x8_t vec)
template<std::uint8_t Shift>
static inline uint16x8_t vshrq(uint16x8_t vec)
template<typename T, typename U = decltype(reinterpret_u8(std::declval<T>().data))>
struct is_simd256bit : public std::is_same<decltype(reinterpret_u8(std::declval<T>().data)), uint8x16x2_t>
template<typename D, typename T>
struct set1_impl

公共函数

template<remove_cv_ref_t<decltype(std::declval<D>().val[0])> (*F)(T)>
inline void call()

公共成员

D &d
T t
template<typename T, typename U>
struct unary_func_impl

公共类型

using Telem = remove_cv_ref_t<decltype(std::declval<T>().val[0])>
using Uelem = remove_cv_ref_t<decltype(std::declval<U>().val[0])>

公共函数

template<Telem (*F)(Uelem)>
inline T call()

公共成员

const U &a
template<typename T, typename U>
struct binary_func_impl

公共类型

using Telem = remove_cv_ref_t<decltype(std::declval<T>().val[0])>
using Uelem = remove_cv_ref_t<decltype(std::declval<U>().val[0])>

公共函数

template<Telem (*F)(Uelem, Uelem)>
inline T call()

公共成员

const U &a
const U &b