Skip to content

Commit aa76ad9

Browse files
authored
Merge branch 'main' into fea-random-probe-graph
2 parents ecc82db + 9606988 commit aa76ad9

44 files changed

Lines changed: 238 additions & 62 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎.devcontainer/cuda12.9-pip/devcontainer.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"args": {
66
"CUDA": "12.9",
77
"PYTHON_PACKAGE_MANAGER": "pip",
8-
"BASE": "rapidsai/devcontainers:27.02-cpp-cuda12.9-ucx1.21.0-openmpi5.0.10"
8+
"BASE": "rapidsai/devcontainers:27.02-cpp-cuda12.9-ucx1.21.1-openmpi5.0.10"
99
},
1010
"cacheFrom": [
1111
"ghcr.io/nvidia/cuvs/devcontainer:27.02-cuda12.9-pip"

‎.devcontainer/cuda13.4-pip/devcontainer.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"args": {
66
"CUDA": "13.4",
77
"PYTHON_PACKAGE_MANAGER": "pip",
8-
"BASE": "rapidsai/devcontainers:27.02-cpp-cuda13.4-ucx1.21.0-openmpi5.0.10"
8+
"BASE": "rapidsai/devcontainers:27.02-cpp-cuda13.4-ucx1.21.1-openmpi5.0.10"
99
},
1010
"cacheFrom": [
1111
"ghcr.io/nvidia/cuvs/devcontainer:27.02-cuda13.4-pip"

‎c/CMakeLists.txt‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
# cmake-format: on
66
# =============================================================================
77

8-
cmake_minimum_required(VERSION 4.0 FATAL_ERROR)
8+
cmake_minimum_required(VERSION 4.3 FATAL_ERROR)
99
include(../cmake/rapids_config.cmake)
1010
include(rapids-cmake)
1111
include(rapids-cpm)

‎c/src/core/c_api.cpp‎

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -347,19 +347,24 @@ extern "C" cuvsError_t cuvsRMMMemoryResourceReset()
347347
});
348348
}
349349

350-
thread_local std::unique_ptr<rmm::mr::pinned_host_memory_resource> pinned_mr;
350+
namespace {
351+
// One process-wide resource: pinned_host_memory_resource is stateless, so a buffer allocated on
352+
// one thread can be freed on another (a thread_local resource left it null on other threads).
353+
rmm::mr::pinned_host_memory_resource& pinned_mr()
354+
{
355+
static rmm::mr::pinned_host_memory_resource mr;
356+
return mr;
357+
}
358+
} // namespace
351359

352360
extern "C" cuvsError_t cuvsRMMHostAlloc(void** ptr, size_t bytes)
353361
{
354-
return cuvs::core::translate_exceptions([=] {
355-
if (pinned_mr == nullptr) { pinned_mr = std::make_unique<rmm::mr::pinned_host_memory_resource>(); }
356-
*ptr = pinned_mr->allocate_sync(bytes);
357-
});
362+
return cuvs::core::translate_exceptions([=] { *ptr = pinned_mr().allocate_sync(bytes); });
358363
}
359364

360365
extern "C" cuvsError_t cuvsRMMHostFree(void* ptr, size_t bytes)
361366
{
362-
return cuvs::core::translate_exceptions([=] { pinned_mr->deallocate_sync(ptr, bytes); });
367+
return cuvs::core::translate_exceptions([=] { pinned_mr().deallocate_sync(ptr, bytes); });
363368
}
364369

365370
thread_local std::string last_error_text = "";

‎c/tests/CMakeLists.txt‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ ConfigureTest(NAME cuvs_c_headers PATH core/headers.c)
109109
ConfigureTest(NAME cuvs_c_test PATH core/c_api.c)
110110
ConfigureTest(NAME cuvs_c_resource_pool_test PATH core/resource_pool.cpp)
111111
ConfigureTest(NAME cuvs_c_resource_stream_pool_test PATH core/resource_stream_pool.cpp)
112+
ConfigureTest(NAME cuvs_c_host_alloc_test PATH core/host_alloc.cpp)
112113
target_link_libraries(cuvs_c_test PRIVATE CUDA::cudart_static)
113114
target_link_libraries(cuvs_c_resource_pool_test PRIVATE CUDA::cudart_static)
114115
target_link_libraries(cuvs_c_resource_stream_pool_test PRIVATE CUDA::cudart_static)

‎c/tests/core/host_alloc.cpp‎

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
/*
2+
* SPDX-FileCopyrightText: Copyright (c) 2026, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
#include <cuvs/core/c_api.h>
7+
8+
#include <gtest/gtest.h>
9+
10+
#include <atomic>
11+
#include <cstddef>
12+
#include <thread>
13+
#include <vector>
14+
15+
// Pinned host buffers may be freed on a different thread than the one that allocated them, e.g.
16+
// when a binding moves the owning object across threads.
17+
TEST(RMMHostAlloc, FreeOnAnotherThread)
18+
{
19+
constexpr std::size_t kBytes = 1024;
20+
void* ptr = nullptr;
21+
cuvsError_t alloc_status = CUVS_ERROR;
22+
std::thread([&] { alloc_status = cuvsRMMHostAlloc(&ptr, kBytes); }).join();
23+
ASSERT_EQ(alloc_status, CUVS_SUCCESS);
24+
ASSERT_NE(ptr, nullptr);
25+
26+
cuvsError_t free_status = CUVS_ERROR;
27+
std::thread([&] { free_status = cuvsRMMHostFree(ptr, kBytes); }).join();
28+
EXPECT_EQ(free_status, CUVS_SUCCESS);
29+
}
30+
31+
TEST(RMMHostAlloc, ConcurrentAllocAndFree)
32+
{
33+
constexpr int kThreads = 8;
34+
constexpr int kIters = 50;
35+
constexpr std::size_t kBytes = 4096;
36+
std::vector<void*> ptrs(kThreads * kIters, nullptr);
37+
std::atomic<int> failures{0};
38+
39+
std::vector<std::thread> threads;
40+
for (int t = 0; t < kThreads; ++t) {
41+
threads.emplace_back([&, t] {
42+
for (int i = 0; i < kIters; ++i) {
43+
if (cuvsRMMHostAlloc(&ptrs[t * kIters + i], kBytes) != CUVS_SUCCESS) { failures++; }
44+
}
45+
});
46+
}
47+
for (auto& th : threads) {
48+
th.join();
49+
}
50+
threads.clear();
51+
ASSERT_EQ(failures.load(), 0);
52+
53+
// Free every buffer from a different thread than the one that allocated it.
54+
for (int t = 0; t < kThreads; ++t) {
55+
threads.emplace_back([&, t] {
56+
int const owner = (t + 1) % kThreads;
57+
for (int i = 0; i < kIters; ++i) {
58+
if (cuvsRMMHostFree(ptrs[owner * kIters + i], kBytes) != CUVS_SUCCESS) { failures++; }
59+
}
60+
});
61+
}
62+
for (auto& th : threads) {
63+
th.join();
64+
}
65+
EXPECT_EQ(failures.load(), 0);
66+
}

‎ci/standalone_c/build_standalone_c.sh‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ source rapids-install-sccache
2323
source rapids-configure-sccache
2424

2525
PIP_PACKAGES=(
26-
'cmake>=4.0,<4.5'
26+
'cmake>=4.3,<4.5'
2727
'git+https://github.com/rapidsai/spdx-license-builder.git'
2828
'ninja>=1.13'
2929
)

‎ci/test_standalone_c.sh‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
set -euo pipefail
66

7-
rapids-pip-retry install "cmake<4.5"
7+
rapids-pip-retry install "cmake>=4.3,<4.5"
88
pyenv rehash
99

1010
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"

‎cmake/RAPIDS.cmake‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
# This is the preferred entry point for projects using rapids-cmake
99
#
1010
# Enforce the minimum required CMake version for all users
11-
cmake_minimum_required(VERSION 4.0 FATAL_ERROR)
11+
cmake_minimum_required(VERSION 4.3 FATAL_ERROR)
1212

1313
# Allow users to control which version is used
1414
if(NOT (rapids-cmake-branch OR rapids-cmake-version))

‎conda/environments/all_cuda-129_arch-aarch64.yaml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ dependencies:
99
- c-compiler
1010
- clang-tools==20.1.8
1111
- clang==20.1.8
12-
- cmake>=4.0,<4.5
12+
- cmake>=4.3,<4.5
1313
- cuda-bindings>=12.9.3,<13.0
1414
- cuda-nvcc
1515
- cuda-nvrtc-dev

0 commit comments

Comments
 (0)