mirror of
https://github.com/facebookresearch/faiss.git
synced 2026-10-11 22:50:00 +00:00
Summary: Pull Request resolved: https://github.com/facebookresearch/faiss/pull/5127 Attempt to enable FAISS dynamic dispatch (DD) mode on Windows/MSVC. Changes: - CMakeLists.txt: Remove if(NOT WIN32) guard from DD section, add MSVC per-file SIMD flags (/arch:AVX2, /arch:AVX512, /bigobj) alongside existing GCC/Clang flags - build-pull-request.yml: Add windows-x86_64-DD-cmake job that runs immediately (no dependency on linux-x86_64-cmake), builds with MSVC and FAISS_OPT_LEVEL=dd, runs C++ tests and Python tests This diff is expected to fail on Windows due to MSVC requiring explicit template specialization declarations (C++ §17.8.3) which GCC/Clang don't enforce. The CI failure will surface the exact errors to guide the fix. UPDATE: in fact, MSVC does not seem to require this. After fixing build scripts and a few classical Windows error, the C++ and python tests pass. Reviewed By: algoriddle Differential Revision: D101649751 fbshipit-source-id: 765ef8483d02652ce58625cd22baab8870acf718
68 lines
1.9 KiB
C++
68 lines
1.9 KiB
C++
/*
|
|
* 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 <chrono>
|
|
#include <cstddef>
|
|
#include <cstdint>
|
|
#include <memory>
|
|
#include <random>
|
|
#include <vector>
|
|
|
|
#include <omp.h>
|
|
|
|
#include <faiss/IndexFlat.h>
|
|
#include <faiss/IndexIVFPQFastScan.h>
|
|
#include <faiss/impl/AuxIndexStructures.h>
|
|
|
|
TEST(TestFastScan, knnVSrange) {
|
|
// small vectors and database
|
|
int d = 64;
|
|
size_t nb = 4000;
|
|
|
|
// ivf centroids
|
|
size_t nlist = 4;
|
|
|
|
// more than 2 threads to surface
|
|
// problems related to multi-threading
|
|
omp_set_num_threads(8);
|
|
|
|
// random database, also used as queries
|
|
std::vector<float> database(nb * d);
|
|
std::mt19937 rng;
|
|
std::uniform_real_distribution<> distrib;
|
|
for (size_t i = 0; i < nb * d; i++) {
|
|
database[i] = distrib(rng);
|
|
}
|
|
|
|
// build index
|
|
faiss::IndexFlatL2 coarse_quantizer(d);
|
|
faiss::IndexIVFPQFastScan index(
|
|
&coarse_quantizer, d, nlist, d / 2, 4, faiss::METRIC_L2, 32);
|
|
index.pq.cp.niter = 10; // speed up train
|
|
index.nprobe = nlist;
|
|
index.train(nb, database.data());
|
|
index.add(nb, database.data());
|
|
|
|
std::vector<float> distances(nb);
|
|
std::vector<faiss::idx_t> labels(nb);
|
|
auto t = std::chrono::high_resolution_clock::now();
|
|
index.search(nb, database.data(), 1, distances.data(), labels.data());
|
|
auto knn_time = std::chrono::high_resolution_clock::now() - t;
|
|
|
|
faiss::RangeSearchResult rsr(nb);
|
|
t = std::chrono::high_resolution_clock::now();
|
|
index.range_search(nb, database.data(), 1.0, &rsr);
|
|
auto range_time = std::chrono::high_resolution_clock::now() - t;
|
|
|
|
// we expect the perf of knn and range search
|
|
// to be similar, at least within a factor of 4
|
|
ASSERT_LE(range_time, knn_time * 4);
|
|
ASSERT_LE(knn_time, range_time * 4);
|
|
}
|