FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
cpp-taskflow/benchmark/mnist/main.cpp at master · fcccode/cpp-taskflow · GitHub
fcccode
/
cpp-taskflow
Public
forked from
taskflow/taskflow
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
cpp-taskflow
/
benchmark
/
mnist
/
main.cpp
Copy path
More file actions
More file actions
Latest commit
History
History
History
84 lines (69 loc) · 2.37 KB
Breadcrumbs
cpp-taskflow
/
benchmark
/
mnist
/
main.cpp
Copy path
File metadata and controls
84 lines (69 loc) · 2.37 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#
include
<
thread
>
#
include
<
iomanip
>
#
include
"
dnn.hpp
"
//
Function: measure_time_taskflow
std::chrono::milliseconds
measure_time_taskflow
(
unsigned
num_epochs,
unsigned
num_threads
) {
auto
dnn {
build_dnn
(num_epochs)};
auto
t1 =
std::chrono::high_resolution_clock::now
();
run_taskflow
(dnn, num_threads);
auto
t2 =
std::chrono::high_resolution_clock::now
();
return
std::chrono::duration_cast<std::chrono::milliseconds>(t2 - t1);
}
//
Function: measure_time_omp
std::chrono::milliseconds
measure_time_omp
(
unsigned
num_epochs,
unsigned
num_threads
) {
auto
dnn {
build_dnn
(num_epochs)};
auto
t1 =
std::chrono::high_resolution_clock::now
();
run_omp
(dnn, num_threads);
auto
t2 =
std::chrono::high_resolution_clock::now
();
return
std::chrono::duration_cast<std::chrono::milliseconds>(t2 - t1);
}
//
Function: measure_time_tbb
std::chrono::milliseconds
measure_time_tbb
(
unsigned
num_epochs,
unsigned
num_threads
) {
auto
dnn {
build_dnn
(num_epochs)};
auto
t1 =
std::chrono::high_resolution_clock::now
();
run_tbb
(dnn, num_threads);
auto
t2 =
std::chrono::high_resolution_clock::now
();
return
std::chrono::duration_cast<std::chrono::milliseconds>(t2 - t1);
}
//
Function: main
int
main
(
int
argc,
char
*argv[]){
unsigned
num_threads =
std::thread::hardware_concurrency
();
if
(argc >
1
) {
num_threads =
std::atoi
(argv[
1
]);
}
int
rounds {
5
};
std::cout <<
std::setw
(
12
) <<
"
# epochs
"
<<
std::setw
(
12
) <<
"
OpenMP
"
<<
std::setw
(
12
) <<
"
TBB
"
<<
std::setw
(
12
) <<
"
Taskflow
"
<<
std::setw
(
12
) <<
"
speedup1
"
<<
std::setw
(
12
) <<
"
speedup2
"
<<
'
\n
'
;
for
(
int
epoch=
10
; epoch<=
100
; epoch+=
10
) {
double
omp_time {
0.0
};
double
tbb_time {
0.0
};
double
tf_time {
0.0
};
for
(
int
j=
0
; j<rounds; ++j) {
omp_time +=
measure_time_omp
(epoch, num_threads).
count
();
tbb_time +=
measure_time_tbb
(epoch, num_threads).
count
();
tf_time +=
measure_time_taskflow
(epoch, num_threads).
count
();
}
std::cout <<
std::setw
(
12
) << epoch
<<
std::setw
(
12
) << omp_time / rounds /
1e3
<<
std::setw
(
12
) << tbb_time / rounds /
1e3
<<
std::setw
(
12
) << tf_time / rounds /
1e3
<<
std::setw
(
12
) << omp_time / tf_time
<<
std::setw
(
12
) << tbb_time / tf_time
<< std::endl;
}
return
EXIT_SUCCESS
;
}
Back
|
FazBrowse Home
|
New Git URL