-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.cc
More file actions
58 lines (45 loc) · 1.47 KB
/
test.cc
File metadata and controls
58 lines (45 loc) · 1.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#include "tensorflow/core/framework/graph.pb.h"
#include "tensorflow/core/public/session.h"
#include "tensorflow/core/framework/tensor.h"
#include <sstream>
#include <string>
#include <fstream>
#include "tensorflow/core/framework/graph_def_util.h"
#include <chrono>
using namespace tensorflow;
const std::string GRAPH_FILE = "test.pb";
int main(int argc, char* argv[]) {
Session* session;
Status status = NewSession(SessionOptions(), &session);
if (!status.ok()) {
std::cout << status.ToString() << "\n";
return 1;
}
GraphDef graph_def;
status = ReadBinaryProto(Env::Default(), GRAPH_FILE, &graph_def);
if (!status.ok()) {
std::cout << status.ToString() << "\n";
return 1;
}
status = session->Create(graph_def);
if (!status.ok()) {
std::cout << status.ToString() << "\n";
return 1;
}
status = session->Run({}, {}, {"init"}, nullptr);
if (!status.ok()) {
std::cout << status.ToString() << "\n";
return 1;
}
std::cout << "Starting to evaluate " << std::endl;
std::chrono::steady_clock::time_point begin = std::chrono::steady_clock::now();
status = session->Run({}, {}, {"MatMul"}, nullptr);
if (!status.ok()) {
std::cout << status.ToString() << "\n";
return 1;
}
std::chrono::steady_clock::time_point end= std::chrono::steady_clock::now();
std::cout << "Total execution time (ms): " << std::chrono::duration_cast<std::chrono::milliseconds>(end - begin).count() << std::endl;
session->Close();
return 0;
}