1 /* Copyright 2019 The TensorFlow Authors. All Rights Reserved. 2 3 Licensed under the Apache License, Version 2.0 (the "License"); 4 you may not use this file except in compliance with the License. 5 You may obtain a copy of the License at 6 7 http://www.apache.org/licenses/LICENSE-2.0 8 9 Unless required by applicable law or agreed to in writing, software 10 distributed under the License is distributed on an "AS IS" BASIS, 11 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 See the License for the specific language governing permissions and 13 limitations under the License. 14 ==============================================================================*/ 15 16 #include "tensorflow/stream_executor/gpu/gpu_stream.h" 17 18 #include "tensorflow/stream_executor/gpu/gpu_executor.h" 19 #include "tensorflow/stream_executor/lib/status.h" 20 #include "tensorflow/stream_executor/stream.h" 21 22 namespace stream_executor { 23 namespace gpu { 24 25 bool GpuStream::Init() { 26 if (!GpuDriver::CreateStream(parent_->gpu_context(), &gpu_stream_)) { 27 return false; 28 } 29 return GpuDriver::CreateEvent(parent_->gpu_context(), &completed_event_, 30 GpuDriver::EventFlags::kDisableTiming) 31 .ok(); 32 } 33 34 void GpuStream::Destroy() { 35 if (completed_event_ != nullptr) { 36 port::Status status = 37 GpuDriver::DestroyEvent(parent_->gpu_context(), &completed_event_); 38 if (!status.ok()) { 39 LOG(ERROR) << status.error_message(); 40 } 41 } 42 43 GpuDriver::DestroyStream(parent_->gpu_context(), &gpu_stream_); 44 } 45 46 bool GpuStream::IsIdle() const { 47 return GpuDriver::IsStreamIdle(parent_->gpu_context(), gpu_stream_); 48 } 49 50 GpuStream* AsGpuStream(Stream* stream) { 51 DCHECK(stream != nullptr); 52 return static_cast<GpuStream*>(stream->implementation()); 53 } 54 55 GpuStreamHandle AsGpuStreamValue(Stream* stream) { 56 DCHECK(stream != nullptr); 57 return AsGpuStream(stream)->gpu_stream(); 58 } 59 60 } // namespace gpu 61 } // namespace stream_executor 62