{"id":146,"date":"2020-03-29T00:01:36","date_gmt":"2020-03-29T00:01:36","guid":{"rendered":"http:\/\/course.ece.cmu.edu\/~ece500\/projects\/s20-teama7\/?p=146"},"modified":"2020-03-29T03:45:25","modified_gmt":"2020-03-29T03:45:25","slug":"theodors-status-update-for-mar-28","status":"publish","type":"post","link":"https:\/\/course.ece.cmu.edu\/~ece500\/projects\/s20-teama7\/2020\/03\/29\/theodors-status-update-for-mar-28\/","title":{"rendered":"Theodor&#8217;s Status Update for Mar. 28"},"content":{"rendered":"<p><strong>Accomplishments<\/strong><\/p>\n<p>This week I accomplished one of the hard parts of the FPU job manager: writing the FSM for the Convolutional Forward module.<\/p>\n<p>It&#8217;s worth mentioning that there were easier options for implementing Convolutional Forward than to define the operation in an FSM. We could have chosen to write convolutional forward in C, compile it to RISCV-assembly, and copy the code to our FPGA and use that, but this would require precious on-board memory that we need to store input samples. Writing Convolutional forward as an FSM is the fastest and smallest solution to our problem, and doing so will maximize our model throughput. Convolutional backward (gradient with respect to the inputs, filters, or bias) are essentially the same nested loops above, so implementing those operations will be significantly easier if I use the code above as a starting point.<\/p>\n<p>I now know the exact requirements that the FPU Job Manager needs: 32&#215;32-bit registers that can be accessed with multiple reads and multiple writes per cycle (I will have to declare an array of registers and expose all of the wires instead of writing a Register File), and some specific ALU\/FPU instructions:<\/p>\n<ul>\n<li>offset = channel_index + (num_channels * i) + ((num_channels * image height) * j)<\/li>\n<li>x = x + 1 (integer increment)<\/li>\n<li>x = y + z (integer addition)<\/li>\n<li>floating-point multiply<\/li>\n<li>floating-point addition<\/li>\n<\/ul>\n<p>Like I mentioned last week, having Convolutional Forward completely defined will cause a lot of other pieces to fall into place. Next week, I plan on implementing some of these ALU\/FPU and register requirements in SystemVerilog.<\/p>\n<p>Here&#8217;s what my definition looks like:<\/p>\n<pre>pseudocode:\r\n\r\nw_o_fac &lt;- x.height * x.channels\r\n\r\nj &lt;- 0\r\nj_x &lt;- (-1 * pad)\r\nwhile(j &lt; z.width):\r\n  w_o &lt;- w_o_fac * j_x\r\n  i &lt;- 0\r\n  i_x &lt;- -1 * pad\r\n  while(i &lt; z.height):\r\n    beta &lt;- 0\r\n    while(beta &lt; f.width):\r\n      alpha &lt;- 0\r\n      while(alpha &lt;- f.height):\r\n        gamma &lt;- 0\r\n        while(gamma &lt; f.in_channels):\r\n          delta &lt;- 0\r\n          while(delta &lt; f.out_channels):\r\n            z[delta, i, j] &lt;- z[delta, i, j] + (f[delta, gamma, alpha, beta] * x[gamma, i_x + alpha, j_x + beta])\r\n            \r\n            delta &lt;- delta + 1\r\n          \r\n          gamma &lt;- gamma + 1\r\n\r\n        alpha &lt;- alpha + 1\r\n\r\n      beta &lt;- beta + 1\r\n      \r\n      delta &lt;- 0\r\n      while(delta &lt;- z.channels):\r\n        z[delta, i, j] &lt;- z[delta, i, j] + b[delta]\r\n\r\n        delta &lt;- delta + 1\r\n\r\n    i &lt;- i + 1\r\n    i_x &lt;- i_x + stride\r\n\r\n  j &lt;- j + 1\r\n  j_x &lt;- j_x + stride\r\n\r\n\r\nState transitions:\r\n\r\n\/\/ STATE == START_LOAD1\r\nr1 &lt;- stride\r\nr5 &lt;- filter.output_channels\r\nr9 &lt;- x.height\r\nnextState = START_LOAD2\r\n\r\n\r\n\/\/ STATE == START_LOAD2\r\nr2 &lt;- pad\r\nr6 &lt;- filter.input_channels\r\nr10 &lt;- x.width\r\nnextState = START_LOAD3\r\n\r\n\r\n\/\/ STATE == START_LOAD3\r\nr3 &lt;- output_height\r\nr7 &lt;- filter.height\r\nnextState = START_LOAD4\r\n\r\n\r\n\/\/ STATE == START_LOAD4\r\nr4 &lt;- output_width\r\nr8 &lt;- filter.width\r\n*z &lt;- output_height\r\nz++\r\nnextState = START_CALC\r\n\r\n\r\n\/\/ STATE == START_CALC\r\n*z &lt;- output_width\r\nz++\r\nr11 &lt;- r9 * r6         \/\/ w_o_factor = x.height * x.channels\r\nr12 &lt;- ~r2 + 1         \/\/ j_x = -1 * pad\r\nr19 &lt;- 0               \/\/ j = 0\r\nnextState = J_LOOP\r\n\r\n\r\n\/\/ STATE == J_LOOP\r\nr13 &lt;- r11 * r12\r\nif(r19 == r4):         \/\/ if j == z.width\r\n  nextState = DONE\r\nelse:\r\n  r21 &lt;- 0             \/\/ i = 0\r\n  r20 &lt;- ~r2 + 1       \/\/ i_x = -1 * pad\r\n  nextState = I_LOOP\r\n\r\n\r\n\/\/ STATE == I_LOOP\r\nif(r21 == r3):         \/\/ if j == z.height\r\n  r19 &lt;- r19 + 1       \/\/ j += 1\r\n  r12 &lt;- r12 + r1      \/\/ j_x += stride\r\n  nextState = J_LOOP\r\nelse:\r\n  r22 &lt;- 0             \/\/ beta = 0\r\n  r28 &lt;- r20 * r6      \/\/ r28 = f.input_channels * i_x\r\n  nextState = BETA_LOOP\r\n\r\n\r\n\/\/ STATE == BETA_LOOP\r\nif(r22 == r8):         \/\/ if beta == f.width\r\n  r25 &lt;- 0             \/\/ delta = 0\r\n  z &lt;- z - r5          \/\/ Reset z counter, we\u2019re going to iterate over channels again\r\n  b &lt;- 2\r\n  nextState = BIAS_LOOP_LOAD\r\nelse:\r\n  r23 &lt;- 0             \/\/ alpha = 0\r\n  nextState = ALPHA_LOOP\r\n\r\n\r\n\/\/ STATE == ALPHA_LOOP\r\nif(r23 == r7):         \/\/ if alpha == f.height\r\n  r22 &lt;- r22 + 1\r\n  nextState = BETA_LOOP\r\nelse:\r\n  r24 &lt;- 0             \/\/ gamma = 0\r\n  nextState = GAMMA_LOOP\r\n\r\n\r\n\/\/ STATE == GAMMA_LOOP\r\nif(r24 == r6):        \/\/ if gamma == f.input_channels\r\n  r23 &lt;- r23 + 1      \/\/ alpha = 0\r\n  nextState = ALPHA_LOOP\r\nelse:\r\n  r25 &lt;- 0            \/\/ delta = 0\r\n  r27 &lt;- r24 + (r6 * (r20 + r23)) + (r11 * (r12 + r22)) \/\/ x offset\r\n  nextState = DELTA_LOOP_LOAD\r\n\r\n\r\n\/\/ STATE == DELTA_LOOP_LOAD\r\nr14 &lt;- *z             \/\/ r14 &lt;- z[delta, i, j]\r\nr15 &lt;- *f             \/\/ r15 &lt;- f[delta, gamma, alpha, beta]\r\nr16 &lt;- *r27           \/\/ r16 &lt;- x[gamma, i_x + alpha, j_x + beta]\r\nif(mem(z).done &amp;&amp; mem(f).done &amp;&amp; mem(x).done):\r\n  nextState = DELTA_LOOP_CALC1\r\nelse:\r\n  nextState = DELTA_LOOP_LOAD\r\n\r\n\r\n\/\/ STATE == DELTA_LOOP_CALC1\r\n  r17 &lt;- r15 * r16    \/\/ r17 &lt;- f[delta, gamma, alpha, beta] * x[gamma, i_x + alpha, j_x + beta]\r\n  nextState = DELTA_LOOP_CALC2\r\n\r\n\r\n\/\/ STATE == DELTA_LOOP_CALC2\r\n  r18 &lt;- r14 + r17   \/\/ r18 &lt;- z[delta, i, j] + (f[delta, gamma, alpha, beta] * x[gamma, i_x + alpha, j_x + beta])\r\n  nextState = DELTA_LOOP_STORE\r\n\r\n\/\/ STATE == DELTA_LOOP_STORE\r\n*z &lt;- r18\r\nif(mem(z).done &amp;&amp; r25 == r5): \/\/ if(memory is done writing and delta == f.output_channels)\r\n  r24 &lt;- r24 + 1\r\n  nextState = GAMMA_LOOP\r\nelse if(mem.done):\r\n  nextState = DELTA_LOOP_STORE\r\nelse:\r\n  r25 &lt;- r25 + 1        \/\/ delta += 1\r\n  z++\r\n  f++\r\n  nextState = DELTA_LOOP_LOAD\r\n  \r\n\r\n\/\/ STATE == BIAS_LOOP_LOAD\r\nr14 &lt;- *z               \/\/ r14 &lt;- z[delta, i, j]\r\nr15 &lt;- *b               \/\/ r15 &lt;- b[delta]\r\nif(mem(z).done &amp;&amp; mem(b).done):\r\n  nextState = BIAS_LOOP_CALCS\r\nelse:\r\n  nextState = BIAS_LOOP_LOAD\r\n\r\n\/\/ STATE == BIAS_LOOP_CALCS\r\nr16 &lt;- r14 + r15\r\nnextState = BIAS_LOOP_STORE\r\n\r\n\/\/ STATE == BIAS_LOOP_STORE\r\n*z &lt;- r16\r\nif(mem(z).done &amp;&amp; r25 == r5):\r\n  z++\r\n  b++\r\n  r21 &lt;- r21 + 1       \/\/ i += 1\r\n  r20 &lt;- r20 + r1      \/\/ i_x += stride\r\n  nextState = I_LOOP\r\nelse if(mem(z).done):\r\n  r25 &lt;- r25 + 1\r\n  nextState = BIAS_LOOP_LOAD\r\nelse:\r\n  nextState = BIAS_LOOP_STORE\r\n\r\n\/\/ STATE == DONE<\/pre>\n<p><strong>Schedule<\/strong><\/p>\n<p>I remain on the schedule that I proposed last week.<\/p>\n<p><strong>Accomplishments for Next Week<\/strong><\/p>\n<p>Next week will be time to start implementing the FPU Job Manager. Now that I know the upper limit for the resources that the FPU Job Manager needs, I can be confident that I won&#8217;t have to redesign it. Although I only have a couple of FSM controllers defined, I want to go ahead with the implementation so that I can solve any unexpected problems related to SystemVerilog implementation of the modules and memory accesses.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Accomplishments This week I accomplished one of the hard parts of the FPU job manager: writing the FSM for the Convolutional Forward module. It&#8217;s worth mentioning that there were easier options for implementing Convolutional Forward than to define the operation in an FSM. We could have chosen to write convolutional forward in C, compile it &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/course.ece.cmu.edu\/~ece500\/projects\/s20-teama7\/2020\/03\/29\/theodors-status-update-for-mar-28\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Theodor&#8217;s Status Update for Mar. 28&#8221;<\/span><\/a><\/p>\n","protected":false},"author":246,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[3],"tags":[],"_links":{"self":[{"href":"https:\/\/course.ece.cmu.edu\/~ece500\/projects\/s20-teama7\/wp-json\/wp\/v2\/posts\/146"}],"collection":[{"href":"https:\/\/course.ece.cmu.edu\/~ece500\/projects\/s20-teama7\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/course.ece.cmu.edu\/~ece500\/projects\/s20-teama7\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/course.ece.cmu.edu\/~ece500\/projects\/s20-teama7\/wp-json\/wp\/v2\/users\/246"}],"replies":[{"embeddable":true,"href":"https:\/\/course.ece.cmu.edu\/~ece500\/projects\/s20-teama7\/wp-json\/wp\/v2\/comments?post=146"}],"version-history":[{"count":3,"href":"https:\/\/course.ece.cmu.edu\/~ece500\/projects\/s20-teama7\/wp-json\/wp\/v2\/posts\/146\/revisions"}],"predecessor-version":[{"id":156,"href":"https:\/\/course.ece.cmu.edu\/~ece500\/projects\/s20-teama7\/wp-json\/wp\/v2\/posts\/146\/revisions\/156"}],"wp:attachment":[{"href":"https:\/\/course.ece.cmu.edu\/~ece500\/projects\/s20-teama7\/wp-json\/wp\/v2\/media?parent=146"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/course.ece.cmu.edu\/~ece500\/projects\/s20-teama7\/wp-json\/wp\/v2\/categories?post=146"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/course.ece.cmu.edu\/~ece500\/projects\/s20-teama7\/wp-json\/wp\/v2\/tags?post=146"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}