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

Function sgd

hls_smartInfinity/src/kernel_cpp/sgd.cpp:26–111  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

24
25
26void sgd ( dhvec* grad16, dhvec* param16, vec* param, vec* exp_avg, uint n_elements,
27 float betta, float w_decay, float step_size, float combined_unscale )
28{
29 vec g[DATA_SIZE];
30 vec p[DATA_SIZE];
31 vec m[DATA_SIZE];
32
33 float _betta = betta;
34 float _betta_minus1 = (1.0f - _betta);
35 float _step_size = step_size;
36 float _w_decay = w_decay;
37 float _combined_unscale = combined_unscale;
38
39 uint iteration = n_elements / VEC_SIZE;
40 vadd_pipeline: for (uint i = 0 ; i < iteration ; i += DATA_SIZE)
41 {
42 #pragma HLS PIPELINE rewind
43 uint size = DATA_SIZE;
44 //boundary check
45 if (i + size > iteration) size = iteration - i;
46
47 uint size_h = size / 2;
48 uint i_h = i / 2;
49
50 read_p: for (uint x = 0 ; x < size; ++x)
51 {
52 #pragma HLS PIPELINE II=1
53 p[x] = param[i + x];
54 }
55
56 read_g: for ( uint x = 0; x < size_h; ++x)
57 {
58 uint a = 2 * x;
59 uint b = i_h + x;
60 #pragma HLS PIPELINE II=1
61 inner_read_g1: for (uint y = 0 ; y < VEC_SIZE; ++y)
62 {
63 #pragma HLS UNROLL
64 g[ a ][y ] = grad16[ b ][y] * _combined_unscale;
65 }
66 inner_read_g2: for (uint y = 0 ; y < VEC_SIZE; ++y)
67 {
68 #pragma HLS UNROLL
69 g[ a + 1 ][y ] = grad16[ b ][VEC_SIZE + y] * _combined_unscale;
70 }
71 }
72
73
74 read_m: for (uint x = 0; x < size; ++x)
75 {
76 #pragma HLS PIPELINE II=1
77 g[x] = g[x] + _w_decay * p[x];
78 m[x] = _betta_minus1 * g[x] + ( _betta )* exp_avg[ i + x];
79 }
80
81 write_m: for (uint x = 0; x < size; ++x)
82 {
83 #pragma HLS PIPELINE II=1

Callers 1

krnl_vaddFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected