• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
Init()25 bool GpuStream::Init() {
26   if (!GpuDriver::CreateStream(parent_->gpu_context(), &gpu_stream_,
27                                priority_)) {
28     return false;
29   }
30   return GpuDriver::InitEvent(parent_->gpu_context(), &completed_event_,
31                               GpuDriver::EventFlags::kDisableTiming)
32       .ok();
33 }
34 
Destroy()35 void GpuStream::Destroy() {
36   if (completed_event_ != nullptr) {
37     port::Status status =
38         GpuDriver::DestroyEvent(parent_->gpu_context(), &completed_event_);
39     if (!status.ok()) {
40       LOG(ERROR) << status.error_message();
41     }
42   }
43 
44   GpuDriver::DestroyStream(parent_->gpu_context(), &gpu_stream_);
45 }
46 
IsIdle() const47 bool GpuStream::IsIdle() const {
48   return GpuDriver::IsStreamIdle(parent_->gpu_context(), gpu_stream_);
49 }
50 
AsGpuStream(Stream * stream)51 GpuStream* AsGpuStream(Stream* stream) {
52   DCHECK(stream != nullptr);
53   return static_cast<GpuStream*>(stream->implementation());
54 }
55 
AsGpuStreamValue(Stream * stream)56 GpuStreamHandle AsGpuStreamValue(Stream* stream) {
57   DCHECK(stream != nullptr);
58   return AsGpuStream(stream)->gpu_stream();
59 }
60 
61 }  // namespace gpu
62 }  // namespace stream_executor
63