Skip to content

Commit 885c056

Browse files
committed
Tune CAGRA hashmap minimum size
Expose the hashmap bit-length floor to benchmarks and select the automatic default from the GPU's shared-memory capacity for SINGLE_CTA searches while preserving the MULTI_CTA default.
1 parent 7a6ca7a commit 885c056

3 files changed

Lines changed: 18 additions & 4 deletions

File tree

cpp/bench/ann/src/cuvs/cuvs_ann_bench_param_parser.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -489,6 +489,9 @@ void parse_search_param(const nlohmann::json& conf,
489489
if (conf.contains("thread_block_size")) {
490490
param.p.thread_block_size = conf.at("thread_block_size");
491491
}
492+
if (conf.contains("hashmap_min_bitlen")) {
493+
param.p.hashmap_min_bitlen = conf.at("hashmap_min_bitlen");
494+
}
492495
if (conf.contains("algo")) {
493496
if (conf.at("algo") == "single_cta") {
494497
param.p.algo = cuvs::neighbors::cagra::search_algo::SINGLE_CTA;

cpp/include/cuvs/neighbors/cagra.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,7 @@ struct search_params : cuvs::neighbors::search_params {
367367
size_t thread_block_size = 0;
368368
/** Hashmap type. Auto selection when AUTO. */
369369
hash_mode hashmap_mode = hash_mode::AUTO;
370-
/** Lower limit of hashmap bit length. More than 8. */
370+
/** Lower limit of hashmap bit length. 0 selects the default; otherwise, 8 to 20. */
371371
size_t hashmap_min_bitlen = 0;
372372
/** Upper limit of hashmap fill rate. More than 0.1, less than 0.9.*/
373373
float hashmap_max_fill_rate = 0.5;

cpp/src/neighbors/detail/cagra/search_plan.cuh

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include <cuvs/neighbors/common.hpp>
1111
#include <neighbors/detail/cagra/compute_distance-ext.cuh>
1212
#include <raft/core/resource/cuda_stream.hpp>
13+
#include <raft/core/resource/device_properties.hpp>
1314
// #include "topk_for_cagra/topk.h"
1415

1516
#include <raft/core/device_mdspan.hpp>
@@ -297,6 +298,17 @@ struct search_plan_impl : public search_plan_impl_base {
297298
}
298299
RAFT_EXPECTS(hash_bitlen <= 25, "hash_bitlen cannot be largen than 25 (32M)");
299300
} else {
301+
constexpr size_t kib = 1024;
302+
const auto shared_mem_per_sm =
303+
raft::resource::get_device_properties(res).sharedMemPerMultiprocessor;
304+
unsigned default_min_bitlen = 8;
305+
if (shared_mem_per_sm >= 196 * kib) {
306+
default_min_bitlen = 11;
307+
} else if (shared_mem_per_sm >= 128 * kib) {
308+
default_min_bitlen = 10;
309+
} else if (shared_mem_per_sm >= 64 * kib) {
310+
default_min_bitlen = 9;
311+
}
300312
while (hashmap_mode == hash_mode::AUTO || hashmap_mode == hash_mode::SMALL) {
301313
//
302314
// The small-hash reduces hash table size by initializing the hash table
@@ -306,10 +318,9 @@ struct search_plan_impl : public search_plan_impl_base {
306318
// visited per iteration.
307319
//
308320
const auto max_visited_nodes = itopk_size + (search_width * graph_degree * 1);
309-
unsigned min_bitlen = 8; // 256
321+
unsigned min_bitlen = hashmap_min_bitlen == 0 ? default_min_bitlen : hashmap_min_bitlen;
310322
unsigned max_bitlen = 13; // 8K
311-
if (min_bitlen < hashmap_min_bitlen) { min_bitlen = hashmap_min_bitlen; }
312-
hash_bitlen = min_bitlen;
323+
hash_bitlen = min_bitlen;
313324
while (max_visited_nodes > hashmap::get_size(hash_bitlen) * max_fill_rate) {
314325
hash_bitlen += 1;
315326
}

0 commit comments

Comments
 (0)