Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Win+AVX2 compat #1681

Closed
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
1 change: 1 addition & 0 deletions faiss/impl/ScalarQuantizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include <algorithm>

#include <omp.h>
#include <faiss/impl/platform_macros.h>

#ifdef __SSE__
#include <immintrin.h>
Expand Down
19 changes: 19 additions & 0 deletions faiss/impl/platform_macros.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,27 @@ inline int __builtin_clzll(uint64_t x) {
return (int)__lzcnt64(x);
}

#define __builtin_popcount __popcnt
#define __builtin_popcountl __popcnt64

// MSVC does not define __SSEx__, and _M_IX86_FP is only defined on 32-bit processors
// cf. https://docs.microsoft.com/en-us/cpp/preprocessor/predefined-macros
#ifdef __AVX__
#define __SSE__ 1
#define __SSE2__ 1
#define __SSE3__ 1
#define __SSE4_1__ 1
#define __SSE4_2__ 1
#endif

// MSVC sets FMA and F16C automatically when using AVX2
// Ref. FMA (under /arch:AVX2): https://docs.microsoft.com/en-us/cpp/build/reference/arch-x64
// Ref. F16C (2nd paragraph): https://walbourn.github.io/directxmath-avx2/
#ifdef __AVX2__
#define __FMA__ 1
#define __F16C__ 1
#endif

#else
/*******************************************************
* Linux and OSX
Expand Down
5 changes: 3 additions & 2 deletions faiss/utils/distances_simd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

#include <faiss/utils/simdlib.h>
#include <faiss/impl/FaissAssert.h>
#include <faiss/impl/platform_macros.h>

#ifdef __SSE3__
#include <immintrin.h>
Expand Down Expand Up @@ -165,7 +166,7 @@ void fvec_inner_products_ny_ref (float * ip,
static inline __m128 masked_read (int d, const float *x)
{
assert (0 <= d && d < 4);
__attribute__((__aligned__(16))) float buf[4] = {0, 0, 0, 0};
ALIGNED(16) float buf[4] = {0, 0, 0, 0};
switch (d) {
case 3:
buf[2] = x[2];
Expand Down Expand Up @@ -987,7 +988,7 @@ void compute_PQ_dis_tables_dsub2(

simd8float32 centroids[8];
for (int k = 0; k < 8; k++) {
float centroid[8] __attribute__((aligned(32)));
ALIGNED(32) float centroid[8];
size_t wp = 0;
size_t rp = (m0 * ksub + k + k0) * 2;
for (int m = m0; m < m1; m++) {
Expand Down