Skip to content

Commit bd94586

Browse files
Allow compilation when OpenMP is disabled (#1346)
Since we compile CUVS with warnings as errors, we need to disable the unknown pragma warning generated by our OpenMP pragmas so we can still compile. Authors: - Robert Maynard (https://github.com/robertmaynard) - Corey J. Nolet (https://github.com/cjnolet) Approvers: - Tamas Bela Feher (https://github.com/tfeher) URL: #1346
1 parent d399d3a commit bd94586

3 files changed

Lines changed: 14 additions & 5 deletions

File tree

cpp/cmake/modules/ConfigureCUDA.cmake

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@ if(DISABLE_DEPRECATION_WARNINGS)
1919
)
2020
endif()
2121

22+
if(DISABLE_OPENMP)
23+
list(APPEND CUVS_CXX_FLAGS -Wno-unknown-pragmas)
24+
list(APPEND CUVS_CUDA_FLAGS -Xcompiler=-Wno-unknown-pragmas)
25+
endif()
26+
2227
# Be very strict when compiling with GCC as host compiler (and thus more lenient when compiling with
2328
# clang)
2429
if(CMAKE_COMPILER_IS_GNUCXX)

cpp/src/neighbors/detail/hnsw.hpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,8 @@ std::enable_if_t<hierarchy == HnswHierarchy::CPU, std::unique_ptr<index<T>>> fro
193193
cagra_index.graph().extent(1) / 2,
194194
params.ef_construction);
195195
appr_algo->base_layer_init = false; // tell hnswlib to build upper layers only
196-
auto num_threads = params.num_threads == 0 ? omp_get_max_threads() : params.num_threads;
196+
[[maybe_unused]] auto num_threads =
197+
params.num_threads == 0 ? omp_get_max_threads() : params.num_threads;
197198
#pragma omp parallel for num_threads(num_threads)
198199
for (int64_t i = 0; i < host_dataset_view.extent(0); i++) {
199200
appr_algo->addPoint((void*)(host_dataset_view.data_handle() + i * host_dataset_view.extent(1)),
@@ -544,7 +545,8 @@ void extend(raft::resources const& res,
544545
const_cast<void*>(idx.get_index()));
545546
auto current_element_count = hnswlib_index->getCurrentElementCount();
546547
auto new_element_count = additional_dataset.extent(0);
547-
auto num_threads = params.num_threads == 0 ? omp_get_max_threads() : params.num_threads;
548+
[[maybe_unused]] auto num_threads =
549+
params.num_threads == 0 ? omp_get_max_threads() : params.num_threads;
548550

549551
hnswlib_index->resizeIndex(current_element_count + new_element_count);
550552
#pragma omp parallel for num_threads(num_threads)

cpp/src/neighbors/refine/refine_host.hpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2023-2024, NVIDIA CORPORATION.
2+
* Copyright (c) 2023-2025, NVIDIA CORPORATION.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -370,10 +370,12 @@ template <typename DC, typename IdxT, typename DataT, typename DistanceT, typena
370370
// taking this into account.
371371
auto n_elements = std::max(size_t(512), dim);
372372
auto max_n_threads = raft::div_rounding_up_safe<size_t>(n_queries * orig_k * dim, n_elements);
373-
auto suggested_n_threads_for_distance = std::min(size_t(suggested_n_threads), max_n_threads);
373+
[[maybe_unused]] auto suggested_n_threads_for_distance =
374+
std::min(size_t(suggested_n_threads), max_n_threads);
374375

375376
// The max number of threads for topk computation is the number of queries.
376-
auto suggested_n_threads_for_topk = std::min(size_t(suggested_n_threads), n_queries);
377+
[[maybe_unused]] auto suggested_n_threads_for_topk =
378+
std::min(size_t(suggested_n_threads), n_queries);
377379

378380
// Compute the refined distance using original dataset vectors
379381
#pragma omp parallel for collapse(2) num_threads(suggested_n_threads_for_distance)

0 commit comments

Comments
 (0)