Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 74 additions & 0 deletions faiss/perf_tests/bench_hnsw_add.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

#include <fmt/format.h>
#include <gflags/gflags.h>
#include <omp.h>

#include <benchmark/benchmark.h>
#include <faiss/perf_tests/utils.h>
#include <faiss/utils/distances.h>
#include <faiss/utils/random.h>
#include <faiss/utils/utils.h>
#include "faiss/IndexHNSW.h"

using namespace faiss;
DEFINE_uint32(d, 128, "dimension");
DEFINE_uint32(n, 2000, "dimension");
DEFINE_uint32(iterations, 20, "iterations");
DEFINE_uint32(M, 32, "connections per vertex");
DEFINE_uint32(num_omp_threads, 1, "number of omp threads");

DEFINE_uint32(
efConstruction,
40,
"size of the dynamic list containing the nearest neighbors, which is used during index time");

static void bench_add(
benchmark::State& state,
int num_threads,
int d,
int n,
int M,
int efConstruction) {
std::vector<float> x(d * n);

float_rand(x.data(), d * n, 12345);
faiss::IndexHNSWFlat index(d, M);
index.hnsw.efConstruction = efConstruction;

omp_set_num_threads(num_threads);

for (auto _ : state) {
index.add(n, x.data());
}
}

int main(int argc, char** argv) {
benchmark::Initialize(&argc, argv);
gflags::AllowCommandLineReparsing();
gflags::ParseCommandLineFlags(&argc, &argv, true);

int iterations = FLAGS_iterations;
int d = FLAGS_d;
int n = FLAGS_n;
int M = FLAGS_M;
int efConstruction = FLAGS_efConstruction;
int num_threads = FLAGS_num_omp_threads;
benchmark::RegisterBenchmark(
fmt::format("hnsw_add_{}d_{}n_{}M", d, n, M).c_str(),
bench_add,
num_threads,
d,
n,
M,
efConstruction)
->Iterations(iterations);

benchmark::RunSpecifiedBenchmarks();
benchmark::Shutdown();
}
2 changes: 0 additions & 2 deletions faiss/perf_tests/bench_scalar_quantizer_accuracy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ static void bench_reconstruction_error(
ScalarQuantizer::QuantizerType type,
int d,
int n) {
state.SetLabel(faiss::get_compile_options());
std::vector<float> x(d * n);

float_rand(x.data(), d * n, 12345);
Expand Down Expand Up @@ -64,7 +63,6 @@ static void bench_reconstruction_error(
state.counters["ndiff_for_idempotence"] = ndiff;

state.counters["code_size_two"] = codes.size();
state.SetLabel(faiss::get_compile_options());
}

int main(int argc, char** argv) {
Expand Down
1 change: 0 additions & 1 deletion faiss/perf_tests/bench_scalar_quantizer_decode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ static void bench_decode(
ScalarQuantizer::QuantizerType type,
int d,
int n) {
state.SetLabel(faiss::get_compile_options());
std::vector<float> x(d * n);

float_rand(x.data(), d * n, 12345);
Expand Down
3 changes: 0 additions & 3 deletions faiss/perf_tests/bench_scalar_quantizer_distance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ static void bench_distance(
ScalarQuantizer::QuantizerType type,
int n,
int d) {
state.SetLabel(faiss::get_compile_options());
std::vector<float> x(d * n);

float_rand(x.data(), d * n, 12345);
Expand All @@ -46,8 +45,6 @@ static void bench_distance(
std::vector<uint8_t> codes(code_size * n);
sq.compute_codes(x.data(), codes.data(), n);

state.SetLabel(faiss::get_compile_options());

std::unique_ptr<ScalarQuantizer::SQDistanceComputer> dc(
sq.get_distance_computer());
dc->codes = codes.data();
Expand Down
1 change: 0 additions & 1 deletion faiss/perf_tests/bench_scalar_quantizer_encode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ static void bench_encode(
ScalarQuantizer::QuantizerType type,
int d,
int n) {
state.SetLabel(faiss::get_compile_options());
std::vector<float> x(d * n);

float_rand(x.data(), d * n, 12345);
Expand Down