Skip to content

Commit c312df7

Browse files
authored
Move get_memory_resource into libcu++ (#4742)
* Move `get_memory_resource` into libcu++ * Expose a private __get_memory_resource_t regardless of `LIBCUDACXX_ENABLE_EXPERIMENTAL_MEMORY_RESOURCE`
1 parent 78e11b3 commit c312df7

File tree

10 files changed

+269
-222
lines changed

10 files changed

+269
-222
lines changed

cudax/include/cuda/experimental/__container/async_buffer.cuh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include <thrust/fill.h>
2828
#include <thrust/for_each.h>
2929

30+
#include <cuda/__memory_resource/get_memory_resource.h>
3031
#include <cuda/__memory_resource/properties.h>
3132
#include <cuda/__memory_resource/resource_ref.h>
3233
#include <cuda/__stream/get_stream.h>
@@ -64,7 +65,6 @@
6465
#include <cuda/experimental/__execution/policy.cuh>
6566
#include <cuda/experimental/__launch/host_launch.cuh>
6667
#include <cuda/experimental/__memory_resource/any_resource.cuh>
67-
#include <cuda/experimental/__memory_resource/get_memory_resource.cuh>
6868
#include <cuda/experimental/__memory_resource/properties.cuh>
6969
#include <cuda/experimental/__utility/ensure_current_device.cuh>
7070
#include <cuda/experimental/__utility/select_execution_space.cuh>
@@ -306,7 +306,7 @@ public:
306306
//! At the destruction of the \c async_buffer all elements in the range `[vec.begin(), vec.end())` will be destroyed.
307307
_CCCL_HIDE_FROM_ABI explicit async_buffer(
308308
const __env_t& __env, const size_type __size, ::cuda::experimental::no_init_t)
309-
: __buf_(::cuda::experimental::get_memory_resource(__env), ::cuda::get_stream(__env), __size)
309+
: __buf_(::cuda::mr::get_memory_resource(__env), ::cuda::get_stream(__env), __size)
310310
{}
311311

312312
//! @brief Constructs a async_buffer using a memory resource and copy-constructs all elements from the forward range

cudax/include/cuda/experimental/__execution/env.cuh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
# pragma system_header
2222
#endif // no system header
2323

24+
#include <cuda/__memory_resource/get_memory_resource.h>
2425
#include <cuda/__memory_resource/properties.h>
2526
#include <cuda/__stream/get_stream.h>
2627
#include <cuda/std/__execution/env.h>
@@ -32,7 +33,6 @@
3233
#include <cuda/experimental/__execution/queries.cuh>
3334
#include <cuda/experimental/__memory_resource/any_resource.cuh>
3435
#include <cuda/experimental/__memory_resource/device_memory_resource.cuh>
35-
#include <cuda/experimental/__memory_resource/get_memory_resource.cuh>
3636
#include <cuda/experimental/__stream/stream_ref.cuh>
3737

3838
#include <cuda/experimental/__execution/prologue.cuh>
@@ -141,7 +141,7 @@ public:
141141
//! properties we need
142142
template <class _Env>
143143
static constexpr bool __is_compatible_env =
144-
_CUDA_STD_EXEC::__queryable_with<_Env, get_memory_resource_t> //
144+
_CUDA_STD_EXEC::__queryable_with<_Env, ::cuda::mr::get_memory_resource_t> //
145145
&& _CUDA_STD_EXEC::__queryable_with<_Env, ::cuda::get_stream_t>
146146
&& _CUDA_STD_EXEC::__queryable_with<_Env, execution::get_execution_policy_t>;
147147

@@ -150,12 +150,12 @@ public:
150150
_CCCL_TEMPLATE(class _Env)
151151
_CCCL_REQUIRES((!_CCCL_TRAIT(_CUDA_VSTD::is_same, _Env, env_t)) _CCCL_AND __is_compatible_env<_Env>)
152152
_CCCL_HIDE_FROM_ABI env_t(const _Env& __env) noexcept
153-
: __mr_(__env.query(get_memory_resource))
153+
: __mr_(__env.query(::cuda::mr::get_memory_resource))
154154
, __stream_(__env.query(::cuda::get_stream))
155155
, __policy_(__env.query(execution::get_execution_policy))
156156
{}
157157

158-
[[nodiscard]] _CCCL_HIDE_FROM_ABI const __resource& query(get_memory_resource_t) const noexcept
158+
[[nodiscard]] _CCCL_HIDE_FROM_ABI const __resource& query(::cuda::mr::get_memory_resource_t) const noexcept
159159
{
160160
return __mr_;
161161
}

cudax/include/cuda/experimental/memory_resource.cuh

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
#include <cuda/experimental/__memory_resource/any_resource.cuh>
2626
#include <cuda/experimental/__memory_resource/device_memory_pool.cuh>
2727
#include <cuda/experimental/__memory_resource/device_memory_resource.cuh>
28-
#include <cuda/experimental/__memory_resource/get_memory_resource.cuh>
2928
#include <cuda/experimental/__memory_resource/legacy_pinned_memory_resource.cuh>
3029
#include <cuda/experimental/__memory_resource/managed_memory_resource.cuh>
3130
#include <cuda/experimental/__memory_resource/pinned_memory_pool.cuh>

cudax/test/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,6 @@ foreach(cn_target IN LISTS cudax_TARGETS)
124124
memory_resource/any_resource.cu
125125
memory_resource/memory_pools.cu
126126
memory_resource/device_memory_resource.cu
127-
memory_resource/get_memory_resource.cu
128127
memory_resource/managed_memory_resource.cu
129128
memory_resource/pinned_memory_resource.cu
130129
memory_resource/shared_resource.cu

cudax/test/containers/async_buffer/copy.cu

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -99,15 +99,15 @@ C2H_TEST("cudax::async_buffer make_async_buffer", "[container][async_buffer]", t
9999
cudax::stream other_stream{};
100100
{ // empty input
101101
const Buffer input{env};
102-
const auto buf = cudax::make_async_buffer(other_stream, env.query(cudax::get_memory_resource), input);
102+
const auto buf = cudax::make_async_buffer(other_stream, env.query(cuda::mr::get_memory_resource), input);
103103
static_assert(!cuda::std::is_same_v<Buffer, cuda::std::remove_const_t<decltype(buf)>>);
104104
CUDAX_CHECK(buf.empty());
105105
CUDAX_CHECK(buf.data() == nullptr);
106106
}
107107

108108
{ // non-empty input
109109
const Buffer input{env, {T(1), T(42), T(1337), T(0), T(12), T(-1)}};
110-
const auto buf = cudax::make_async_buffer(other_stream, env.query(cudax::get_memory_resource), input);
110+
const auto buf = cudax::make_async_buffer(other_stream, env.query(cuda::mr::get_memory_resource), input);
111111
static_assert(!cuda::std::is_same_v<Buffer, cuda::std::remove_const_t<decltype(buf)>>);
112112
CUDAX_CHECK(!buf.empty());
113113
CUDAX_CHECK(equal_range(buf));
@@ -118,31 +118,31 @@ C2H_TEST("cudax::async_buffer make_async_buffer", "[container][async_buffer]", t
118118
{
119119
{ // empty input
120120
const Buffer input{env};
121-
const auto buf = cudax::make_async_buffer(stream, env.query(cudax::get_memory_resource), input);
121+
const auto buf = cudax::make_async_buffer(stream, env.query(cuda::mr::get_memory_resource), input);
122122
static_assert(!cuda::std::is_same_v<Buffer, cuda::std::remove_const_t<decltype(buf)>>);
123123
CUDAX_CHECK(buf.empty());
124124
CUDAX_CHECK(buf.data() == nullptr);
125125
}
126126

127127
{ // non-empty input
128128
const Buffer input{env, {T(1), T(42), T(1337), T(0), T(12), T(-1)}};
129-
const auto buf = cudax::make_async_buffer(stream, env.query(cudax::get_memory_resource), input);
129+
const auto buf = cudax::make_async_buffer(stream, env.query(cuda::mr::get_memory_resource), input);
130130
static_assert(!cuda::std::is_same_v<Buffer, cuda::std::remove_const_t<decltype(buf)>>);
131131
CUDAX_CHECK(!buf.empty());
132132
CUDAX_CHECK(equal_range(buf));
133133
}
134134

135135
{ // empty input
136136
const Buffer input{env};
137-
const auto buf = cudax::make_async_buffer(stream, env.query(cudax::get_memory_resource), input);
137+
const auto buf = cudax::make_async_buffer(stream, env.query(cuda::mr::get_memory_resource), input);
138138
static_assert(!cuda::std::is_same_v<Buffer, cuda::std::remove_const_t<decltype(buf)>>);
139139
CUDAX_CHECK(buf.empty());
140140
CUDAX_CHECK(buf.data() == nullptr);
141141
}
142142

143143
{ // non-empty input
144144
const Buffer input{env, {T(1), T(42), T(1337), T(0), T(12), T(-1)}};
145-
const auto buf = cudax::make_async_buffer(stream, env.query(cudax::get_memory_resource), input);
145+
const auto buf = cudax::make_async_buffer(stream, env.query(cuda::mr::get_memory_resource), input);
146146
static_assert(!cuda::std::is_same_v<Buffer, cuda::std::remove_const_t<decltype(buf)>>);
147147
CUDAX_CHECK(!buf.empty());
148148
CUDAX_CHECK(equal_range(buf));

cudax/test/execution/env.cu

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ struct test_resource
4848
C2H_TEST("env_t is queryable for all properties we want", "[execution, env]")
4949
{
5050
STATIC_REQUIRE(cuda::std::execution::__queryable_with<env_t, cuda::get_stream_t>);
51-
STATIC_REQUIRE(cuda::std::execution::__queryable_with<env_t, cudax::get_memory_resource_t>);
51+
STATIC_REQUIRE(cuda::std::execution::__queryable_with<env_t, cuda::mr::get_memory_resource_t>);
5252
STATIC_REQUIRE(cuda::std::execution::__queryable_with<env_t, cudax::execution::get_execution_policy_t>);
5353
}
5454

@@ -58,7 +58,7 @@ C2H_TEST("env_t is default constructible", "[execution, env]")
5858
CHECK(env.query(cuda::get_stream) == ::cuda::experimental::detail::__invalid_stream);
5959
CHECK(env.query(cudax::execution::get_execution_policy)
6060
== cudax::execution::execution_policy::invalid_execution_policy);
61-
CHECK(env.query(cudax::get_memory_resource) == cudax::device_memory_resource{});
61+
CHECK(env.query(cuda::mr::get_memory_resource) == cudax::device_memory_resource{});
6262
}
6363

6464
C2H_TEST("env_t is constructible from an any_resource", "[execution, env]")
@@ -71,7 +71,7 @@ C2H_TEST("env_t is constructible from an any_resource", "[execution, env]")
7171
CHECK(env.query(cuda::get_stream) == ::cuda::experimental::detail::__invalid_stream);
7272
CHECK(env.query(cudax::execution::get_execution_policy)
7373
== cudax::execution::execution_policy::invalid_execution_policy);
74-
CHECK(env.query(cudax::get_memory_resource) == mr);
74+
CHECK(env.query(cuda::mr::get_memory_resource) == mr);
7575
}
7676

7777
SECTION("Passing an any_resource and a stream")
@@ -81,7 +81,7 @@ C2H_TEST("env_t is constructible from an any_resource", "[execution, env]")
8181
CHECK(env.query(cuda::get_stream) == stream);
8282
CHECK(env.query(cudax::execution::get_execution_policy)
8383
== cudax::execution::execution_policy::invalid_execution_policy);
84-
CHECK(env.query(cudax::get_memory_resource) == mr);
84+
CHECK(env.query(cuda::mr::get_memory_resource) == mr);
8585
}
8686

8787
SECTION("Passing an any_resource, a stream and a policy")
@@ -91,7 +91,7 @@ C2H_TEST("env_t is constructible from an any_resource", "[execution, env]")
9191
CHECK(env.query(cuda::get_stream) == stream);
9292
CHECK(env.query(cudax::execution::get_execution_policy)
9393
== cudax::execution::execution_policy::parallel_unsequenced_device);
94-
CHECK(env.query(cudax::get_memory_resource) == mr);
94+
CHECK(env.query(cuda::mr::get_memory_resource) == mr);
9595
}
9696
}
9797

@@ -103,7 +103,7 @@ C2H_TEST("env_t is constructible from an any_resource passed as an rvalue", "[ex
103103
CHECK(env.query(cuda::get_stream) == ::cuda::experimental::detail::__invalid_stream);
104104
CHECK(env.query(cudax::execution::get_execution_policy)
105105
== cudax::execution::execution_policy::invalid_execution_policy);
106-
CHECK(env.query(cudax::get_memory_resource)
106+
CHECK(env.query(cuda::mr::get_memory_resource)
107107
== cudax::any_async_resource<cuda::mr::device_accessible>{test_resource{}});
108108
}
109109

@@ -114,7 +114,7 @@ C2H_TEST("env_t is constructible from an any_resource passed as an rvalue", "[ex
114114
CHECK(env.query(cuda::get_stream) == stream);
115115
CHECK(env.query(cudax::execution::get_execution_policy)
116116
== cudax::execution::execution_policy::invalid_execution_policy);
117-
CHECK(env.query(cudax::get_memory_resource)
117+
CHECK(env.query(cuda::mr::get_memory_resource)
118118
== cudax::any_async_resource<cuda::mr::device_accessible>{test_resource{}});
119119
}
120120

@@ -127,7 +127,7 @@ C2H_TEST("env_t is constructible from an any_resource passed as an rvalue", "[ex
127127
CHECK(env.query(cuda::get_stream) == stream);
128128
CHECK(env.query(cudax::execution::get_execution_policy)
129129
== cudax::execution::execution_policy::parallel_unsequenced_device);
130-
CHECK(env.query(cudax::get_memory_resource)
130+
CHECK(env.query(cuda::mr::get_memory_resource)
131131
== cudax::any_async_resource<cuda::mr::device_accessible>{test_resource{}});
132132
}
133133
}
@@ -142,7 +142,7 @@ C2H_TEST("env_t is constructible from a resource", "[execution, env]")
142142
CHECK(env.query(cuda::get_stream) == ::cuda::experimental::detail::__invalid_stream);
143143
CHECK(env.query(cudax::execution::get_execution_policy)
144144
== cudax::execution::execution_policy::invalid_execution_policy);
145-
CHECK(env.query(cudax::get_memory_resource) == mr);
145+
CHECK(env.query(cuda::mr::get_memory_resource) == mr);
146146
}
147147

148148
SECTION("Passing an any_resource and a stream")
@@ -152,7 +152,7 @@ C2H_TEST("env_t is constructible from a resource", "[execution, env]")
152152
CHECK(env.query(cuda::get_stream) == stream);
153153
CHECK(env.query(cudax::execution::get_execution_policy)
154154
== cudax::execution::execution_policy::invalid_execution_policy);
155-
CHECK(env.query(cudax::get_memory_resource) == mr);
155+
CHECK(env.query(cuda::mr::get_memory_resource) == mr);
156156
}
157157

158158
SECTION("Passing an any_resource, a stream and a policy")
@@ -162,7 +162,7 @@ C2H_TEST("env_t is constructible from a resource", "[execution, env]")
162162
CHECK(env.query(cuda::get_stream) == stream);
163163
CHECK(env.query(cudax::execution::get_execution_policy)
164164
== cudax::execution::execution_policy::parallel_unsequenced_device);
165-
CHECK(env.query(cudax::get_memory_resource) == mr);
165+
CHECK(env.query(cuda::mr::get_memory_resource) == mr);
166166
}
167167
}
168168

@@ -174,7 +174,7 @@ C2H_TEST("env_t is constructible from a resource passed as an rvalue", "[executi
174174
CHECK(env.query(cuda::get_stream) == ::cuda::experimental::detail::__invalid_stream);
175175
CHECK(env.query(cudax::execution::get_execution_policy)
176176
== cudax::execution::execution_policy::invalid_execution_policy);
177-
CHECK(env.query(cudax::get_memory_resource) == test_resource{});
177+
CHECK(env.query(cuda::mr::get_memory_resource) == test_resource{});
178178
}
179179

180180
SECTION("Passing an any_resource and a stream")
@@ -184,7 +184,7 @@ C2H_TEST("env_t is constructible from a resource passed as an rvalue", "[executi
184184
CHECK(env.query(cuda::get_stream) == stream);
185185
CHECK(env.query(cudax::execution::get_execution_policy)
186186
== cudax::execution::execution_policy::invalid_execution_policy);
187-
CHECK(env.query(cudax::get_memory_resource) == test_resource{});
187+
CHECK(env.query(cuda::mr::get_memory_resource) == test_resource{});
188188
}
189189

190190
SECTION("Passing an any_resource, a stream and a policy")
@@ -194,7 +194,7 @@ C2H_TEST("env_t is constructible from a resource passed as an rvalue", "[executi
194194
CHECK(env.query(cuda::get_stream) == stream);
195195
CHECK(env.query(cudax::execution::get_execution_policy)
196196
== cudax::execution::execution_policy::parallel_unsequenced_device);
197-
CHECK(env.query(cudax::get_memory_resource) == test_resource{});
197+
CHECK(env.query(cuda::mr::get_memory_resource) == test_resource{});
198198
}
199199
}
200200

@@ -204,7 +204,7 @@ struct some_env_t
204204
cudax::stream stream_{};
205205
cudax::execution::execution_policy policy_ = cudax::execution::execution_policy::parallel_unsequenced_device;
206206

207-
const test_resource& query(cudax::get_memory_resource_t) const noexcept
207+
const test_resource& query(cuda::mr::get_memory_resource_t) const noexcept
208208
{
209209
return res_;
210210
}
@@ -225,7 +225,7 @@ C2H_TEST("env_t is constructible from a suitable env", "[execution, env]")
225225
env_t env{other_env};
226226
CHECK(env.query(cuda::get_stream) == other_env.stream_);
227227
CHECK(env.query(cudax::execution::get_execution_policy) == other_env.policy_);
228-
CHECK(env.query(cudax::get_memory_resource) == other_env.res_);
228+
CHECK(env.query(cuda::mr::get_memory_resource) == other_env.res_);
229229
}
230230

231231
template <bool WithResource, bool WithStream, bool WithPolicy>
@@ -236,7 +236,7 @@ struct bad_env_t
236236
cudax::execution::execution_policy policy_ = cudax::execution::execution_policy::parallel_unsequenced_device;
237237

238238
template <bool Enable = WithResource, cuda::std::enable_if_t<Enable, int> = 0>
239-
const test_resource& query(cudax::get_memory_resource_t) const noexcept
239+
const test_resource& query(cuda::mr::get_memory_resource_t) const noexcept
240240
{
241241
return res_;
242242
}
@@ -266,7 +266,7 @@ C2H_TEST("Can use query to construct various objects", "[execution, env]")
266266
SECTION("Can create an any_resource")
267267
{
268268
env_t env{test_resource{}};
269-
cudax::any_resource<cuda::mr::device_accessible> resource = env.query(cudax::get_memory_resource);
269+
cudax::any_resource<cuda::mr::device_accessible> resource = env.query(cuda::mr::get_memory_resource);
270270
CHECK(resource == test_resource{});
271271
}
272272

@@ -275,7 +275,7 @@ C2H_TEST("Can use query to construct various objects", "[execution, env]")
275275
cudax::stream stream_{};
276276
env_t env{test_resource{}, stream_};
277277
cudax::uninitialized_async_buffer<int, cuda::mr::device_accessible> buf{
278-
env.query(cudax::get_memory_resource), env.query(cuda::get_stream), 0ull};
278+
env.query(cuda::mr::get_memory_resource), env.query(cuda::get_stream), 0ull};
279279
CHECK(buf.get_memory_resource() == test_resource{});
280280
CHECK(buf.get_stream() == stream_);
281281
}

0 commit comments

Comments
 (0)