Add nvbench::make_cuda_stream_view(cudaStream_t).

This commit is contained in:
Allison Vacanti
2022-02-11 13:26:10 -05:00
parent 8ae58981ca
commit 3b41387637
2 changed files with 13 additions and 3 deletions

View File

@@ -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);

View File

@@ -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<cudaStream_t, stream_deleter> 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