mirror of
https://github.com/NVIDIA/nvbench.git
synced 2026-04-30 03:31:13 +00:00
Add nvbench::make_cuda_stream_view(cudaStream_t).
This commit is contained in:
@@ -49,8 +49,7 @@ void stream_bench(nvbench::state &state)
|
|||||||
// Set CUDA default stream as the target stream. Note the default stream
|
// Set CUDA default stream as the target stream. Note the default stream
|
||||||
// is non-owning.
|
// is non-owning.
|
||||||
cudaStream_t default_stream = 0;
|
cudaStream_t default_stream = 0;
|
||||||
state.set_cuda_stream(
|
state.set_cuda_stream(nvbench::make_cuda_stream_view(default_stream));
|
||||||
nvbench::cuda_stream{default_stream, false /*owning = false*/});
|
|
||||||
|
|
||||||
state.exec([&input, &output, num_values](nvbench::launch &) {
|
state.exec([&input, &output, num_values](nvbench::launch &) {
|
||||||
copy(thrust::raw_pointer_cast(input.data()),
|
copy(thrust::raw_pointer_cast(input.data()),
|
||||||
@@ -58,5 +57,4 @@ void stream_bench(nvbench::state &state)
|
|||||||
num_values);
|
num_values);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
NVBENCH_BENCH(stream_bench);
|
NVBENCH_BENCH(stream_bench);
|
||||||
|
|||||||
@@ -33,6 +33,8 @@ namespace nvbench
|
|||||||
* May be owning or non-owning. If the stream is owned, it will be freed with
|
* 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
|
* `cudaStreamDestroy` when the `cuda_stream`'s lifetime ends. Non-owning
|
||||||
* `cuda_stream`s are sometimes referred to as views.
|
* `cuda_stream`s are sometimes referred to as views.
|
||||||
|
*
|
||||||
|
* @sa nvbench::make_cuda_stream_view
|
||||||
*/
|
*/
|
||||||
struct cuda_stream
|
struct cuda_stream
|
||||||
{
|
{
|
||||||
@@ -54,6 +56,8 @@ struct cuda_stream
|
|||||||
*
|
*
|
||||||
* @param owning If true, `cudaStreamCreate(stream)` will be called from this
|
* @param owning If true, `cudaStreamCreate(stream)` will be called from this
|
||||||
* `cuda_stream`'s destructor.
|
* `cuda_stream`'s destructor.
|
||||||
|
*
|
||||||
|
* @sa nvbench::make_cuda_stream_view
|
||||||
*/
|
*/
|
||||||
cuda_stream(cudaStream_t stream, bool owning)
|
cuda_stream(cudaStream_t stream, bool owning)
|
||||||
: m_stream{stream, stream_deleter{owning}}
|
: m_stream{stream, stream_deleter{owning}}
|
||||||
@@ -94,4 +98,12 @@ private:
|
|||||||
std::unique_ptr<cudaStream_t, stream_deleter> m_stream;
|
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
|
} // namespace nvbench
|
||||||
|
|||||||
Reference in New Issue
Block a user