From 9adb66072a617d8b337137a120d6e100434f692f Mon Sep 17 00:00:00 2001 From: I <1091761+wx257osn2@users.noreply.github.com> Date: Wed, 31 May 2023 13:00:30 -0700 Subject: [PATCH] Fix windows CI (#2889) Summary: https://github.com/facebookresearch/faiss/issues/2882 added [a for loop, which has unsigned index, qualified with `#pragma omp parallel for`](https://github.com/facebookresearch/faiss/pull/2882/files#diff-5a89dcb99a1cce3f297c7f7dfc8e221306b281d4ced6dac1e0fc0fa54188195fR449-R452), but it seems that [MSVC doesn't support unsigned index with `#pragma omp parallel for`](https://app.circleci.com/pipelines/github/facebookresearch/faiss/4220/workflows/ee72de05-6ead-42d9-8ec5-44772e9fd41b/jobs/22529?invite=true#step-104-333) (I think this would not be conformed to OpenMP specification, but...) I (finally) change the loop with signed index. This changes introduce the precondition `n <= std::numeric_limits>::max()` , but usually this is `true` I think, so I just put this limitation as a comment instead of any `FAISS_ASSERT` or something like that. Pull Request resolved: https://github.com/facebookresearch/faiss/pull/2889 Reviewed By: wickedfoo Differential Revision: D46325322 Pulled By: alexanderguzhva fbshipit-source-id: c68f4c8be3db188ac067e053c6c716e2896f75c0 --- faiss/utils/utils.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/faiss/utils/utils.cpp b/faiss/utils/utils.cpp index 9cc8d3fe45..5f3e5eb964 100644 --- a/faiss/utils/utils.cpp +++ b/faiss/utils/utils.cpp @@ -28,6 +28,7 @@ #include #include +#include #include #include @@ -446,8 +447,13 @@ uint64_t bvec_checksum(size_t n, const uint8_t* a) { } void bvecs_checksum(size_t n, size_t d, const uint8_t* a, uint64_t* cs) { -#pragma omp parallel for if (n > 1000) - for (size_t i = 0; i < n; i++) { + // MSVC can't accept unsigned index for #pragma omp parallel for + // so below codes only accept n <= std::numeric_limits::max() + using ssize_t = std::make_signed::type; + const ssize_t size = n; +#pragma omp parallel for if (size > 1000) + for (ssize_t i_ = 0; i_ < size; i_++) { + const auto i = static_cast(i_); cs[i] = bvec_checksum(d, a + i * d); } }