getOrDie(Device->allocateDeviceMemory<float>(ArraySize));
// Run operations on a stream.
- std::unique_ptr<se::Stream> Stream = getOrDie(Device->createStream());
- Stream->thenCopyH2D<float>(HostX, X)
+ se::Stream Stream = getOrDie(Device->createStream());
+ Stream.thenCopyH2D<float>(HostX, X)
.thenCopyH2D<float>(HostY, Y)
.thenLaunch(ArraySize, 1, *Kernel, A, X, Y)
.thenCopyD2H<float>(X, HostX);
// Wait for the stream to complete.
- se::dieIfError(Stream->blockHostUntilDone());
+ se::dieIfError(Stream.blockHostUntilDone());
// Process output data in HostX.
std::vector<float> ExpectedX = {4, 47, 90, 133};
std::move(*MaybeKernelHandle));
}
- Expected<std::unique_ptr<Stream>> createStream();
+ /// Creates a stream object for this device.
+ Expected<Stream> createStream();
/// Allocates an array of ElementCount entries of type T in device memory.
template <typename T>
public:
explicit Stream(std::unique_ptr<PlatformStreamHandle> PStream);
+ Stream(Stream &&Other) = default;
+ Stream &operator=(Stream &&Other) = default;
+
~Stream();
/// Returns whether any error has occurred while entraining work on this
/// stream.
bool isOK() const {
- llvm::sys::ScopedReader ReaderLock(ErrorMessageMutex);
+ llvm::sys::ScopedReader ReaderLock(*ErrorMessageMutex);
return !ErrorMessage;
}
/// Returns the status created by the first error that occurred while
/// entraining work on this stream.
Error getStatus() const {
- llvm::sys::ScopedReader ReaderLock(ErrorMessageMutex);
+ llvm::sys::ScopedReader ReaderLock(*ErrorMessageMutex);
if (ErrorMessage)
return make_error(*ErrorMessage);
else
/// Does not overwrite the error if it is already set.
void setError(Error &&E) {
if (E) {
- llvm::sys::ScopedWriter WriterLock(ErrorMessageMutex);
+ llvm::sys::ScopedWriter WriterLock(*ErrorMessageMutex);
if (!ErrorMessage)
ErrorMessage = consumeAndGetMessage(std::move(E));
}
///
/// Does not overwrite the error if it is already set.
void setError(llvm::Twine Message) {
- llvm::sys::ScopedWriter WriterLock(ErrorMessageMutex);
+ llvm::sys::ScopedWriter WriterLock(*ErrorMessageMutex);
if (!ErrorMessage)
ErrorMessage = Message.str();
}
std::unique_ptr<PlatformStreamHandle> ThePlatformStream;
/// Mutex that guards the error state flags.
- ///
- /// Mutable so that it can be obtained via const reader lock.
- mutable llvm::sys::RWMutex ErrorMessageMutex;
+ std::unique_ptr<llvm::sys::RWMutex> ErrorMessageMutex;
/// First error message for an operation in this stream or empty if there have
/// been no errors.
Device::~Device() = default;
-Expected<std::unique_ptr<Stream>> Device::createStream() {
+Expected<Stream> Device::createStream() {
Expected<std::unique_ptr<PlatformStreamHandle>> MaybePlatformStream =
PDevice->createStream();
if (!MaybePlatformStream) {
}
assert((*MaybePlatformStream)->getDevice() == PDevice &&
"an executor created a stream with a different stored executor");
- return llvm::make_unique<Stream>(std::move(*MaybePlatformStream));
+ return Stream(std::move(*MaybePlatformStream));
}
} // namespace streamexecutor
namespace streamexecutor {
Stream::Stream(std::unique_ptr<PlatformStreamHandle> PStream)
- : PDevice(PStream->getDevice()), ThePlatformStream(std::move(PStream)) {}
+ : PDevice(PStream->getDevice()), ThePlatformStream(std::move(PStream)),
+ ErrorMessageMutex(llvm::make_unique<llvm::sys::RWMutex>()) {}
Stream::~Stream() = default;