Skip to content
This repository was archived by the owner on Jul 1, 2025. It is now read-only.

Commit 0f81edf

Browse files
authored
Merge pull request #24 from compnerd/timer
Support: use llvm::Timer instead of a local implementation
2 parents 81e3b66 + 34168e5 commit 0f81edf

File tree

4 files changed

+19
-21
lines changed

4 files changed

+19
-21
lines changed

examples/cifar10.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
#include "glow/Interpreter/Interpreter.h"
55
#include "glow/Support/Support.h"
66

7+
#include "llvm/Support/Timer.h"
8+
79
#include <cassert>
810
#include <cstddef>
911
#include <cstdint>
@@ -109,7 +111,9 @@ void testCIFAR10() {
109111

110112
for (int iter = 0; iter < 100000; iter++) {
111113
std::cout << "Training - iteration #" << iter << "\n";
112-
TimerGuard reportTime(reportRate * minibatchSize);
114+
115+
llvm::Timer timer("Training", "Training");
116+
timer.startTimer();
113117

114118
// Bind the images tensor to the input array A, and the labels tensor
115119
// to the softmax node SM.
@@ -137,6 +141,8 @@ void testCIFAR10() {
137141
}
138142
}
139143

144+
timer.stopTimer();
145+
140146
std::cout << "Batch #" << iter << " score: " << score << "%\n";
141147
}
142148
}

examples/mnist.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
#include "glow/Interpreter/Interpreter.h"
55
#include "glow/Support/Support.h"
66

7+
#include "llvm/Support/Timer.h"
8+
79
#include <cassert>
810
#include <cstddef>
911
#include <cstdint>
@@ -102,11 +104,16 @@ void testMNIST() {
102104

103105
for (int iter = 0; iter < 60; iter++) {
104106
std::cout << "Training - iteration #" << iter << " ";
105-
TimerGuard reportTime(reportRate * minibatchSize);
107+
108+
llvm::Timer timer("Training", "Training");
109+
timer.startTimer();
110+
106111
// On each training iteration take an input from imageInputs and update
107112
// the input variable A, and add take a corresponding label and update the
108113
// softmax layer.
109114
IP.train(reportRate, {A, selected}, {&imageInputs, &labelInputs});
115+
116+
timer.stopTimer();
110117
}
111118
std::cout << "Validating.\n";
112119
IP.optimize(OptimizationMode::Infer);

external/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,10 @@ foreach(library tinfo terminfo curses ncurses ncursesw)
6767
endif()
6868
endforeach()
6969

70+
target_link_libraries(LLVMSupport
71+
INTERFACE
72+
Threads::Threads)
73+
7074
add_dependencies(LLVMSupport llvm-install)
7175

7276
ExternalProject_Add(googletest

include/glow/Support/Support.h

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -16,25 +16,6 @@ std::string to_string(const llvm::StringRef sr);
1616

1717
namespace glow {
1818

19-
/// A class for measuring the lifetime of some event
20-
/// and for rate calculation.
21-
class TimerGuard {
22-
int iterations_;
23-
std::chrono::time_point<std::chrono::system_clock> start;
24-
25-
public:
26-
TimerGuard(int iterations) : iterations_(iterations) {
27-
start = std::chrono::system_clock::now();
28-
}
29-
30-
~TimerGuard() {
31-
auto end = std::chrono::system_clock::now();
32-
std::chrono::duration<double> elapsed_seconds = end - start;
33-
std::cout << "Rate: " << (iterations_ / elapsed_seconds.count())
34-
<< "/sec\n";
35-
}
36-
};
37-
3819
/// \returns the escaped content of string \p str.
3920
/// The char '\n' becomes '\'+'n' and quotes are handled correctly.
4021
std::string escapeDottyString(const std::string &str);

0 commit comments

Comments
 (0)