Skip to content

Commit 6b5b472

Browse files
authored
Expand NVTX annotations in CAGRA build and HNSW (#711)
Add a few more NVTX annotations in CAGRA and HNSW routines to make it easier to analyze index build times. Add the missing `NVTX_ENABLED` definition to `cuvs_objs` (without this, only CAGRA-search-related annotations are enabled as they are a part of a different component). Authors: - Artem M. Chirkin (https://github.com/achirkin) Approvers: - Corey J. Nolet (https://github.com/cjnolet) URL: #711
1 parent 3c9e745 commit 6b5b472

3 files changed

Lines changed: 26 additions & 8 deletions

File tree

cpp/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -636,6 +636,7 @@ SECTIONS
636636
if(CUVS_NVTX)
637637
# This enables NVTX within the project with no option to disable it downstream.
638638
target_link_libraries(cuvs PUBLIC CUDA::nvtx3)
639+
target_compile_definitions(cuvs_objs PUBLIC NVTX_ENABLED)
639640
target_compile_definitions(cuvs PUBLIC NVTX_ENABLED)
640641

641642
target_link_libraries(cuvs-cagra-search PUBLIC CUDA::nvtx3)

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include <raft/core/resources.hpp>
2525

2626
// TODO: This shouldn't be invoking anything from spatial/knn
27+
#include "../../../core/nvtx.hpp"
2728
#include "../ann_utils.cuh"
2829

2930
#include <raft/util/bitonic_sort.cuh>
@@ -1086,6 +1087,8 @@ void optimize(
10861087
const uint64_t graph_size = new_graph.extent(0);
10871088
auto input_graph_ptr = knn_graph.data_handle();
10881089
auto output_graph_ptr = new_graph.data_handle();
1090+
raft::common::nvtx::range<cuvs::common::nvtx::domain::cuvs> fun_scope(
1091+
"cagra::graph::optimize(%zu, %zu, %u)", graph_size, input_graph_degree, output_graph_degree);
10891092

10901093
// MST optimization
10911094
auto mst_graph = raft::make_host_matrix<IdxT, int64_t, raft::row_major>(0, 0);
@@ -1096,6 +1099,8 @@ void optimize(
10961099
mst_graph_num_edges_ptr[i] = 0;
10971100
}
10981101
if (guarantee_connectivity) {
1102+
raft::common::nvtx::range<cuvs::common::nvtx::domain::cuvs> block_scope(
1103+
"cagra::graph::optimize/check_connectivity");
10991104
mst_graph =
11001105
raft::make_host_matrix<IdxT, int64_t, raft::row_major>(graph_size, output_graph_degree);
11011106
RAFT_LOG_INFO("MST optimization is used to guarantee graph connectivity.");
@@ -1110,6 +1115,8 @@ void optimize(
11101115
}
11111116

11121117
{
1118+
raft::common::nvtx::range<cuvs::common::nvtx::domain::cuvs> block_scope(
1119+
"cagra::graph::optimize/prune");
11131120
//
11141121
// Prune kNN graph
11151122
//
@@ -1270,6 +1277,8 @@ void optimize(
12701277
auto rev_graph_count = raft::make_host_vector<uint32_t, int64_t>(graph_size);
12711278

12721279
{
1280+
raft::common::nvtx::range<cuvs::common::nvtx::domain::cuvs> block_scope(
1281+
"cagra::graph::optimize/reverse");
12731282
//
12741283
// Make reverse graph
12751284
//
@@ -1335,6 +1344,8 @@ void optimize(
13351344
}
13361345

13371346
{
1347+
raft::common::nvtx::range<cuvs::common::nvtx::domain::cuvs> block_scope(
1348+
"cagra::graph::optimize/combine");
13381349
//
13391350
// Create search graphs from MST and pruned and reverse graphs
13401351
//
@@ -1435,6 +1446,8 @@ void optimize(
14351446

14361447
// Check number of incoming edges
14371448
{
1449+
raft::common::nvtx::range<cuvs::common::nvtx::domain::cuvs> block_scope(
1450+
"cagra::graph::optimize/check_edges");
14381451
auto in_edge_count = raft::make_host_vector<uint32_t, int64_t>(graph_size);
14391452
auto in_edge_count_ptr = in_edge_count.data_handle();
14401453
#pragma omp parallel for
@@ -1477,6 +1490,8 @@ void optimize(
14771490

14781491
// Check duplication and out-of-range indices
14791492
{
1493+
raft::common::nvtx::range<cuvs::common::nvtx::domain::cuvs> block_scope(
1494+
"cagra::graph::optimize/check_duplicates");
14801495
uint64_t num_dup = 0;
14811496
uint64_t num_oor = 0;
14821497
#pragma omp parallel for reduction(+ : num_dup) reduction(+ : num_oor)

cpp/src/neighbors/hnsw.cpp

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,22 @@
1515
*/
1616

1717
#include "detail/hnsw.hpp"
18+
#include "../core/nvtx.hpp"
1819
#include <cstdint>
1920
#include <cuvs/neighbors/hnsw.hpp>
2021
#include <sys/types.h>
2122

2223
namespace cuvs::neighbors::hnsw {
2324

24-
#define CUVS_INST_HNSW_FROM_CAGRA(T) \
25-
std::unique_ptr<index<T>> from_cagra( \
26-
raft::resources const& res, \
27-
const index_params& params, \
28-
const cuvs::neighbors::cagra::index<T, uint32_t>& cagra_index, \
29-
std::optional<raft::host_matrix_view<const T, int64_t, raft::row_major>> dataset) \
30-
{ \
31-
return detail::from_cagra<T>(res, params, cagra_index, dataset); \
25+
#define CUVS_INST_HNSW_FROM_CAGRA(T) \
26+
std::unique_ptr<index<T>> from_cagra( \
27+
raft::resources const& res, \
28+
const index_params& params, \
29+
const cuvs::neighbors::cagra::index<T, uint32_t>& cagra_index, \
30+
std::optional<raft::host_matrix_view<const T, int64_t, raft::row_major>> dataset) \
31+
{ \
32+
raft::common::nvtx::range<cuvs::common::nvtx::domain::cuvs> fun_scope("hnsw::from_cagra"); \
33+
return detail::from_cagra<T>(res, params, cagra_index, dataset); \
3234
}
3335

3436
CUVS_INST_HNSW_FROM_CAGRA(float);

0 commit comments

Comments
 (0)