[Core/NPU/Emul] Fill the function body for AVGP emulation
authorWook Song <wook16.song@samsung.com>
Mon, 18 Nov 2019 04:42:20 +0000 (13:42 +0900)
committer채동주/On-Device Lab(SR)/Staff Engineer/삼성전자 <dongju.chae@samsung.com>
Tue, 19 Nov 2019 06:42:20 +0000 (15:42 +0900)
This function fills the function body for emulation of the Average
Pooling instruction. The emulation for AVGP is enabled via this
function.

Signed-off-by: Wook Song <wook16.song@samsung.com>
src/core/npu/NPUemul.cpp

index 9a7e9cb..869d76f 100644 (file)
@@ -228,11 +228,48 @@ class NPUCoreEmul : public TrinityCore<64>, public DataGen {
 
     /** @brief run AVGP (average pooling) op */
     void run_avgp_op (TRINITY_CORE_PARA_OP& op) {
+      static const int AVGP_RSHAMTS[17] = {
+          0, 0, 0, 1,
+          1, 0, 2, 0,
+          2, 3, 0, 0,
+          3, 0, 0, 0,
+          3};
+      static const int AVGP_MULTS[17] = {
+          0, 0, 1073741824, 1431655765,
+          1073741824, 0, 1431655765, 0,
+          1073741824, 1908874354, 0, 0,
+          1431655765, 0, 0, 0,
+          1073741824};
       avgp_fields avgp;
 
       memcpy(&avgp, PC, sizeof(avgp));
+      op.info.OPCODE = 5;
+      op.cfg.WGT_QBIT = 1;
 
-      /* TODO: Fill here */
+      op.cfg.FLT_H = avgp.flt_h_m1 + 1;
+      op.cfg.FLT_W = avgp.flt_w_m1 + 1;
+      op.cfg.STR_Y = avgp.str_y_m1 + 1;
+      op.cfg.STR_X = avgp.str_x_m1 + 1;
+      op.cfg.PAD_L = avgp.pad_l;
+      op.cfg.PAD_R = avgp.pad_r;
+      op.cfg.PAD_T = avgp.pad_t;
+      op.cfg.PAD_B = avgp.pad_b;
+
+      op.data_size.OUT_H = avgp.out_h_m1 + 1;
+      op.data_size.OUT_W = avgp.out_w_m1 + 1;
+      op.data_size.OUT_D = avgp.out_d_m1 + 1;
+      op.data_size.IN0_D = avgp.out_d_m1 + 1;
+
+      op.quant.IN0_ZERO = 0;
+      op.quant.OUT_ZERO = 0;
+
+      op.quant.OUT_RSHAMT = AVGP_RSHAMTS[op.cfg.FLT_H * op.cfg.FLT_W];
+      op.quant.OUT_MULT = AVGP_MULTS[op.cfg.FLT_H * op.cfg.FLT_W];
+      op.quant.OUT_LSHAMT = 0;
+
+      if (alloc_trinity_data (op, avgp.in0_eaddr0, -1, -1)) {
+        dump_fmap_out(avgp.out_eaddr0);
+      }
 
       PC += sizeof(avgp);
     }
@@ -358,7 +395,8 @@ class NPUCoreEmul : public TrinityCore<64>, public DataGen {
 
         switch (opcode) {
           case VISA_RELU:   /** @todo */
-          case VISA_AVGP:   /** @todo */
+          case VISA_AVGP:
+            run_avgp_op (op);
           case VISA_NOP:    /** do nothing */
             PC += sizeof(uint32_t);
             break;