From 88f550deee6c7c59f2b38f1c342013c11795236d Mon Sep 17 00:00:00 2001 From: Matthijs Douze Date: Thu, 5 May 2022 13:50:08 -0700 Subject: [PATCH] Fix failures surfaced by platform010 migration (#2320) Summary: Pull Request resolved: https://github.com/facebookresearch/faiss/pull/2320 Checks are a bit stricted in platform010, so fix new CI errors here. The errors corrected fall in 3 classes: - `&vector[vector.size()]` now fails because `operator []` checks for array bounds even if only the address is maniuplated - `omp schedule(dynamic)` does not run the loop in the correct order. - several threads calling omp loop seems to cause errors in the distributed Faiss code Reviewed By: beauby Differential Revision: D35895550 fbshipit-source-id: e9dcf5615158610a42870e6a41c77e4db6ebeea0 --- faiss/IndexFlatCodes.cpp | 3 +++ faiss/IndexHNSW.cpp | 6 ++++-- faiss/IndexIVF.cpp | 2 -- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/faiss/IndexFlatCodes.cpp b/faiss/IndexFlatCodes.cpp index 8049cb5cb..03cd3c16e 100644 --- a/faiss/IndexFlatCodes.cpp +++ b/faiss/IndexFlatCodes.cpp @@ -20,6 +20,9 @@ IndexFlatCodes::IndexFlatCodes() : code_size(0) {} void IndexFlatCodes::add(idx_t n, const float* x) { FAISS_THROW_IF_NOT(is_trained); + if (n == 0) { + return; + } codes.resize((ntotal + n) * code_size); sa_encode(n, x, codes.data() + (ntotal * code_size)); ntotal += n; diff --git a/faiss/IndexHNSW.cpp b/faiss/IndexHNSW.cpp index 51c7f98a2..81d319c9f 100644 --- a/faiss/IndexHNSW.cpp +++ b/faiss/IndexHNSW.cpp @@ -202,7 +202,10 @@ void hnsw_add_vertices( verbose && omp_get_thread_num() == 0 ? 0 : -1; size_t counter = 0; -#pragma omp for schedule(dynamic) + // here we should do schedule(dynamic) but this segfaults for + // some versions of LLVM. The performance impact should not be + // too large when (i1 - i0) / num_threads >> 1 +#pragma omp for schedule(static) for (int i = i0; i < i1; i++) { storage_idx_t pt_id = order[i]; dis->set_query(x + (pt_id - n0) * d); @@ -219,7 +222,6 @@ void hnsw_add_vertices( printf(" %d / %d\r", i - i0, i1 - i0); fflush(stdout); } - if (counter % check_period == 0) { if (InterruptCallback::is_interrupted()) { interrupt = true; diff --git a/faiss/IndexIVF.cpp b/faiss/IndexIVF.cpp index eb2447a1a..6c7b0598c 100644 --- a/faiss/IndexIVF.cpp +++ b/faiss/IndexIVF.cpp @@ -774,7 +774,6 @@ void IndexIVF::range_search_preassigned( } } } else if (parallel_mode == 2) { - std::vector all_qres(nx); RangeQueryResult* qres = nullptr; #pragma omp for schedule(dynamic) @@ -782,7 +781,6 @@ void IndexIVF::range_search_preassigned( idx_t i = iik / (idx_t)nprobe; idx_t ik = iik % (idx_t)nprobe; if (qres == nullptr || qres->qno != i) { - FAISS_ASSERT(!qres || i > qres->qno); qres = &pres.new_result(i); scanner->set_query(x + i * d); }