Skip to content

Commit

Permalink
Fixed issue with code hanging when num_threads == 1
Browse files Browse the repository at this point in the history
  • Loading branch information
gopal-msr authored and rakri committed Jan 2, 2025
1 parent 392c49f commit 07e1dfb
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 0 deletions.
28 changes: 28 additions & 0 deletions apps/search_disk_index.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,31 @@

namespace po = boost::program_options;

#ifdef DISKANN_DEBUG_PRINT_RETSET
void dump_retset(uint64_t test_id, uint64_t query_num, diskann::QueryStats *stats, const std::string &result_output_prefix)
{
std::stringstream ss;
if (stats != nullptr)
{
for (int i = 0; i < query_num; i++)
{
ss << i << "\t";
for (int j = 0; j < (stats + i)->query_retset.size(); j++)
{
ss << "(" << (stats + i)->query_retset[j].id << ", " << (stats + i)->query_retset[j].distance
<< "), ";
}
ss << std::endl;
}

}
std::string results_file = result_output_prefix + "_L" + std::to_string(test_id) + "_retset.tsv";
std::ofstream writer(results_file);
writer << ss.str() << std::endl;
writer.close();
}
#endif

#ifdef DISKANN_DEBUG_INDIVIDUAL_RESULTS
void dump_individual_results(uint64_t test_id, uint64_t query_num, uint32_t *gt_ids, float *gt_dists, uint64_t gt_dim,
const std::vector<uint32_t> &query_result_ids,
Expand Down Expand Up @@ -414,6 +439,9 @@ int search_disk_index(diskann::Metric &metric, const std::string &index_path_pre
dump_individual_results(test_id, query_num, gt_ids, gt_dists, gt_dim, query_result_ids[test_id],
query_result_dists[test_id], recall_at, result_output_prefix);
#endif
#ifdef DISKANN_DEBUG_PRINT_RETSET
dump_retset(test_id, query_num, stats, result_output_prefix);
#endif

diskann::cout << std::setw(6) << L << std::setw(12) << optimized_beamwidth << std::setw(16) << qps
<< std::setw(16) << mean_latency << std::setw(16) << latency_999 << std::setw(16) << mean_ios
Expand Down
4 changes: 4 additions & 0 deletions include/percentile_stats.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ struct QueryStats
unsigned n_cmps = 0; // # cmps
unsigned n_cache_hits = 0; // # cache_hits
unsigned n_hops = 0; // # search hops

#ifdef DISKANN_DEBUG_PRINT_RETSET
std::vector<Neighbor> query_retset; //copy of the retset to debug PQ distances.
#endif
};

template <typename T>
Expand Down
24 changes: 24 additions & 0 deletions src/pq_flash_index.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ void PQFlashIndex<T, LabelT>::setup_thread_data(uint64_t nthreads, uint64_t visi
this->_thread_data.push(data);
}
}
this->_thread_data.push_notify_all();
_load_flag = true;
}

Expand Down Expand Up @@ -1431,6 +1432,9 @@ void PQFlashIndex<T, LabelT>::cached_beam_search(const T *query1, const uint64_t
}
compute_dists(&best_medoid, 1, dist_scratch);
retset.insert(Neighbor(best_medoid, dist_scratch[0]));
#ifdef DISKANN_DEBUG_PRINT_RETSET
stats->query_retset.push_back(Neighbor(best_medoid, dist_scratch[0]));
#endif
visited.insert(best_medoid);
cur_list_size = 1;
} else {
Expand Down Expand Up @@ -1638,6 +1642,10 @@ void PQFlashIndex<T, LabelT>::cached_beam_search(const T *query1, const uint64_t
float dist = dist_scratch[m];
Neighbor nn(id, dist);
retset.insert(nn);
#ifdef DISKANN_DEBUG_PRINT_RETSET
stats->query_retset.push_back(nn);
#endif

}
}
}
Expand Down Expand Up @@ -1712,6 +1720,10 @@ void PQFlashIndex<T, LabelT>::cached_beam_search(const T *query1, const uint64_t

Neighbor nn(id, dist);
retset.insert(nn);
#ifdef DISKANN_DEBUG_PRINT_RETSET
stats->query_retset.push_back(nn);
#endif

}
}

Expand All @@ -1725,6 +1737,18 @@ void PQFlashIndex<T, LabelT>::cached_beam_search(const T *query1, const uint64_t
// re-sort by distance
std::sort(full_retset.begin(), full_retset.end());

#ifdef DISKANN_DEBUG_PRINT_RETSET
{
for (int i = 0; i < retset.size(); i++)
{
if (stats != nullptr)
{
stats->query_retset.push_back(retset[i]);
}
}
}
#endif

if (use_reorder_data)
{
if (!(this->_reorder_data_exists))
Expand Down

0 comments on commit 07e1dfb

Please sign in to comment.