| 126 | } |
| 127 | |
| 128 | bool EltwiseOps::Run(Node* node) |
| 129 | { |
| 130 | Eltwise* elt_op = dynamic_cast<Eltwise*>(node->GetOp()); |
| 131 | EltwiseParam* param = elt_op->GetParam(); |
| 132 | Tensor* input_tensor0 = node->GetInputTensor(0); |
| 133 | const TShape& ishape = input_tensor0->GetShape(); |
| 134 | void* input0 = get_tensor_mem(input_tensor0); |
| 135 | Tensor* input_tensor1 = nullptr; |
| 136 | void* input1 = nullptr; |
| 137 | // this version only support for input_num=2 |
| 138 | // int input_number=node->GetInputNum(); |
| 139 | |
| 140 | // output |
| 141 | Tensor* output_tensor = node->GetOutputTensor(0); |
| 142 | if(input_tensor0->GetDataType() == TENGINE_DT_INT8 || input_tensor0->GetDataType() == TENGINE_DT_UINT8) |
| 143 | { |
| 144 | if(get_scale_zero(input_tensor0, output_tensor, &op_param) < 0) |
| 145 | return false; |
| 146 | } |
| 147 | |
| 148 | if(node->GetInputNum() > 1) |
| 149 | { |
| 150 | input_tensor1 = node->GetInputTensor(1); |
| 151 | const TShape& ishape1 = input_tensor1->GetShape(); |
| 152 | input1 = get_tensor_mem(input_tensor1); |
| 153 | op_param.shape1[0] = ishape1.GetN(); |
| 154 | op_param.shape1[1] = ishape1.GetC(); |
| 155 | op_param.shape1[2] = ishape1.GetH(); |
| 156 | op_param.shape1[3] = ishape1.GetW(); |
| 157 | |
| 158 | if(input_tensor1->GetDataType() == TENGINE_DT_INT8 || input_tensor1->GetDataType() == TENGINE_DT_UINT8) |
| 159 | { |
| 160 | if(get_scale_zero_1(input_tensor1, &op_param) < 0) |
| 161 | return false; |
| 162 | } |
| 163 | } |
| 164 | void* output = get_tensor_mem(output_tensor); |
| 165 | op_param.shape0[0] = ishape.GetN(); |
| 166 | op_param.shape0[1] = ishape.GetC(); |
| 167 | op_param.shape0[2] = ishape.GetH(); |
| 168 | op_param.shape0[3] = ishape.GetW(); |
| 169 | op_param.type = param->type; |
| 170 | op_param.shift = param->shift; |
| 171 | op_param.power = param->power; |
| 172 | op_param.pScale = param->scale; |
| 173 | int ret = kernel_run(input0, input1, output, &op_param); |
| 174 | |
| 175 | if(input_tensor0->GetDataType() == TENGINE_DT_INT8) |
| 176 | { |
| 177 | auto* o_quant = output_tensor->GetQuantParam(); |
| 178 | QuantParam q_param; |
| 179 | q_param.scale = op_param.scale[2]; |
| 180 | o_quant->resize(0); |
| 181 | o_quant->push_back(q_param); |
| 182 | } |
| 183 | |
| 184 | if(ret < 0) |
| 185 | return false; |
nothing calls this directly
no test coverage detected