Skip to content

Commit

Permalink
Remove unused variables in faiss/IndexIVF.cpp
Browse files Browse the repository at this point in the history
Summary:
LLVM-15 has a warning `-Wunused-but-set-variable` which we treat as an error because it's so often diagnostic of a code issue. Unused variables can compromise readability or, worse, performance.

This diff either (a) removes an unused variable and, possibly, it's associated code, or (b) qualifies the variable with `[[maybe_unused]]`, mostly in cases where the variable _is_ used, but, eg, in an `assert` statement that isn't present in production code.

 - If you approve of this diff, please use the "Accept & Ship" button :-)

Reviewed By: dmm-fb

Differential Revision: D56065763

fbshipit-source-id: b0541b8a759c4b6ca0e8753fc24b8c227047bd3d
  • Loading branch information
r-barnes authored and facebook-github-bot committed Apr 12, 2024
1 parent acd06d6 commit a35eb0a
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 5 deletions.
1 change: 0 additions & 1 deletion demos/demo_imi_pq.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ int main() {
// the coarse quantizer should not be dealloced before the index
// 4 = nb of bytes per code (d must be a multiple of this)
// 8 = nb of bits per sub-code (almost always 8)
faiss::MetricType metric = faiss::METRIC_L2; // can be METRIC_INNER_PRODUCT
faiss::IndexIVFPQ index(
&coarse_quantizer, d, ncentroids, bytes_per_code, 8);
index.quantizer_trains_alone = true;
Expand Down
4 changes: 2 additions & 2 deletions faiss/IndexIVF.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,7 @@ void IndexIVF::search_preassigned(
max_codes = unlimited_list_size;
}

bool do_parallel = omp_get_max_threads() >= 2 &&
[[maybe_unused]] bool do_parallel = omp_get_max_threads() >= 2 &&
(pmode == 0 ? false
: pmode == 3 ? n > 1
: pmode == 1 ? nprobe > 1
Expand Down Expand Up @@ -784,7 +784,7 @@ void IndexIVF::range_search_preassigned(

int pmode = this->parallel_mode & ~PARALLEL_MODE_NO_HEAP_INIT;
// don't start parallel section if single query
bool do_parallel = omp_get_max_threads() >= 2 &&
[[maybe_unused]] bool do_parallel = omp_get_max_threads() >= 2 &&
(pmode == 3 ? false
: pmode == 0 ? nx > 1
: pmode == 1 ? nprobe > 1
Expand Down
4 changes: 2 additions & 2 deletions faiss/utils/distances.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ void exhaustive_inner_product_seq(
const IDSelector* sel = nullptr) {
using SingleResultHandler =
typename BlockResultHandler::SingleResultHandler;
int nt = std::min(int(nx), omp_get_max_threads());
[[maybe_unused]] int nt = std::min(int(nx), omp_get_max_threads());

FAISS_ASSERT(use_sel == (sel != nullptr));

Expand Down Expand Up @@ -178,7 +178,7 @@ void exhaustive_L2sqr_seq(
const IDSelector* sel = nullptr) {
using SingleResultHandler =
typename BlockResultHandler::SingleResultHandler;
int nt = std::min(int(nx), omp_get_max_threads());
[[maybe_unused]] int nt = std::min(int(nx), omp_get_max_threads());

FAISS_ASSERT(use_sel == (sel != nullptr));

Expand Down

0 comments on commit a35eb0a

Please sign in to comment.