MCPcopy Create free account
hub / github.com/AIS-SNU/Smart-Infinity / adagrad

Function adagrad

hls_smartInfinity/src/kernel_cpp/adagrad_topk.cpp:89–171  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

87
88
89void adagrad ( half* grad16, dhvec* param16, vec* param, vec* exp_avg_sq, uint n_elements,
90 float eps, float w_decay, float step_size, float combined_unscale )
91{
92 hvec g16[DATA_SIZE];
93 vec g[DATA_SIZE];
94 vec p[DATA_SIZE];
95 vec v[DATA_SIZE];
96 vec m[DATA_SIZE];
97
98 float _eps = eps;
99 float _step_size = step_size;
100 float _w_decay = w_decay;
101 float _combined_unscale = combined_unscale;
102
103 uint iteration = n_elements / VEC_SIZE;
104 vadd_pipeline: for (uint i = 0 ; i < iteration ; i += DATA_SIZE)
105 {
106 #pragma HLS PIPELINE rewind
107 uint size = DATA_SIZE;
108 //boundary check
109 if (i + size > iteration) size = iteration - i;
110
111 uint size_h = size / 2;
112 uint i_h = i / 2;
113
114 read_p: for (uint x = 0 ; x < size; ++x)
115 {
116 #pragma HLS PIPELINE II=1
117 p[x] = param[i + x];
118 }
119
120 read_g: for ( uint x = 0; x < size; ++x)
121 {
122 #pragma HLS PIPELINE II=1
123 inner_read_g1: for (uint y = 0 ; y < VEC_SIZE; ++y)
124 {
125 #pragma HLS UNROLL
126 m[ x ][y ] = grad16[ (i + x) * VEC_SIZE + y] * _combined_unscale;
127 }
128 }
129
130 read_v: for (uint x = 0; x < size; ++x)
131 {
132 #pragma HLS PIPELINE II=1
133 g[x] = m[x] + _w_decay * p[x];
134 v[x] = g[x] * g[x] + exp_avg_sq[i + x];
135 }
136
137 write_v: for (uint x = 0; x < size; ++x)
138 {
139 #pragma HLS PIPELINE II=1
140 exp_avg_sq[i + x] = v[x];
141 }
142
143 compute_p: for ( uint x = 0; x < size; ++x)
144 {
145 #pragma HLS PIPELINE II=1
146 inner_compute_p: for ( uint y= 0 ; y< VEC_SIZE; y++)

Callers 1

adagrad_topk.cppFile · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected