Skip to content

Commit

Permalink
Fix std::lock_guard use for gcc 14 support (#639)
Browse files Browse the repository at this point in the history
The constructor of `std::lock_guard` in gcc 14 <mutex>, which is supported by CUDA 12.8, has the `nodiscard` attribute. This PR fixes the error occurring with gcc 14.

Authors:
  - tsuki (https://github.com/enp1s0)

Approvers:
  - Corey J. Nolet (https://github.com/cjnolet)
  - Artem M. Chirkin (https://github.com/achirkin)

URL: #639
  • Loading branch information
enp1s0 authored Feb 1, 2025
1 parent 88f0dfc commit 995b244
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion cpp/bench/ann/src/common/thread_pool.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class fixed_thread_pool {
finished_.store(true, std::memory_order_relaxed);
for (unsigned i = 0; i < threads_.size(); ++i) {
auto& task = tasks_[i];
std::lock_guard<std::mutex>(task.mtx);
std::lock_guard lock(task.mtx);

task.cv.notify_one();
threads_[i].join();
Expand Down
10 changes: 5 additions & 5 deletions cpp/src/neighbors/iface/iface.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ void build(const raft::device_resources& handle,
const cuvs::neighbors::index_params* index_params,
raft::mdspan<const T, matrix_extent<int64_t>, row_major, Accessor> index_dataset)
{
std::lock_guard(*interface.mutex_);
std::lock_guard lock(*interface.mutex_);

if constexpr (std::is_same<AnnIndexType, ivf_flat::index<T, IdxT>>::value) {
auto idx = cuvs::neighbors::ivf_flat::build(
Expand All @@ -62,7 +62,7 @@ void extend(
std::optional<raft::mdspan<const IdxT, vector_extent<int64_t>, layout_c_contiguous, Accessor2>>
new_indices)
{
std::lock_guard(*interface.mutex_);
std::lock_guard lock(*interface.mutex_);

if constexpr (std::is_same<AnnIndexType, ivf_flat::index<T, IdxT>>::value) {
auto idx =
Expand Down Expand Up @@ -141,7 +141,7 @@ void serialize(const raft::device_resources& handle,
const cuvs::neighbors::iface<AnnIndexType, T, IdxT>& interface,
std::ostream& os)
{
std::lock_guard(*interface.mutex_);
std::lock_guard lock(*interface.mutex_);

if constexpr (std::is_same<AnnIndexType, ivf_flat::index<T, IdxT>>::value) {
ivf_flat::serialize(handle, os, interface.index_.value());
Expand All @@ -157,7 +157,7 @@ void deserialize(const raft::device_resources& handle,
cuvs::neighbors::iface<AnnIndexType, T, IdxT>& interface,
std::istream& is)
{
std::lock_guard(*interface.mutex_);
std::lock_guard lock(*interface.mutex_);

if constexpr (std::is_same<AnnIndexType, ivf_flat::index<T, IdxT>>::value) {
ivf_flat::index<T, IdxT> idx(handle);
Expand All @@ -179,7 +179,7 @@ void deserialize(const raft::device_resources& handle,
cuvs::neighbors::iface<AnnIndexType, T, IdxT>& interface,
const std::string& filename)
{
std::lock_guard(*interface.mutex_);
std::lock_guard lock(*interface.mutex_);

std::ifstream is(filename, std::ios::in | std::ios::binary);
if (!is) { RAFT_FAIL("Cannot open file %s", filename.c_str()); }
Expand Down

0 comments on commit 995b244

Please sign in to comment.