From 3b4138763736d3cf184c6239bd26966e51c8fbbc Mon Sep 17 00:00:00 2001 From: Allison Vacanti Date: Fri, 11 Feb 2022 13:26:10 -0500 Subject: [PATCH] Add `nvbench::make_cuda_stream_view(cudaStream_t)`. --- examples/stream.cu | 4 +--- nvbench/cuda_stream.cuh | 12 ++++++++++++ 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/examples/stream.cu b/examples/stream.cu index d0ca0c8..9507558 100644 --- a/examples/stream.cu +++ b/examples/stream.cu @@ -49,8 +49,7 @@ void stream_bench(nvbench::state &state) // Set CUDA default stream as the target stream. Note the default stream // is non-owning. cudaStream_t default_stream = 0; - state.set_cuda_stream( - nvbench::cuda_stream{default_stream, false /*owning = false*/}); + state.set_cuda_stream(nvbench::make_cuda_stream_view(default_stream)); state.exec([&input, &output, num_values](nvbench::launch &) { copy(thrust::raw_pointer_cast(input.data()), @@ -58,5 +57,4 @@ void stream_bench(nvbench::state &state) num_values); }); } - NVBENCH_BENCH(stream_bench); diff --git a/nvbench/cuda_stream.cuh b/nvbench/cuda_stream.cuh index f8f4a52..6674c27 100644 --- a/nvbench/cuda_stream.cuh +++ b/nvbench/cuda_stream.cuh @@ -33,6 +33,8 @@ namespace nvbench * May be owning or non-owning. If the stream is owned, it will be freed with * `cudaStreamDestroy` when the `cuda_stream`'s lifetime ends. Non-owning * `cuda_stream`s are sometimes referred to as views. + * + * @sa nvbench::make_cuda_stream_view */ struct cuda_stream { @@ -54,6 +56,8 @@ struct cuda_stream * * @param owning If true, `cudaStreamCreate(stream)` will be called from this * `cuda_stream`'s destructor. + * + * @sa nvbench::make_cuda_stream_view */ cuda_stream(cudaStream_t stream, bool owning) : m_stream{stream, stream_deleter{owning}} @@ -94,4 +98,12 @@ private: std::unique_ptr m_stream; }; +/** + * Creates a non-owning view of the specified `stream`. + */ +inline nvbench::cuda_stream make_cuda_stream_view(cudaStream_t stream) +{ + return cuda_stream{stream, false}; +} + } // namespace nvbench