[TESTDATA] Add enum for trinity opcodes
authorDongju Chae <dongju.chae@samsung.com>
Fri, 15 Nov 2019 05:19:32 +0000 (14:19 +0900)
committer파리차이카푸르/On-Device Lab(SR)/Engineer/삼성전자 <pk.kapoor@samsung.com>
Mon, 18 Nov 2019 07:01:51 +0000 (16:01 +0900)
This commit adds enum for trinity opcodes.

Signed-off-by: Dongju Chae <dongju.chae@samsung.com>
src/test/testdata/testdata_gen.cpp

index 21aea6f..ae6a8c5 100644 (file)
 /** the output address of last layer should be this value */
 #define OUTPUT_ADDR_FINAL 0x200000
 
+/** revise this later */
+typedef enum {
+  TRINITY_OPCODE_CONV = 0,
+  TRINITY_OPCODE_MAXP = 4,
+  TRINITY_OPCODE_AVGP = 5,
+  TRINITY_OPCODE_RELU = 6,
+  TRINITY_OPCODE_ESUM = 7
+} trinity_opcode;
+
 using namespace std;
 using namespace trinity_vision;
 
@@ -61,7 +70,7 @@ void TestdataGen::write_asm_file(int idx, TRINITY_FMAP_PARA& in,
   int dma_wgt_en = 0;
 
   switch (op.info.OPCODE) {
-    case 0:
+    case TRINITY_OPCODE_CONV:
       dma_wgt_en = 1;
       if (op.info.CNV_ESUM_EN) {
         ofs_asm << "CONVE";
@@ -70,16 +79,16 @@ void TestdataGen::write_asm_file(int idx, TRINITY_FMAP_PARA& in,
         ofs_asm << "CONV";
       }
       break;
-    case 4:
+    case TRINITY_OPCODE_MAXP:
       ofs_asm << "MAXP";
       break;
-    case 5:
+    case TRINITY_OPCODE_AVGP:
       ofs_asm << "AVGP";
       break;
-    case 6:
+    case TRINITY_OPCODE_RELU:
       ofs_asm << "RELU";
       break;
-    case 7:
+    case TRINITY_OPCODE_ESUM:
       dma_in1_en = 1;
       ofs_asm << "ESUM";
       break;
@@ -103,7 +112,8 @@ void TestdataGen::write_asm_file(int idx, TRINITY_FMAP_PARA& in,
   ofs_asm << " wgt_qbit_m1=" << cp.WGT_QBIT_M1;
   /** in/out parameters */
   ofs_asm << " in0_zero=" << cp.IN0_ZERO
-          << " in0_shamt=" << (op.info.OPCODE == 7 ? cp.IN0_RSHAMT : cp.IN0_LSHAMT)
+          << " in0_shamt=" << (op.info.OPCODE == TRINITY_OPCODE_ESUM ?
+                               cp.IN0_RSHAMT : cp.IN0_LSHAMT)
           << " in0_mult=" << cp.IN0_MULT;
   ofs_asm << " in1_zero=" << cp.IN1_ZERO
           << " in1_shamt=" << cp.IN1_RSHAMT
@@ -136,11 +146,11 @@ void TestdataGen::write_asm_file(int idx, TRINITY_FMAP_PARA& in,
   ofs_asm << hex;
   /** the input address is the output address of the previous layer */
   ofs_asm << " in0_iaddr0=0x0 in0_eaddr0=0x" << addr_out_prev;
-  if (op.info.OPCODE == 7 || op.info.CNV_ESUM_EN) {
+  if (op.info.OPCODE == TRINITY_OPCODE_ESUM || op.info.CNV_ESUM_EN) {
     ofs_asm << " in1_iaddr0=0x40000 in1_eaddr0=0x" << addr_in;
     addr_in += size_input;
   }
-  if (op.info.OPCODE < 4)
+  if (op.info.OPCODE < TRINITY_OPCODE_MAXP)
     ofs_asm << " wgt_iaddr0=0x80000 wgt_eaddr0=0x" << addr_wgt;
   ofs_asm << " out_iaddr0=0xC0000 out_eaddr0=0x" << (last ? OUTPUT_ADDR_FINAL : addr_out);
 
@@ -211,7 +221,7 @@ void TestdataGen::emit()
 
     /** esum (== in1) fmap (if exist) */
     TR_FMAP trinity_esum_in;
-    if (ops[idx].info.OPCODE == 7 || ops[idx].info.CNV_ESUM_EN) {
+    if (ops[idx].info.OPCODE == TRINITY_OPCODE_ESUM || ops[idx].info.CNV_ESUM_EN) {
       trinity_esum_in.alloc(size3d_in);
       trinity_esum_in.gen_rand(9, 0);
       trinity_esum_in.write_data_file(dir, "input_esum_" + to_string(idx),
@@ -220,7 +230,7 @@ void TestdataGen::emit()
 
     /** input weight (random generation) */
     TrinityWgt trinity_weight;
-    if (ops[idx].info.OPCODE < 4) {
+    if (ops[idx].info.OPCODE < TRINITY_OPCODE_MAXP) {
       trinity_weight.alloc(para_weight);
       trinity_weight.gen_rand();
       trinity_weight.write_data_file(dir, "input_weight_" + to_string(idx),
@@ -263,7 +273,7 @@ void gen_testdata_testcase1(const char* dir)
   /** 1) 3x3 CONV */
   TRINITY_CORE_PARA_OP conv1;
 
-  conv1.info.OPCODE = 0;
+  conv1.info.OPCODE = TRINITY_OPCODE_CONV;
   /** the number of code bits per weight */
   conv1.cfg.WGT_QBIT = 2;
   /** the dimension of convoution filter */
@@ -288,7 +298,7 @@ void gen_testdata_testcase1(const char* dir)
   /** 2) 1x1 CONV */
   TRINITY_CORE_PARA_OP conv2;
 
-  conv2.info.OPCODE = 0;
+  conv2.info.OPCODE = TRINITY_OPCODE_CONV;
   /** the number of code bits per weight */
   conv2.cfg.WGT_QBIT = 2;
   /** the dimension of convoution filter */
@@ -316,7 +326,7 @@ void gen_testdata_testcase2(const char* dir)
   /** 1) 3x3 CONV */
   TRINITY_CORE_PARA_OP conv;
 
-  conv.info.OPCODE = 0;
+  conv.info.OPCODE = TRINITY_OPCODE_CONV;
   /** the number of code bits per weight */
   conv.cfg.WGT_QBIT = 2;
   /** the dimension of convoution filter */
@@ -341,7 +351,7 @@ void gen_testdata_testcase2(const char* dir)
   /** 2) ESUM */
   TRINITY_CORE_PARA_OP esum;
 
-  esum.info.OPCODE = 7;
+  esum.info.OPCODE = TRINITY_OPCODE_ESUM;
   esum.cfg.WGT_QBIT = 1;
   esum.cfg.FLT_H = 1;
   esum.cfg.FLT_W = 1;
@@ -359,7 +369,7 @@ void gen_testdata_testcase2(const char* dir)
   /** 3) MAXP */
   TRINITY_CORE_PARA_OP maxp;
 
-  maxp.info.OPCODE = 4;
+  maxp.info.OPCODE = TRINITY_OPCODE_MAXP;
   maxp.cfg.WGT_QBIT = 1;
   maxp.cfg.FLT_H = 2;
   maxp.cfg.FLT_W = 2;