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

Function adagrad

hls_smartInfinity/src/kernel_cpp/adagrad.cpp:25–113  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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

Callers 1

krnl_vaddFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected