-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathim.cpp
More file actions
117 lines (93 loc) · 3.28 KB
/
Copy pathim.cpp
File metadata and controls
117 lines (93 loc) · 3.28 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
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
#include <convolution.hpp>
#define DEBUG_LEVEL warning
//#define DEBUG_LEVEL trace
void boost_init()
{
logging::core::get()->set_filter
(
logging::trivial::severity >= logging::trivial::DEBUG_LEVEL
);
};
inline void print_header(std::string s){
using namespace std;
print_separator(rang::fg::red,s.length()+4);
cout << rang::fg::red << "║ " << s << " ║" << rang::style::reset << endl;
print_separator(rang::fg::red,s.length()+4);
}
int main(){
// Let's initialize Boost logging system
boost_init();
BOOST_LOG_TRIVIAL(trace) << "Starting main";
// Define input parameters
const size_t input_width = 14;
const size_t input_height = 14;
const size_t input_depth = 3;
const short stride=1;
const int bias = 0;
/*
* GoogLeNet values
*
const int num11=128;
const int num33reduce=128;
const int num33=256;
const int num55reduce=24;
const int num55=64;
const int poolproj=64;
*/
const int num1_11=5;
const int num2_11=5;
const int num2_33=7;
const int num3_11=6;
const int num3_55=3;
const int num4_11=2;
/*
* Let's create the components of the Inception module. For each volume,
* we first create a convolver object; weights are generated by a stub method.
* Then, we apply the convolution/pool.
*/
cl::sycl::queue q;
print_header("Initializing volumes");
Volume input_volume=Volume(cl::sycl::range<3>(input_width,input_height,input_depth));
Volume *vol1, *vol2, *vol3, *vol4, *vol2_t, *vol3_t, *vol4_t;
Volume output;
initialize_volume(input_volume, true, 255, q);
print_header("Initializing convolvers");
Volumes weights_1_11 = generate_stub_weights(1,input_depth,num1_11,q);
convolver c1_11(weights_1_11,stride,bias);
vol1=c1_11.initialize_hard(input_volume,q);
Volumes weights_2_11 = generate_stub_weights(1,input_depth,num2_11,q);
convolver c2_11(weights_2_11,stride,bias);
vol2_t=c2_11.initialize_hard(input_volume,q);
Volumes weights_2_33 = generate_stub_weights(3,num2_11,num2_33,q);
convolver c2_33(weights_2_33,stride,bias);
vol2=c2_33.initialize_soft(vol2_t,input_width,input_height,num2_11,q);
Volumes weights_3_11 = generate_stub_weights(1,input_depth,num3_11,q);
convolver c3_11(weights_3_11,stride,bias);
vol3_t=c3_11.initialize_hard(input_volume,q);
Volumes weights_3_55 = generate_stub_weights(5,num3_11,num3_55,q);
convolver c3_55(weights_3_55,stride,bias);
vol3=c3_55.initialize_soft(vol3_t,input_width,input_height,num3_11,q);
convolver p4_33(3,1);
vol4_t=p4_33.initialize_hard(input_volume,q);
Volumes weights_4_11 = generate_stub_weights(1,input_depth,num4_11,q);
convolver c4_11(weights_4_11,stride,bias);
vol4=c4_11.initialize_soft(vol4_t,input_width,input_height,input_depth,q);
concatenator concat=concatenator({vol1,vol2,vol3,vol4});
output=concat.concatenated_volume;
print_header("Launching convolutions");
c1_11.convolve();
c2_11.convolve();
c2_33.convolve();
c3_11.convolve();
c3_55.convolve();
p4_33.pool();
c4_11.convolve();
print_header("Concatenating");
concat.concatenate(q);
BOOST_LOG_TRIVIAL(debug) << "Waiting for queue to finish...";
auto a = output.get_access<cl::sycl::access::mode::read>();
BOOST_LOG_TRIVIAL(debug) << "Finished.";
print_header("Final output");
print_volume(output);
return 0;
};