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

Function sgd

hls_smartInfinity/src/kernel_cpp/sgd_topk.cpp:89–167  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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

Callers 1

sgd_topk.cppFile · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected