77#include < rmm/cuda_stream_view.hpp>
88#include < rmm/detail/cuda_memory_resource.hpp>
99#include < rmm/detail/export.hpp>
10- #include < rmm/mr/detail/device_memory_resource_view.hpp>
11- #include < rmm/mr/device_memory_resource.hpp>
12-
13- #include < cstddef>
14- #include < optional>
15- #include < type_traits>
16- #include < utility>
1710
1811namespace RMM_NAMESPACE {
1912
2013namespace detail {
2114
22- // Helper base class to hold the view (Base from Member idiom)
23- // This is initialized before the main base class, allowing us to pass it to the base constructor
24- struct view_holder {
25- view_holder () = default ;
26- view_holder (rmm::mr::device_memory_resource* ptr) : view_{ptr} {}
27- std::optional<rmm::mr::detail::device_memory_resource_view> view_;
28- };
29-
3015template <typename ResourceType>
31- class cccl_resource_ref : private view_holder , public ResourceType {
16+ class cccl_resource_ref : public ResourceType {
3217 public:
3318 using base = ResourceType;
3419
35- /* *
36- * @brief Constructs a resource reference from a raw `device_memory_resource` pointer.
37- *
38- * This constructor enables compatibility with CCCL 3.2 by wrapping the pointer in a
39- * `device_memory_resource_view`, which is copyable unlike the virtual base class.
40- *
41- * @param ptr Non-null pointer to a `device_memory_resource`
42- */
43- cccl_resource_ref (rmm::mr::device_memory_resource* ptr)
44- : view_holder{ptr}, base{*view_holder::view_}
45- {
46- }
47-
48- /* *
49- * @brief Constructs a resource reference from a `device_memory_resource` reference.
50- *
51- * This constructor enables compatibility with CCCL 3.2 by wrapping the address in a
52- * `device_memory_resource_view`, which is copyable unlike the virtual base class.
53- *
54- * @param res Reference to a `device_memory_resource`
55- */
56- cccl_resource_ref (rmm::mr::device_memory_resource& res)
57- : view_holder{&res}, base{*view_holder::view_}
58- {
59- }
60-
61- /* *
62- * @brief Constructs a resource reference from a CCCL resource_ref directly.
63- *
64- * This constructor enables interoperability with CCCL 3.2 resource_ref types,
65- * allowing RMM resource_ref types to be constructed from CCCL resource_ref types.
66- *
67- * @param ref A CCCL resource_ref of the appropriate type
68- */
69- cccl_resource_ref (ResourceType const & ref) : view_holder{}, base{ref} {}
70-
71- /* *
72- * @brief Constructs a resource reference from a CCCL resource_ref directly (move).
73- *
74- * This constructor enables interoperability with CCCL 3.2 resource_ref types,
75- * allowing RMM resource_ref types to be constructed from CCCL resource_ref types
76- * using move semantics.
77- *
78- * @param ref A CCCL resource_ref of the appropriate type
79- */
80- cccl_resource_ref (ResourceType&& ref) : view_holder{}, base{std::move (ref)} {}
81-
82- /* *
83- * @brief Copy constructor that properly reconstructs the base to point to the new view.
84- *
85- * If the view is present (e.g., when constructed from device_memory_resource*), we reconstruct
86- * the base from our local view. Otherwise, we copy the base directly.
87- */
88- cccl_resource_ref (cccl_resource_ref const & other)
89- : view_holder{static_cast <view_holder const &>(other)},
90- base{view_holder::view_.has_value () ? base{*view_holder::view_}
91- : static_cast <base const &>(other)}
92- {
93- }
20+ using base::base;
9421
95- /* *
96- * @brief Move constructor that properly reconstructs the base to point to the new view.
97- *
98- * If the view is present (e.g., when constructed from device_memory_resource*), we reconstruct
99- * the base from our local view. Otherwise, we move the base directly.
100- */
101- cccl_resource_ref (cccl_resource_ref&& other) noexcept
102- : view_holder{static_cast <view_holder&&>(other)},
103- base{view_holder::view_.has_value () ? base{*view_holder::view_} : static_cast <base&&>(other)}
104- {
105- }
22+ cccl_resource_ref (base const & other) : base(other) {}
10623
107- /* *
108- * @brief Conversion constructor from a cccl_resource_ref with a convertible ResourceType.
109- *
110- * This enables conversions like host_device_resource_ref -> device_resource_ref,
111- * where the source type has a superset of properties compared to the target type.
112- * The underlying CCCL resource_ref types handle the actual property compatibility check.
113- *
114- * @tparam OtherResourceType A CCCL resource_ref type that is convertible to ResourceType
115- * @param other The source resource_ref to convert from
116- */
117- template <typename OtherResourceType,
118- typename = std::enable_if_t <std::is_constructible_v<ResourceType, OtherResourceType>>>
119- cccl_resource_ref (cccl_resource_ref<OtherResourceType> const & other)
120- : view_holder{}, base{static_cast <OtherResourceType const &>(other)}
121- {
122- }
123-
124- /* *
125- * @brief Copy assignment operator.
126- *
127- * If the view is present, we reconstruct the base from our local view.
128- * Otherwise, we copy the base directly.
129- */
130- cccl_resource_ref& operator =(cccl_resource_ref const & other)
131- {
132- if (this != &other) {
133- view_holder::view_ = other.view_ ;
134- base::operator =(view_holder::view_.has_value () ? base (*view_holder::view_)
135- : static_cast <base const &>(other));
136- }
137- return *this ;
138- }
139-
140- /* *
141- * @brief Move assignment operator.
142- *
143- * If the view is present, we reconstruct the base from our local view.
144- * Otherwise, we move the base directly.
145- */
146- cccl_resource_ref& operator =(cccl_resource_ref&& other) noexcept
147- {
148- if (this != &other) {
149- view_holder::view_ = std::move (other.view_ );
150- base::operator =(view_holder::view_.has_value () ? base (*view_holder::view_)
151- : static_cast <base&&>(other));
152- }
153- return *this ;
154- }
24+ cccl_resource_ref (base&& other) : base(std::move(other)) {}
15525
15626 void * allocate_sync (std::size_t bytes) { return base::allocate_sync (bytes); }
15727
@@ -172,134 +42,14 @@ class cccl_resource_ref : private view_holder, public ResourceType {
17242};
17343
17444template <typename ResourceType>
175- class cccl_async_resource_ref : private view_holder , public ResourceType {
45+ class cccl_async_resource_ref : public ResourceType {
17646 public:
17747 using base = ResourceType;
17848
179- /* *
180- * @brief Constructs an async resource reference from a raw `device_memory_resource` pointer.
181- *
182- * This constructor enables compatibility with CCCL 3.2 by wrapping the pointer in a
183- * `device_memory_resource_view`, which is copyable unlike the virtual base class.
184- *
185- * @param ptr Non-null pointer to a `device_memory_resource`
186- */
187- cccl_async_resource_ref (rmm::mr::device_memory_resource* ptr)
188- : view_holder{ptr}, base{*view_holder::view_}
189- {
190- }
191-
192- /* *
193- * @brief Constructs an async resource reference from a `device_memory_resource` reference.
194- *
195- * This constructor enables compatibility with CCCL 3.2 by wrapping the address in a
196- * `device_memory_resource_view`, which is copyable unlike the virtual base class.
197- *
198- * @param res Reference to a `device_memory_resource`
199- */
200- cccl_async_resource_ref (rmm::mr::device_memory_resource& res)
201- : view_holder{&res}, base{*view_holder::view_}
202- {
203- }
204-
205- /* *
206- * @brief Constructs an async resource reference from a CCCL resource_ref directly.
207- *
208- * This constructor enables interoperability with CCCL 3.2 resource_ref types,
209- * allowing RMM async resource_ref types to be constructed from CCCL resource_ref types.
210- *
211- * @param ref A CCCL async resource_ref of the appropriate type
212- */
213- cccl_async_resource_ref (ResourceType const & ref) : view_holder{}, base{ref} {}
214-
215- /* *
216- * @brief Constructs an async resource reference from a CCCL resource_ref directly (move).
217- *
218- * This constructor enables interoperability with CCCL 3.2 resource_ref types,
219- * allowing RMM async resource_ref types to be constructed from CCCL resource_ref types
220- * using move semantics.
221- *
222- * @param ref A CCCL async resource_ref of the appropriate type
223- */
224- cccl_async_resource_ref (ResourceType&& ref) : view_holder{}, base{std::move (ref)} {}
225-
226- /* *
227- * @brief Copy constructor that properly reconstructs the base to point to the new view.
228- *
229- * The implicit copy constructor would copy the view_holder correctly, but the base
230- * would still point to the original object's view. We need to reconstruct the base
231- * to point to our own view.
232- *
233- * If the view is present (e.g., when constructed from device_memory_resource*), we reconstruct
234- * the base from our local view. Otherwise, we copy the base directly.
235- */
236- cccl_async_resource_ref (cccl_async_resource_ref const & other)
237- : view_holder{static_cast <view_holder const &>(other)},
238- base{view_holder::view_.has_value () ? base{*view_holder::view_}
239- : static_cast <base const &>(other)}
240- {
241- }
242-
243- /* *
244- * @brief Move constructor that properly reconstructs the base to point to the new view.
245- *
246- * If the view is present (e.g., when constructed from device_memory_resource*), we reconstruct
247- * the base from our local view. Otherwise, we move the base directly.
248- */
249- cccl_async_resource_ref (cccl_async_resource_ref&& other) noexcept
250- : view_holder{static_cast <view_holder&&>(other)},
251- base{view_holder::view_.has_value () ? base{*view_holder::view_} : static_cast <base&&>(other)}
252- {
253- }
254-
255- /* *
256- * @brief Conversion constructor from a cccl_async_resource_ref with a convertible ResourceType.
257- *
258- * This enables conversions like host_device_async_resource_ref -> device_async_resource_ref,
259- * where the source type has a superset of properties compared to the target type.
260- * The underlying CCCL resource_ref types handle the actual property compatibility check.
261- *
262- * @tparam OtherResourceType A CCCL async resource_ref type that is convertible to ResourceType
263- * @param other The source async resource_ref to convert from
264- */
265- template <typename OtherResourceType,
266- typename = std::enable_if_t <std::is_constructible_v<ResourceType, OtherResourceType>>>
267- cccl_async_resource_ref (cccl_async_resource_ref<OtherResourceType> const & other)
268- : view_holder{}, base{static_cast <OtherResourceType const &>(other)}
269- {
270- }
49+ using base::base;
27150
272- /* *
273- * @brief Copy assignment operator.
274- *
275- * If the view is present, we reconstruct the base from our local view.
276- * Otherwise, we copy the base directly.
277- */
278- cccl_async_resource_ref& operator =(cccl_async_resource_ref const & other)
279- {
280- if (this != &other) {
281- view_holder::view_ = other.view_ ;
282- base::operator =(view_holder::view_.has_value () ? base (*view_holder::view_)
283- : static_cast <base const &>(other));
284- }
285- return *this ;
286- }
287-
288- /* *
289- * @brief Move assignment operator.
290- *
291- * If the view is present, we reconstruct the base from our local view.
292- * Otherwise, we move the base directly.
293- */
294- cccl_async_resource_ref& operator =(cccl_async_resource_ref&& other) noexcept
295- {
296- if (this != &other) {
297- view_holder::view_ = std::move (other.view_ );
298- base::operator =(view_holder::view_.has_value () ? base (*view_holder::view_)
299- : static_cast <base&&>(other));
300- }
301- return *this ;
302- }
51+ cccl_async_resource_ref (base const & other) : base(other) {}
52+ cccl_async_resource_ref (base&& other) : base(std::move(other)) {}
30353
30454 void * allocate_sync (std::size_t bytes) { return base::allocate_sync (bytes); }
30555
0 commit comments