1 /* Copyright 2016 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_HOST_HOST_TIMER_H_ 17 #define TENSORFLOW_STREAM_EXECUTOR_HOST_HOST_TIMER_H_ 18 19 #include <chrono> 20 21 #include "tensorflow/stream_executor/stream_executor_internal.h" 22 23 namespace stream_executor { 24 namespace host { 25 26 class HostTimer : public internal::TimerInterface { 27 public: HostTimer()28 HostTimer() {} ~HostTimer()29 ~HostTimer() override {} 30 31 // Begins the timer at the present point in the stream. 32 bool Start(Stream *stream); 33 34 // Stops the timer at the present point in the stream. 35 bool Stop(Stream *stream); 36 37 // Returns the most recent value recorded for a start/stopcycle, in 38 // microseconds. 39 uint64 Microseconds() const override; 40 41 // Returns the most recent value recorded for a start/stopcycle, in 42 // nanoseconds. 43 uint64 Nanoseconds() const override; 44 45 private: 46 using clock = std::chrono::high_resolution_clock; 47 48 clock::time_point start_time_; 49 clock::duration duration_; 50 51 // Actually starts (rather than enqueues starting) the timer. 52 void StartNow(); 53 54 // Actually stops (rather than enqueues stopping) the timer. 55 void StopNow(); 56 }; 57 58 } // namespace host 59 } // namespace stream_executor 60 61 #endif // TENSORFLOW_STREAM_EXECUTOR_HOST_HOST_TIMER_H_ 62