/** 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;
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";
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;
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
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);
/** 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),
/** 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),
/** 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 */
/** 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 */
/** 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 */
/** 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;
/** 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;