FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
cpp-taskflow/benchmark/mnist/taskflow.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
/
taskflow.cpp
Copy path
More file actions
More file actions
Latest commit
History
History
History
84 lines (67 loc) · 2.58 KB
Breadcrumbs
cpp-taskflow
/
benchmark
/
mnist
/
taskflow.cpp
Copy path
File metadata and controls
84 lines (67 loc) · 2.58 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
"
dnn.hpp
"
#
include
<
taskflow/taskflow.hpp
>
void
run_taskflow
(
MNIST
& D,
unsigned
num_threads) {
tf::Taskflow tf {num_threads};
std::vector<tf::Task> forward_tasks;
std::vector<tf::Task> backward_tasks;
std::vector<tf::Task> update_tasks;
std::vector<tf::Task> shuffle_tasks;
//
Number of parallel shuffle
const
auto
num_storage = num_threads;
const
auto
num_par_shf =
std::min
(num_storage, D.
epoch
);
std::vector<Eigen::MatrixXf>
mats
(num_par_shf, D.
images
);
std::vector<Eigen::VectorXi>
vecs
(num_par_shf, D.
labels
);
//
Create task flow graph
const
auto
iter_num = D.
images
.
rows
()/D.
batch_size
;
for
(
auto
e=
0u
; e<D.
epoch
; e++) {
for
(
auto
i=
0u
; i<iter_num; i++) {
auto
& f_task = forward_tasks.
emplace_back
(tf.
silent_emplace
(
[&, i=i, e=e%num_par_shf]() {
forward_task
(D, i, e, mats, vecs); }
));
if
(i !=
0
|| (i ==
0
&& e !=
0
)) {
auto
sz = update_tasks.
size
();
for
(
auto
j=
1u
; j<=D.
acts
.
size
() ;j++) {
update_tasks[sz-j].
precede
(f_task);
}
}
for
(
int
j=D.
acts
.
size
()-
1
; j>=
0
; j--) {
//
backward propagation
auto
& b_task = backward_tasks.
emplace_back
(tf.
silent_emplace
(
[&, i=j, e=e%num_par_shf] () {
backward_task
(D, i, e, mats); }
));
//
update weight
auto
& u_task = update_tasks.
emplace_back
(
tf.
silent_emplace
([&, i=j] () {D.
update
(i);})
);
if
(j +
1u
== D.
acts
.
size
()) {
f_task.
precede
(b_task);
}
else
{
backward_tasks[backward_tasks.
size
()-
2
].
precede
(b_task);
}
b_task.
precede
(u_task);
}
//
End of backward propagation
}
//
End of all iterations (task flow graph creation)
if
(e ==
0
) {
//
No need to shuffle in first epoch
shuffle_tasks.
emplace_back
(tf.
silent_emplace
([](){}))
.
precede
(forward_tasks[forward_tasks.
size
()-iter_num]);
}
else
{
auto
& t = shuffle_tasks.
emplace_back
(tf.
silent_emplace
(
[&, e=e%num_par_shf]() { D.
shuffle
(mats[e], vecs[e], D.
images
.
rows
());}
));
t.
precede
(forward_tasks[forward_tasks.
size
()-iter_num]);
//
This shuffle task starts after belows finish
//
1. previous shuffle on the same storage
//
2. the last backward task of previous epoch on the same storage
if
(e >= num_par_shf) {
auto
prev_e = e - num_par_shf;
shuffle_tasks[prev_e].
precede
(t);
int
task_id = (prev_e+
1
)*iter_num*D.
acts
.
size
() -
1
;
backward_tasks[task_id].
precede
(t);
}
}
}
//
End of all epoch
tf.
wait_for_all
();
}
Back
|
FazBrowse Home
|
New Git URL