@@ -11,6 +11,9 @@ struct stream_registry_factory_t;
1111
1212#include < thrust/device_vector.h>
1313
14+ #include < cuda/devices>
15+ #include < cuda/stream>
16+
1417#include " catch2_test_env_launch_helper.h"
1518
1619DECLARE_LAUNCH_WRAPPER (cub::DeviceSegmentedSort::StableSortPairs, stable_sort_pairs);
@@ -204,8 +207,7 @@ TEST_CASE("DeviceSegmentedSort::SortPairs nonstable uses custom stream", "[segme
204207 auto values_out = c2h::device_vector<int >(7 );
205208 auto offsets = c2h::device_vector<int >{0 , 3 , 7 };
206209
207- cudaStream_t custom_stream;
208- REQUIRE (cudaSuccess == cudaStreamCreate (&custom_stream));
210+ cuda::stream stream{cuda::devices[0 ]};
209211
210212 size_t expected_bytes_allocated{};
211213 REQUIRE (
@@ -222,7 +224,7 @@ TEST_CASE("DeviceSegmentedSort::SortPairs nonstable uses custom stream", "[segme
222224 thrust::raw_pointer_cast (offsets.data ()),
223225 thrust::raw_pointer_cast (offsets.data ()) + 1 ));
224226
225- auto stream_prop = stdexec::prop{cuda::get_stream_t {}, cuda::stream_ref{custom_stream }};
227+ auto stream_prop = stdexec::prop{cuda::get_stream_t {}, cuda::stream_ref{stream }};
226228 auto env = stdexec::env{stream_prop, expected_allocation_size (expected_bytes_allocated)};
227229
228230 sort_pairs (
@@ -236,13 +238,12 @@ TEST_CASE("DeviceSegmentedSort::SortPairs nonstable uses custom stream", "[segme
236238 thrust::raw_pointer_cast (offsets.data ()) + 1 ,
237239 env);
238240
239- REQUIRE (cudaSuccess == cudaStreamSynchronize (custom_stream) );
241+ stream. sync ( );
240242
241243 c2h::device_vector<int > expected_keys{6 , 7 , 8 , 0 , 3 , 5 , 9 };
242244 c2h::device_vector<int > expected_values{1 , 2 , 0 , 5 , 4 , 3 , 6 };
243245 REQUIRE (keys_out == expected_keys);
244246 REQUIRE (values_out == expected_values);
245- REQUIRE (cudaSuccess == cudaStreamDestroy (custom_stream));
246247}
247248
248249TEST_CASE (" DeviceSegmentedSort::SortPairsDescending nonstable uses custom stream" , " [segmented_sort][pairs][device]" )
@@ -253,8 +254,7 @@ TEST_CASE("DeviceSegmentedSort::SortPairsDescending nonstable uses custom stream
253254 auto values_out = c2h::device_vector<int >(7 );
254255 auto offsets = c2h::device_vector<int >{0 , 3 , 7 };
255256
256- cudaStream_t custom_stream;
257- REQUIRE (cudaSuccess == cudaStreamCreate (&custom_stream));
257+ cuda::stream stream{cuda::devices[0 ]};
258258
259259 size_t expected_bytes_allocated{};
260260 REQUIRE (
@@ -271,7 +271,7 @@ TEST_CASE("DeviceSegmentedSort::SortPairsDescending nonstable uses custom stream
271271 thrust::raw_pointer_cast (offsets.data ()),
272272 thrust::raw_pointer_cast (offsets.data ()) + 1 ));
273273
274- auto stream_prop = stdexec::prop{cuda::get_stream_t {}, cuda::stream_ref{custom_stream }};
274+ auto stream_prop = stdexec::prop{cuda::get_stream_t {}, cuda::stream_ref{stream }};
275275 auto env = stdexec::env{stream_prop, expected_allocation_size (expected_bytes_allocated)};
276276
277277 sort_pairs_descending (
@@ -285,13 +285,12 @@ TEST_CASE("DeviceSegmentedSort::SortPairsDescending nonstable uses custom stream
285285 thrust::raw_pointer_cast (offsets.data ()) + 1 ,
286286 env);
287287
288- REQUIRE (cudaSuccess == cudaStreamSynchronize (custom_stream) );
288+ stream. sync ( );
289289
290290 c2h::device_vector<int > expected_keys{8 , 7 , 6 , 9 , 5 , 3 , 0 };
291291 c2h::device_vector<int > expected_values{0 , 2 , 1 , 6 , 3 , 4 , 5 };
292292 REQUIRE (keys_out == expected_keys);
293293 REQUIRE (values_out == expected_values);
294- REQUIRE (cudaSuccess == cudaStreamDestroy (custom_stream));
295294}
296295
297296TEST_CASE (" DeviceSegmentedSort::SortPairs nonstable DoubleBuffer uses custom stream" , " [segmented_sort][pairs][device]" )
@@ -306,8 +305,7 @@ TEST_CASE("DeviceSegmentedSort::SortPairs nonstable DoubleBuffer uses custom str
306305 cub::DoubleBuffer<int > d_values (
307306 thrust::raw_pointer_cast (values_buf0.data ()), thrust::raw_pointer_cast (values_buf1.data ()));
308307
309- cudaStream_t custom_stream;
310- REQUIRE (cudaSuccess == cudaStreamCreate (&custom_stream));
308+ cuda::stream stream{cuda::devices[0 ]};
311309
312310 size_t expected_bytes_allocated{};
313311 REQUIRE (
@@ -322,7 +320,7 @@ TEST_CASE("DeviceSegmentedSort::SortPairs nonstable DoubleBuffer uses custom str
322320 thrust::raw_pointer_cast (offsets.data ()),
323321 thrust::raw_pointer_cast (offsets.data ()) + 1 ));
324322
325- auto stream_prop = stdexec::prop{cuda::get_stream_t {}, cuda::stream_ref{custom_stream }};
323+ auto stream_prop = stdexec::prop{cuda::get_stream_t {}, cuda::stream_ref{stream }};
326324 auto env = stdexec::env{stream_prop, expected_allocation_size (expected_bytes_allocated)};
327325
328326 sort_pairs (d_keys,
@@ -333,15 +331,14 @@ TEST_CASE("DeviceSegmentedSort::SortPairs nonstable DoubleBuffer uses custom str
333331 thrust::raw_pointer_cast (offsets.data ()) + 1 ,
334332 env);
335333
336- REQUIRE (cudaSuccess == cudaStreamSynchronize (custom_stream) );
334+ stream. sync ( );
337335
338336 c2h::device_vector<int > expected_keys{6 , 7 , 8 , 0 , 3 , 5 , 9 };
339337 c2h::device_vector<int > expected_values{1 , 2 , 0 , 5 , 4 , 3 , 6 };
340338 c2h::device_vector<int > result_keys (d_keys.Current (), d_keys.Current () + 7 );
341339 c2h::device_vector<int > result_values (d_values.Current (), d_values.Current () + 7 );
342340 REQUIRE (result_keys == expected_keys);
343341 REQUIRE (result_values == expected_values);
344- REQUIRE (cudaSuccess == cudaStreamDestroy (custom_stream));
345342}
346343
347344TEST_CASE (" DeviceSegmentedSort::SortPairsDescending nonstable DoubleBuffer uses custom stream" ,
@@ -357,8 +354,7 @@ TEST_CASE("DeviceSegmentedSort::SortPairsDescending nonstable DoubleBuffer uses
357354 cub::DoubleBuffer<int > d_values (
358355 thrust::raw_pointer_cast (values_buf0.data ()), thrust::raw_pointer_cast (values_buf1.data ()));
359356
360- cudaStream_t custom_stream;
361- REQUIRE (cudaSuccess == cudaStreamCreate (&custom_stream));
357+ cuda::stream stream{cuda::devices[0 ]};
362358
363359 size_t expected_bytes_allocated{};
364360 REQUIRE (
@@ -373,7 +369,7 @@ TEST_CASE("DeviceSegmentedSort::SortPairsDescending nonstable DoubleBuffer uses
373369 thrust::raw_pointer_cast (offsets.data ()),
374370 thrust::raw_pointer_cast (offsets.data ()) + 1 ));
375371
376- auto stream_prop = stdexec::prop{cuda::get_stream_t {}, cuda::stream_ref{custom_stream }};
372+ auto stream_prop = stdexec::prop{cuda::get_stream_t {}, cuda::stream_ref{stream }};
377373 auto env = stdexec::env{stream_prop, expected_allocation_size (expected_bytes_allocated)};
378374
379375 sort_pairs_descending (
@@ -385,15 +381,14 @@ TEST_CASE("DeviceSegmentedSort::SortPairsDescending nonstable DoubleBuffer uses
385381 thrust::raw_pointer_cast (offsets.data ()) + 1 ,
386382 env);
387383
388- REQUIRE (cudaSuccess == cudaStreamSynchronize (custom_stream) );
384+ stream. sync ( );
389385
390386 c2h::device_vector<int > expected_keys{8 , 7 , 6 , 9 , 5 , 3 , 0 };
391387 c2h::device_vector<int > expected_values{0 , 2 , 1 , 6 , 3 , 4 , 5 };
392388 c2h::device_vector<int > result_keys (d_keys.Current (), d_keys.Current () + 7 );
393389 c2h::device_vector<int > result_values (d_values.Current (), d_values.Current () + 7 );
394390 REQUIRE (result_keys == expected_keys);
395391 REQUIRE (result_values == expected_values);
396- REQUIRE (cudaSuccess == cudaStreamDestroy (custom_stream));
397392}
398393
399394C2H_TEST (" DeviceSegmentedSort::StableSortPairs uses environment" , " [segmented_sort][pairs][device]" )
0 commit comments