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 #ifndef TENSORFLOW_STREAM_EXECUTOR_EVENT_H_ 17 #define TENSORFLOW_STREAM_EXECUTOR_EVENT_H_ 18 19 #include <memory> 20 21 #include "tensorflow/stream_executor/platform/port.h" 22 23 namespace stream_executor { 24 25 namespace internal { 26 class EventInterface; 27 } 28 29 class Stream; 30 class StreamExecutor; 31 32 // The Event class, when supported by a platform, enables low-overhead status 33 // reporting for a Stream. An Event is inserted at a location in a stream via 34 // the Stream::ThenRecordEvent() API. From then on, the Event's status can be 35 // monitored via the nonblocking Event::PollForStatus() call. 36 class Event { 37 public: 38 // Potential states for an Event. If PollForStatus() returns anything aside 39 // from kPending or kComplete, an error has occurred; kUnknown is a bad state. 40 // Not all implementations are able to return all enumeration values. Refer to 41 // the platform-specific implementation for details. 42 enum class Status { 43 kUnknown, 44 kError, 45 kPending, 46 kComplete, 47 }; 48 49 explicit Event(StreamExecutor* stream_exec); // NOLINT 50 51 // Releases any resources held by the Event object. 52 ~Event(); 53 54 // Performs any platform-specific or potentially error-generating 55 // initialization. 56 bool Init(); 57 58 // Returns the current Status for the event. 59 Status PollForStatus(); 60 61 // Returns a pointer to the underlying platform-specific implementation. implementation()62 internal::EventInterface* implementation() { return implementation_.get(); } 63 64 Event(Event&&) = default; 65 Event& operator=(Event&&) = default; 66 67 private: 68 friend class Stream; 69 70 // Pointer to the StreamExecutor interface used to create this object. 71 // Not owned. 72 StreamExecutor* stream_exec_; 73 74 // Pointer to the platform-specific EventInterface implementation underlying 75 // the object. Owned. 76 std::unique_ptr<internal::EventInterface> implementation_; 77 78 SE_DISALLOW_COPY_AND_ASSIGN(Event); 79 }; 80 81 } // namespace stream_executor 82 83 #endif // TENSORFLOW_STREAM_EXECUTOR_EVENT_H_ 84