• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #include "tensorflow/stream_executor/host/host_timer.h"
17 
18 #include "tensorflow/stream_executor/platform/logging.h"
19 #include "tensorflow/stream_executor/stream.h"
20 #include "tensorflow/stream_executor/stream_executor_internal.h"
21 
22 namespace stream_executor {
23 namespace host {
24 
25 using std::chrono::duration_cast;
26 
Start(Stream * stream)27 bool HostTimer::Start(Stream* stream) {
28   return stream->ThenDoHostCallback([this]() { this->StartNow(); }).ok();
29 }
30 
Stop(Stream * stream)31 bool HostTimer::Stop(Stream* stream) {
32   return stream->ThenDoHostCallback([this]() { this->StopNow(); }).ok();
33 }
34 
Microseconds() const35 uint64 HostTimer::Microseconds() const {
36   return duration_cast<std::chrono::microseconds>(duration_).count();
37 }
38 
Nanoseconds() const39 uint64 HostTimer::Nanoseconds() const {
40   return duration_cast<std::chrono::nanoseconds>(duration_).count();
41 }
42 
StartNow()43 void HostTimer::StartNow() { start_time_ = clock::now(); }
44 
StopNow()45 void HostTimer::StopNow() { duration_ = clock::now() - start_time_; }
46 
47 }  // namespace host
48 }  // namespace stream_executor
49