Skip to content
Open
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
8 changes: 8 additions & 0 deletions faiss/IVFlib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -601,10 +601,14 @@ void handle_ivf(
sharded_centroids[i].data());
}
char fname[256];
#if defined(__GNUC__) || defined(__clang__)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wformat-nonliteral"
#endif
snprintf(fname, 256, filename_template.c_str(), i);
#if defined(__GNUC__) || defined(__clang__)
#pragma GCC diagnostic pop
#endif
faiss::write_index(sharded_index, fname);
delete sharded_index;
}
Expand Down Expand Up @@ -655,10 +659,14 @@ void handle_binary_ivf(
sharded_centroids[i].data());
}
char fname[256];
#if defined(__GNUC__) || defined(__clang__)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wformat-nonliteral"
#endif
snprintf(fname, 256, filename_template.c_str(), i);
#if defined(__GNUC__) || defined(__clang__)
#pragma GCC diagnostic pop
#endif
faiss::write_index_binary(sharded_index, fname);
delete sharded_index;
}
Expand Down
2 changes: 1 addition & 1 deletion faiss/IndexIVFFlat.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ struct IVFFlatScanner : InvertedListScanner {
size_t list_size,
const uint8_t* codes,
const idx_t* ids,
ResultHandler& handler) const;
ResultHandler& handler) const override;
};

struct IndexIVFFlatDedup : IndexIVFFlat {
Expand Down
3 changes: 2 additions & 1 deletion faiss/IndexIVFSpectralHash.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ IndexIVFSpectralHash::IndexIVFSpectralHash(
own_invlists_in),
nbit(nbit_in),
period(period_in) {
auto rr = std::make_unique<RandomRotationMatrix>(d_in, nbit_in);
auto rr = std::make_unique<RandomRotationMatrix>(
static_cast<int>(d_in), nbit_in);
rr->init(1234);
vt = rr.release();
own_fields = true;
Expand Down
4 changes: 2 additions & 2 deletions faiss/IndexRaBitQFastScan.h
Original file line number Diff line number Diff line change
Expand Up @@ -279,11 +279,11 @@ struct RaBitQHeapHandler
rabitq_stats.n_multibit_evaluations += local_multibit_evaluations;
}

void begin(const float* norms) {
void begin(const float* norms) override {
normalizers = norms;
}

void end() {
void end() override {
#pragma omp parallel for if (nq > 100)
for (int64_t q = 0; q < static_cast<int64_t>(nq); q++) {
float* heap_dis = heap_distances + q * k;
Expand Down
8 changes: 8 additions & 0 deletions faiss/impl/PolysemousTraining.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -823,10 +823,14 @@ void PolysemousTraining::optimize_reproduce_distances(

if (log_pattern.size()) {
char fname[256];
#if defined(__GNUC__) || defined(__clang__)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wformat-nonliteral"
#endif
snprintf(fname, 256, log_pattern.c_str(), m);
#if defined(__GNUC__) || defined(__clang__)
#pragma GCC diagnostic pop
#endif
printf("opening log file %s\n", fname);
optim.logfile = fopen(fname, "w");
FAISS_THROW_IF_NOT_MSG(optim.logfile, "could not open logfile");
Expand Down Expand Up @@ -938,10 +942,14 @@ void PolysemousTraining::optimize_ranking(

if (log_pattern.size()) {
char fname[256];
#if defined(__GNUC__) || defined(__clang__)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wformat-nonliteral"
#endif
snprintf(fname, 256, log_pattern.c_str(), m);
#if defined(__GNUC__) || defined(__clang__)
#pragma GCC diagnostic pop
#endif
printf("opening log file %s\n", fname);
optim.logfile = fopen(fname, "w");
FAISS_THROW_IF_NOT_FMT(
Expand Down
24 changes: 20 additions & 4 deletions faiss/impl/simdlib/simdlib_avx2.h
Original file line number Diff line number Diff line change
Expand Up @@ -141,12 +141,17 @@ struct simd16uint16_tpl<SIMDLevel::AVX2> : simd256bit_tpl<SIMDLevel::AVX2> {
storeu((void*)bytes);
char res[1000];
char* ptr = res;
#if defined(__GNUC__) || defined(__clang__)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wformat-nonliteral"
#endif
for (int idx = 0; idx < 16; idx++) {
ptr += sprintf(ptr, fmt, bytes[idx]);
ptr += snprintf(
ptr, (size_t)(res + sizeof(res) - ptr), fmt, bytes[idx]);
}
#if defined(__GNUC__) || defined(__clang__)
#pragma GCC diagnostic pop
#endif
// strip last ,
ptr[-1] = 0;
return std::string(res);
Expand Down Expand Up @@ -462,12 +467,17 @@ struct simd32uint8_tpl<SIMDLevel::AVX2> : simd256bit_tpl<SIMDLevel::AVX2> {
storeu((void*)bytes);
char res[1000];
char* ptr = res;
#if defined(__GNUC__) || defined(__clang__)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wformat-nonliteral"
#endif
for (int idx = 0; idx < 32; idx++) {
ptr += sprintf(ptr, fmt, bytes[idx]);
ptr += snprintf(
ptr, (size_t)(res + sizeof(res) - ptr), fmt, bytes[idx]);
}
#if defined(__GNUC__) || defined(__clang__)
#pragma GCC diagnostic pop
#endif
// strip last ,
ptr[-1] = 0;
return std::string(res);
Expand Down Expand Up @@ -601,12 +611,17 @@ struct simd8uint32_tpl<SIMDLevel::AVX2> : simd256bit_tpl<SIMDLevel::AVX2> {
storeu((void*)bytes);
char res[1000];
char* ptr = res;
#if defined(__GNUC__) || defined(__clang__)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wformat-nonliteral"
#endif
for (int idx = 0; idx < 8; idx++) {
ptr += sprintf(ptr, fmt, bytes[idx]);
ptr += snprintf(
ptr, (size_t)(res + sizeof(res) - ptr), fmt, bytes[idx]);
}
#if defined(__GNUC__) || defined(__clang__)
#pragma GCC diagnostic pop
#endif
// strip last ,
ptr[-1] = 0;
return std::string(res);
Expand Down Expand Up @@ -727,7 +742,8 @@ struct simd8float32_tpl<SIMDLevel::AVX2> : simd256bit_tpl<SIMDLevel::AVX2> {
char res[1000];
char* ptr = res;
for (int idx = 0; idx < 8; idx++) {
ptr += sprintf(ptr, "%g,", tab[idx]);
ptr += snprintf(
ptr, (size_t)(res + sizeof(res) - ptr), "%g,", tab[idx]);
}
// strip last ,
ptr[-1] = 0;
Expand Down
23 changes: 20 additions & 3 deletions faiss/impl/simdlib/simdlib_avx512.h
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,17 @@ struct simd32uint16_tpl<SIMDLevel::AVX512> : simd512bit_tpl<SIMDLevel::AVX512> {
storeu((void*)bytes);
char res[2000];
char* ptr = res;
#if defined(__GNUC__) || defined(__clang__)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wformat-nonliteral"
#endif
for (int i = 0; i < 32; i++) {
ptr += sprintf(ptr, fmt, bytes[i]);
ptr += snprintf(
ptr, (size_t)(res + sizeof(res) - ptr), fmt, bytes[i]);
}
#if defined(__GNUC__) || defined(__clang__)
#pragma GCC diagnostic pop
#endif
// strip last ,
ptr[-1] = 0;
return std::string(res);
Expand Down Expand Up @@ -263,9 +271,17 @@ struct simd64uint8_tpl<SIMDLevel::AVX512> : simd512bit_tpl<SIMDLevel::AVX512> {
storeu((void*)bytes);
char res[2000];
char* ptr = res;
#if defined(__GNUC__) || defined(__clang__)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wformat-nonliteral"
#endif
for (int i = 0; i < 64; i++) {
ptr += sprintf(ptr, fmt, bytes[i]);
ptr += snprintf(
ptr, (size_t)(res + sizeof(res) - ptr), fmt, bytes[i]);
}
#if defined(__GNUC__) || defined(__clang__)
#pragma GCC diagnostic pop
#endif
// strip last ,
ptr[-1] = 0;
return std::string(res);
Expand Down Expand Up @@ -374,7 +390,8 @@ struct simd16float32_tpl<SIMDLevel::AVX512>
char res[1000];
char* ptr = res;
for (int i = 0; i < 16; i++) {
ptr += sprintf(ptr, "%g,", tab[i]);
ptr += snprintf(
ptr, (size_t)(res + sizeof(res) - ptr), "%g,", tab[i]);
}
ptr[-1] = 0;
return std::string(res);
Expand Down
23 changes: 19 additions & 4 deletions faiss/impl/simdlib/simdlib_emulated.h
Original file line number Diff line number Diff line change
Expand Up @@ -129,12 +129,17 @@ struct simd16uint16_tpl<SIMDLevel::NONE> : simd256bit_tpl<SIMDLevel::NONE> {

std::string elements_to_string(const char* fmt) const {
char res[1000], *ptr = res;
#if defined(__GNUC__) || defined(__clang__)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wformat-nonliteral"
#endif
for (int i = 0; i < 16; i++) {
ptr += sprintf(ptr, fmt, u16[i]);
ptr += snprintf(
ptr, (size_t)(res + sizeof(res) - ptr), fmt, u16[i]);
}
#if defined(__GNUC__) || defined(__clang__)
#pragma GCC diagnostic pop
#endif
// strip last ,
ptr[-1] = 0;
return std::string(res);
Expand Down Expand Up @@ -507,12 +512,16 @@ struct simd32uint8_tpl<SIMDLevel::NONE> : simd256bit_tpl<SIMDLevel::NONE> {

std::string elements_to_string(const char* fmt) const {
char res[1000], *ptr = res;
#if defined(__GNUC__) || defined(__clang__)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wformat-nonliteral"
#endif
for (int i = 0; i < 32; i++) {
ptr += sprintf(ptr, fmt, u8[i]);
ptr += snprintf(ptr, (size_t)(res + sizeof(res) - ptr), fmt, u8[i]);
}
#if defined(__GNUC__) || defined(__clang__)
#pragma GCC diagnostic pop
#endif
// strip last ,
ptr[-1] = 0;
return std::string(res);
Expand Down Expand Up @@ -707,12 +716,17 @@ struct simd8uint32_tpl<SIMDLevel::NONE> : simd256bit_tpl<SIMDLevel::NONE> {

std::string elements_to_string(const char* fmt) const {
char res[1000], *ptr = res;
#if defined(__GNUC__) || defined(__clang__)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wformat-nonliteral"
#endif
for (int i = 0; i < 8; i++) {
ptr += sprintf(ptr, fmt, u32[i]);
ptr += snprintf(
ptr, (size_t)(res + sizeof(res) - ptr), fmt, u32[i]);
}
#if defined(__GNUC__) || defined(__clang__)
#pragma GCC diagnostic pop
#endif
// strip last ,
ptr[-1] = 0;
return std::string(res);
Expand Down Expand Up @@ -863,7 +877,8 @@ struct simd8float32_tpl<SIMDLevel::NONE> : simd256bit_tpl<SIMDLevel::NONE> {
std::string tostring() const {
char res[1000], *ptr = res;
for (int i = 0; i < 8; i++) {
ptr += sprintf(ptr, "%g,", f32[i]);
ptr += snprintf(
ptr, (size_t)(res + sizeof(res) - ptr), "%g,", f32[i]);
}
// strip last ,
ptr[-1] = 0;
Expand Down
2 changes: 1 addition & 1 deletion faiss/python/faiss_example_external_module.swig
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ struct IDSelectorModulo : faiss::IDSelector {

IDSelectorModulo(int mod): mod(mod) {}

bool is_member(faiss::idx_t id) const {
bool is_member(faiss::idx_t id) const override {
return id % mod == 0;
}

Expand Down
63 changes: 63 additions & 0 deletions faiss/utils/distances.h
Original file line number Diff line number Diff line change
Expand Up @@ -600,4 +600,67 @@ int fvec_madd_and_argmin(
const float* b,
float* c);

/* Explicit specialization declarations for all SIMD-templated distance
functions. C++ [temp.expl.spec]/7 requires that these appear before any
translation unit that might implicitly instantiate them. GCC/Clang are
lenient about this, but MSVC is not — without these declarations the
linker emits LNK2001 for the specializations defined in the _avx2
translation units. */

// clang-format off
#define FAISS_DECLARE_DISTANCES_SPECIALIZATIONS(SL) \
template <> float fvec_L2sqr<SL>( \
const float* x, const float* y, size_t d); \
template <> float fvec_inner_product<SL>( \
const float* x, const float* y, size_t d); \
template <> float fvec_L1<SL>( \
const float* x, const float* y, size_t d); \
template <> float fvec_Linf<SL>( \
const float* x, const float* y, size_t d); \
template <> void fvec_inner_product_batch_4<SL>( \
const float* x, const float* y0, const float* y1, \
const float* y2, const float* y3, const size_t d, \
float& dis0, float& dis1, float& dis2, float& dis3); \
template <> void fvec_L2sqr_batch_4<SL>( \
const float* x, const float* y0, const float* y1, \
const float* y2, const float* y3, const size_t d, \
float& dis0, float& dis1, float& dis2, float& dis3); \
template <> void fvec_inner_products_ny<SL>( \
float* ip, const float* x, const float* y, \
size_t d, size_t ny); \
template <> void fvec_L2sqr_ny<SL>( \
float* dis, const float* x, const float* y, \
size_t d, size_t ny); \
template <> void fvec_L2sqr_ny_transposed<SL>( \
float* dis, const float* x, const float* y, \
const float* y_sqlen, size_t d, size_t d_offset, size_t ny); \
template <> size_t fvec_L2sqr_ny_nearest<SL>( \
float* distances_tmp_buffer, const float* x, \
const float* y, size_t d, size_t ny); \
template <> size_t fvec_L2sqr_ny_nearest_y_transposed<SL>( \
float* distances_tmp_buffer, const float* x, \
const float* y, const float* y_sqlen, \
size_t d, size_t d_offset, size_t ny); \
template <> float fvec_norm_L2sqr<SL>(const float* x, size_t d); \
template <> void fvec_add<SL>( \
size_t d, const float* a, const float* b, float* c); \
template <> void fvec_add<SL>( \
size_t d, const float* a, float b, float* c); \
template <> void fvec_sub<SL>( \
size_t d, const float* a, const float* b, float* c); \
template <> void compute_PQ_dis_tables_dsub2<SL>( \
size_t d, size_t ksub, const float* centroids, \
size_t nx, const float* x, bool is_inner_product, \
float* dis_tables); \
template <> void fvec_madd<SL>( \
size_t n, const float* a, float bf, const float* b, float* c); \
template <> int fvec_madd_and_argmin<SL>( \
size_t n, const float* a, float bf, const float* b, float* c);

FAISS_DECLARE_DISTANCES_SPECIALIZATIONS(SIMDLevel::NONE)
FAISS_DECLARE_DISTANCES_SPECIALIZATIONS(SIMDLevel::AVX2)

#undef FAISS_DECLARE_DISTANCES_SPECIALIZATIONS
// clang-format on

} // namespace faiss
Loading
Loading