1 /* Copyright 2015 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/cuda/cuda_stream.h" 17 18 #include "tensorflow/stream_executor/cuda/cuda_gpu_executor.h" 19 #include "tensorflow/stream_executor/lib/status.h" 20 #include "tensorflow/stream_executor/stream.h" 21 22 namespace perftools { 23 namespace gputools { 24 namespace cuda { 25 26 bool CUDAStream::Init() { 27 if (!CUDADriver::CreateStream(parent_->cuda_context(), &cuda_stream_)) { 28 return false; 29 } 30 return CUDADriver::CreateEvent(parent_->cuda_context(), &completed_event_, 31 CUDADriver::EventFlags::kDisableTiming) 32 .ok(); 33 } 34 35 void CUDAStream::Destroy() { 36 if (completed_event_ != nullptr) { 37 port::Status status = 38 CUDADriver::DestroyEvent(parent_->cuda_context(), &completed_event_); 39 if (!status.ok()) { 40 LOG(ERROR) << status.error_message(); 41 } 42 } 43 44 CUDADriver::DestroyStream(parent_->cuda_context(), &cuda_stream_); 45 } 46 47 bool CUDAStream::IsIdle() const { 48 return CUDADriver::IsStreamIdle(parent_->cuda_context(), cuda_stream_); 49 } 50 51 CUDAStream *AsCUDAStream(Stream *stream) { 52 DCHECK(stream != nullptr); 53 return static_cast<CUDAStream *>(stream->implementation()); 54 } 55 56 CUstream AsCUDAStreamValue(Stream *stream) { 57 DCHECK(stream != nullptr); 58 return AsCUDAStream(stream)->cuda_stream(); 59 } 60 61 } // namespace cuda 62 } // namespace gputools 63 } // namespace perftools 64