File indexing completed on 2025-01-18 09:12:17
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010 #include "Acts/Plugins/Cuda/Utilities/StreamWrapper.hpp"
0011
0012 #include "ErrorCheck.cuh"
0013 #include "StreamHandlers.cuh"
0014
0015
0016 #include <cuda_runtime.h>
0017
0018 namespace Acts {
0019 namespace Cuda {
0020
0021 StreamWrapper::StreamWrapper(void* stream, bool ownsStream)
0022 : m_stream(stream), m_ownsStream(ownsStream) {}
0023
0024 StreamWrapper::StreamWrapper(StreamWrapper&& parent)
0025 : m_stream(parent.m_stream), m_ownsStream(parent.m_ownsStream) {
0026 parent.m_stream = nullptr;
0027 parent.m_ownsStream = false;
0028 }
0029
0030 StreamWrapper::~StreamWrapper() {
0031
0032 if (m_stream && m_ownsStream) {
0033 ACTS_CUDA_ERROR_CHECK(cudaStreamDestroy(getStreamFrom(*this)));
0034 }
0035 }
0036
0037 StreamWrapper& StreamWrapper::operator=(StreamWrapper&& rhs) {
0038
0039 if (this == &rhs) {
0040 return *this;
0041 }
0042
0043
0044 if (m_stream && m_ownsStream) {
0045 ACTS_CUDA_ERROR_CHECK(cudaStreamDestroy(getStreamFrom(*this)));
0046 }
0047
0048
0049 m_stream = rhs.m_stream;
0050 m_ownsStream = rhs.m_ownsStream;
0051 rhs.m_stream = nullptr;
0052 rhs.m_ownsStream = false;
0053
0054
0055 return *this;
0056 }
0057
0058 void StreamWrapper::synchronize() const {
0059
0060 ACTS_CUDA_ERROR_CHECK(cudaStreamSynchronize(getStreamFrom(*this)));
0061 return;
0062 }
0063
0064 StreamWrapper createStreamFor(const Acts::Cuda::Info::Device& device) {
0065
0066 ACTS_CUDA_ERROR_CHECK(cudaSetDevice(device.id));
0067 cudaStream_t stream = nullptr;
0068 ACTS_CUDA_ERROR_CHECK(
0069 cudaStreamCreateWithFlags(&stream, cudaStreamNonBlocking));
0070
0071
0072 return StreamWrapper(stream);
0073 }
0074
0075 }
0076 }