diff --git a/.circleci/config.yml b/.circleci/config.yml index 7e8bd8170a..3914da46d7 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -39,16 +39,12 @@ jobs: name: Install clang-format command: | apt-get update -y - apt-get install -y wget - apt install -y lsb-release wget software-properties-common gnupg - wget https://apt.llvm.org/llvm.sh - chmod u+x llvm.sh - ./llvm.sh 18 - apt-get install -y git-core clang-format-18 + apt-get install -y curl tar gzip + bash .circleci/setup-clang-format.sh - run: name: Verify clang-format command: | - git ls-files | grep -E '\.(cpp|h|cu|cuh)$' | xargs clang-format-18 -i + git ls-files | grep -E '\.(cpp|h|cu|cuh)$' | xargs clang-format -i if git diff --quiet; then echo "Formatting OK!" else diff --git a/.circleci/setup-clang-format.sh b/.circleci/setup-clang-format.sh new file mode 100755 index 0000000000..a94691f9e1 --- /dev/null +++ b/.circleci/setup-clang-format.sh @@ -0,0 +1,43 @@ +#!/bin/bash +# (c) Meta Platforms, Inc. and affiliates. Confidential and proprietary. + +set -euo pipefail +# https://reproducible-builds.org/docs/archives/ +deterministic_tar_gz() { + # Use year 2030 to thwart tmpreaper. + tar \ + --sort=name \ + --mtime=2030-01-01T00:00:00Z \ + --owner=0 --group=0 --numeric-owner \ + -cf- \ + "${@:2}" \ + | gzip -9n \ + > "$1" +} + +# To curl from devservers +if host -W 1 fwdproxy >/dev/null; then + curl() { HTTP_PROXY=fwdproxy:8080 HTTPS_PROXY=fwdproxy:8080 command curl "$@"; } +fi + +### CHANGE THESE VARIABLES WHEN UPDATING ### + +# https://pypi.org/project/clang-format/18.1.3 + + +LINUX_X86_64_URL=https://files.pythonhosted.org/packages/d5/9c/4f3806d20397790b3cd80aef89d295bf399581804f5c5758b6207e54e902/clang_format-18.1.3-py2.py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl + +### +NAME=${LINUX_X86_64_URL##*/} + +set -x +curl -L -o "$NAME.zip" "$LINUX_X86_64_URL" +mkdir "clang-format" +unzip -q -d "clang-format" "$NAME.zip" +echo "clang-format/clang_format/data/bin" +deterministic_tar_gz "$NAME.tar.gz" -C "clang-format/clang_format/data/bin" "clang-format" +tar tvf "$NAME.tar.gz" + +echo "$PWD" +export PATH="${PWD}/clang-format/clang_format/data/bin:$PATH" +echo $PATH diff --git a/faiss/impl/NNDescent.cpp b/faiss/impl/NNDescent.cpp index b609aba390..5afcdaf5b7 100644 --- a/faiss/impl/NNDescent.cpp +++ b/faiss/impl/NNDescent.cpp @@ -154,15 +154,20 @@ NNDescent::NNDescent(const int d, const int K) : K(K), d(d) { NNDescent::~NNDescent() {} void NNDescent::join(DistanceComputer& qdis) { + idx_t check_period = InterruptCallback::get_period_hint(d * search_L); + for (idx_t i0 = 0; i0 < (idx_t)ntotal; i0 += check_period) { + idx_t i1 = std::min(i0 + check_period, (idx_t)ntotal); #pragma omp parallel for default(shared) schedule(dynamic, 100) - for (int n = 0; n < ntotal; n++) { - graph[n].join([&](int i, int j) { - if (i != j) { - float dist = qdis.symmetric_dis(i, j); - graph[i].insert(j, dist); - graph[j].insert(i, dist); - } - }); + for (idx_t n = i0; n < i1; n++) { + graph[n].join([&](int i, int j) { + if (i != j) { + float dist = qdis.symmetric_dis(i, j); + graph[i].insert(j, dist); + graph[j].insert(i, dist); + } + }); + } + InterruptCallback::check(); } }