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