Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add static omp #564

Open
wants to merge 3 commits into
base: python_bindings_diskann
Choose a base branch
from
Open
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
14 changes: 12 additions & 2 deletions python/src/diskann_bindings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
#include <omp.h>
#include <string>
#include <memory>
#include <chrono>
#include <iostream>

#include <pybind11/numpy.h>
#include <pybind11/pybind11.h>
Expand Down Expand Up @@ -158,15 +160,22 @@ struct DiskANNIndex {
const _u64 l_search, const _u64 beam_width, const int num_threads) {
py::array_t<unsigned> ids({num_queries, knn});
py::array_t<float> dists({num_queries, knn});

// auto start = std::chrono::high_resolution_clock::now();
std::vector<_u64> u64_ids(knn * num_queries);
diskann::QueryStats *stats = new diskann::QueryStats[num_queries];

#pragma omp parallel for schedule(dynamic, 1)
#pragma omp parallel for schedule(static, 100)
for (_u64 i = 0; i < num_queries; i++) {
auto start = std::chrono::high_resolution_clock::now();
pq_flash_index->cached_beam_search(
queries.data(i), knn, l_search, u64_ids.data() + i * knn,
dists.mutable_data(i), beam_width, stats + i);
auto stop = std::chrono::high_resolution_clock::now();

auto duration = std::chrono::duration_cast<std::chrono::microseconds>(stop - start);

std::cout << "Time taken by function: "
<< duration.count() << " microseconds" << std::endl;
}

auto r = ids.mutable_unchecked();
Expand All @@ -188,6 +197,7 @@ struct DiskANNIndex {
stats, num_queries,
[](const diskann::QueryStats &stats) { return stats.n_cmps; });
delete[] stats;

return std::make_pair(std::make_pair(ids, dists), collective_stats);
}

Expand Down