|
22 | 22 |
|
23 | 23 | #if _CCCL_HAS_BACKEND_CUDA() |
24 | 24 |
|
25 | | -# include <cuda/__functional/call_or.h> |
26 | | -# include <cuda/__fwd/execution_policy.h> |
27 | | -# include <cuda/__memory_resource/any_resource.h> |
28 | | -# include <cuda/__memory_resource/get_memory_resource.h> |
29 | | -# include <cuda/__memory_resource/resource.h> |
30 | | -# include <cuda/__stream/get_stream.h> |
31 | | -# include <cuda/__stream/stream_ref.h> |
32 | 25 | # include <cuda/std/__execution/policy.h> |
33 | | -# include <cuda/std/__type_traits/is_execution_policy.h> |
34 | | -# include <cuda/std/__utility/forward.h> |
35 | | -# include <cuda/std/__utility/move.h> |
36 | 26 |
|
37 | 27 | # include <cuda/std/__cccl/prologue.h> |
38 | 28 |
|
39 | | -_CCCL_BEGIN_NAMESPACE_CUDA_STD_EXECUTION |
40 | | - |
41 | | -template <bool _HasStream> |
42 | | -struct __policy_stream_holder |
43 | | -{ |
44 | | - ::cuda::stream_ref __stream_; |
45 | | - |
46 | | - _CCCL_HOST_API constexpr __policy_stream_holder(::cuda::stream_ref __stream) noexcept |
47 | | - : __stream_(__stream) |
48 | | - {} |
49 | | -}; |
50 | | - |
51 | | -template <> |
52 | | -struct __policy_stream_holder<false> |
53 | | -{ |
54 | | - _CCCL_HIDE_FROM_ABI __policy_stream_holder() = default; |
55 | | - |
56 | | - //! @brief Dummy constructor to simplify implementation of the cuda policy |
57 | | - _CCCL_HOST_API constexpr __policy_stream_holder(::cuda::stream_ref) noexcept {} |
58 | | -}; |
59 | | - |
60 | | -template <bool _HasResource> |
61 | | -struct __policy_memory_resource_holder |
62 | | -{ |
63 | | - ::cuda::mr::resource_ref<::cuda::mr::device_accessible> __resource_; |
64 | | - |
65 | | - _CCCL_HIDE_FROM_ABI __policy_memory_resource_holder() = default; |
66 | | - |
67 | | - _CCCL_HOST_API constexpr __policy_memory_resource_holder( |
68 | | - ::cuda::mr::resource_ref<::cuda::mr::device_accessible> __resource) noexcept |
69 | | - : __resource_(__resource) |
70 | | - {} |
71 | | -}; |
72 | | - |
73 | | -template <> |
74 | | -struct __policy_memory_resource_holder<false> |
75 | | -{ |
76 | | - _CCCL_HIDE_FROM_ABI __policy_memory_resource_holder() = default; |
77 | | - |
78 | | - //! @brief Dummy constructor to simplify implementation of the cuda policy |
79 | | - _CCCL_HOST_API constexpr __policy_memory_resource_holder( |
80 | | - ::cuda::mr::resource_ref<::cuda::mr::device_accessible>) noexcept |
81 | | - {} |
82 | | -}; |
83 | | - |
84 | | -template <uint32_t _Policy> |
85 | | -struct _CCCL_DECLSPEC_EMPTY_BASES __execution_policy_base<_Policy, __execution_backend::__cuda> |
86 | | - : __execution_policy_base<_Policy, __execution_backend::__none> |
87 | | - , protected __policy_stream_holder<__cuda_policy_with_stream<_Policy>> |
88 | | - , protected __policy_memory_resource_holder<__cuda_policy_with_memory_resource<_Policy>> |
89 | | -{ |
90 | | -private: |
91 | | - template <uint32_t, __execution_backend> |
92 | | - friend struct __execution_policy_base; |
93 | | - |
94 | | - using __stream_holder = __policy_stream_holder<__cuda_policy_with_stream<_Policy>>; |
95 | | - using __resource_holder = __policy_memory_resource_holder<__cuda_policy_with_memory_resource<_Policy>>; |
96 | | - |
97 | | - _CCCL_TEMPLATE(bool _WithStream = __cuda_policy_with_stream<_Policy>, |
98 | | - bool _WithResource = __cuda_policy_with_memory_resource<_Policy>) |
99 | | - _CCCL_REQUIRES((_WithStream) _CCCL_AND(!_WithResource)) |
100 | | - _CCCL_HOST_API constexpr __execution_policy_base(::cuda::stream_ref __stream) noexcept |
101 | | - : __stream_holder(__stream) |
102 | | - , __resource_holder() |
103 | | - {} |
104 | | - |
105 | | - _CCCL_TEMPLATE(bool _WithStream = __cuda_policy_with_stream<_Policy>, |
106 | | - bool _WithResource = __cuda_policy_with_memory_resource<_Policy>) |
107 | | - _CCCL_REQUIRES((!_WithStream) _CCCL_AND _WithResource) |
108 | | - _CCCL_HOST_API constexpr __execution_policy_base( |
109 | | - ::cuda::mr::resource_ref<::cuda::mr::device_accessible> __resource) noexcept |
110 | | - : __stream_holder() |
111 | | - , __resource_holder(::cuda::std::move(__resource)) // NVCC 12.0 needs the move |
112 | | - {} |
113 | | - |
114 | | - _CCCL_TEMPLATE(bool _WithStream = __cuda_policy_with_stream<_Policy>, |
115 | | - bool _WithResource = __cuda_policy_with_memory_resource<_Policy>) |
116 | | - _CCCL_REQUIRES(_WithStream _CCCL_AND _WithResource) |
117 | | - _CCCL_HOST_API constexpr __execution_policy_base( |
118 | | - ::cuda::stream_ref __stream, ::cuda::mr::resource_ref<::cuda::mr::device_accessible> __resource) noexcept |
119 | | - : __stream_holder(__stream) |
120 | | - , __resource_holder(::cuda::std::move(__resource)) |
121 | | - {} |
122 | | - |
123 | | -public: |
124 | | - _CCCL_HIDE_FROM_ABI constexpr __execution_policy_base() noexcept = default; |
125 | | - |
126 | | - //! @brief Convert to a policy that holds a stream |
127 | | - //! @note This cannot be merged with the other case where we already have a stream as this needs to be const qualified |
128 | | - //! This is because we start with a constexpr global and modify that through with |
129 | | - [[nodiscard]] _CCCL_HOST_API auto with(const ::cuda::get_stream_t&, ::cuda::stream_ref __stream) const noexcept |
130 | | - { |
131 | | - constexpr uint32_t __new_policy = __set_cuda_backend_option<_Policy, __cuda_backend_options::__with_stream>; |
132 | | - if constexpr (__cuda_policy_with_memory_resource<_Policy>) |
133 | | - { |
134 | | - return __execution_policy_base<__new_policy>{__stream, this->__resource_}; |
135 | | - } |
136 | | - else |
137 | | - { |
138 | | - return __execution_policy_base<__new_policy>{__stream}; |
139 | | - } |
140 | | - } |
141 | | - |
142 | | - //! @brief Return the stream stored in the holder or a default stream |
143 | | - _CCCL_TEMPLATE(bool _WithStream = __cuda_policy_with_stream<_Policy>) |
144 | | - _CCCL_REQUIRES(_WithStream) |
145 | | - [[nodiscard]] _CCCL_API ::cuda::stream_ref query(const ::cuda::get_stream_t&) const noexcept |
146 | | - { |
147 | | - return this->__stream_; |
148 | | - } |
149 | | - |
150 | | - //! @brief Convert to a policy that holds a memory resource |
151 | | - //! @warning We hold the memory resource by reference, so passing rvalue is a bug |
152 | | - template <class _Resource> |
153 | | - [[nodiscard]] _CCCL_HOST_API auto with(const cuda::mr::get_memory_resource_t&, _Resource&&) const = delete; |
154 | | - |
155 | | - //! @brief Convert to a policy that holds a memory resource |
156 | | - //! @note This cannot be merged with the other case as this needs to be const qualified |
157 | | - //! This is because we start with a constexpr global and modify that through with |
158 | | - template <class _Resource> |
159 | | - [[nodiscard]] _CCCL_HOST_API auto with(const cuda::mr::get_memory_resource_t&, _Resource& __resource) const noexcept |
160 | | - { |
161 | | - constexpr uint32_t __new_policy = |
162 | | - __set_cuda_backend_option<_Policy, __cuda_backend_options::__with_memory_resource>; |
163 | | - if constexpr (__cuda_policy_with_stream<_Policy>) |
164 | | - { |
165 | | - return __execution_policy_base<__new_policy>{this->__stream_, __resource}; |
166 | | - } |
167 | | - else |
168 | | - { |
169 | | - return __execution_policy_base<__new_policy>{__resource}; |
170 | | - } |
171 | | - } |
172 | | - |
173 | | - //! @brief Return either a stored or a default memory resource |
174 | | - _CCCL_TEMPLATE(bool _WithResource = __cuda_policy_with_memory_resource<_Policy>) |
175 | | - _CCCL_REQUIRES(_WithResource) |
176 | | - [[nodiscard]] _CCCL_API auto query(const ::cuda::mr::get_memory_resource_t&) const noexcept |
177 | | - { |
178 | | - return this->__resource_; |
179 | | - } |
180 | | - |
181 | | - template <uint32_t _OtherPolicy, __execution_backend _OtherBackend> |
182 | | - [[nodiscard]] _CCCL_API friend constexpr bool operator==( |
183 | | - const __execution_policy_base& __lhs, const __execution_policy_base<_OtherPolicy, _OtherBackend>& __rhs) noexcept |
184 | | - { |
185 | | - if constexpr (_Policy != _OtherPolicy) |
186 | | - { |
187 | | - return false; |
188 | | - } |
189 | | - |
190 | | - if constexpr (__cuda_policy_with_stream<_Policy>) |
191 | | - { |
192 | | - if (__lhs.query(::cuda::get_stream) != __rhs.query(::cuda::get_stream)) |
193 | | - { |
194 | | - return false; |
195 | | - } |
196 | | - } |
197 | | - |
198 | | - if constexpr (__cuda_policy_with_memory_resource<_Policy>) |
199 | | - { |
200 | | - if (__lhs.query(::cuda::mr::get_memory_resource) != __rhs.query(::cuda::mr::get_memory_resource)) |
201 | | - { |
202 | | - return false; |
203 | | - } |
204 | | - } |
205 | | - |
206 | | - return true; |
207 | | - } |
208 | | - |
209 | | -# if _CCCL_STD_VER <= 2017 |
210 | | - template <uint32_t _OtherPolicy, __execution_backend _OtherBackend> |
211 | | - [[nodiscard]] _CCCL_API friend constexpr bool operator!=( |
212 | | - const __execution_policy_base& __lhs, const __execution_policy_base<_OtherPolicy, _OtherBackend>& __rhs) noexcept |
213 | | - { |
214 | | - return !(__lhs == __rhs); |
215 | | - } |
216 | | -# endif // _CCCL_STD_VER <= 2017 |
217 | | -}; |
218 | | - |
219 | | -_CCCL_END_NAMESPACE_CUDA_STD_EXECUTION |
220 | | - |
221 | 29 | _CCCL_BEGIN_NAMESPACE_CUDA_EXECUTION |
222 | 30 |
|
223 | 31 | using __cub_parallel_unsequenced_policy = |
224 | | - ::cuda::std::execution::__execution_policy_base<::cuda::std::execution::__with_cuda_backend<static_cast<uint32_t>( |
225 | | - ::cuda::std::execution::__execution_policy::__parallel_unsequenced)>()>; |
| 32 | + ::cuda::std::execution::__execution_policy_base<::cuda::std::execution::__with_backend< |
| 33 | + static_cast<uint32_t>(::cuda::std::execution::__execution_policy::__parallel_unsequenced), |
| 34 | + ::cuda::std::execution::__execution_backend::__cuda>()>; |
226 | 35 | _CCCL_GLOBAL_CONSTANT __cub_parallel_unsequenced_policy __cub_par_unseq{}; |
227 | 36 |
|
228 | 37 | _CCCL_END_NAMESPACE_CUDA_EXECUTION |
|
0 commit comments