Skip to content

Commit 7e31a45

Browse files
committed
Merge branch 'add-async-fill' into 'develop'
remove-rank-typedef See merge request correaa/boost-multi!1881
2 parents b3a27fb + 69e57a4 commit 7e31a45

2 files changed

Lines changed: 42 additions & 0 deletions

File tree

include/boost/multi/adaptors/thrust/test/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ set(TEST_SRCS
4040
by_key.cu
4141
device_function.cu
4242
diffusion3d_kernel.cu
43+
fill_async.cu
4344
for_each.cu
4445
memory_resource.cu
4546
neighbor_list.cu
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
// Copyright 2024 Alfredo A. Correa
2+
// Distributed under the Boost Software License, Version 1.0.
3+
// https://www.boost.org/LICENSE_1_0.txt
4+
5+
#define BOOST_TEST_MODULE "C++ Unit Tests for Multi thrust::fill with async (stream) execution policy"
6+
7+
#include <boost/multi/array.hpp>
8+
#include <boost/multi/adaptors/thrust.hpp>
9+
10+
#include <thrust/fill.h>
11+
#include <thrust/system/cuda/execution_policy.h> // for thrust::cuda::par_nosync
12+
13+
#include <boost/core/lightweight_test.hpp>
14+
15+
namespace multi = boost::multi;
16+
17+
auto main() -> int { // NOLINT(bugprone-exception-escape)
18+
cudaStream_t stream; // NOLINT(cppcoreguidelines-init-variables)
19+
BOOST_TEST( cudaStreamCreate(&stream) == cudaSuccess );
20+
21+
multi::thrust::cuda::array<double, 2> darr({1024, 1024});
22+
23+
// `par_nosync` is the asynchronous execution policy: the algorithm is
24+
// enqueued on `stream` and the call returns without synchronizing.
25+
thrust::fill(
26+
thrust::cuda::par_nosync.on(stream),
27+
darr.elements().begin(), darr.elements().end(),
28+
42.0
29+
);
30+
31+
// nothing is guaranteed complete until the stream is drained
32+
BOOST_TEST( cudaStreamSynchronize(stream) == cudaSuccess );
33+
34+
multi::array<double, 2> host = darr; // copy back to verify
35+
BOOST_TEST( host[0][0] == 42.0 );
36+
BOOST_TEST( host[1023][1023] == 42.0 );
37+
38+
BOOST_TEST( cudaStreamDestroy(stream) == cudaSuccess );
39+
40+
return boost::report_errors();
41+
}

0 commit comments

Comments
 (0)