diff --git a/lite/kernels/mlu/bridges/conv_op.cc b/lite/kernels/mlu/bridges/conv_op.cc index 1d0eedede62d0df424d8cdce705e62ec1c92029b..b061365018f2b06c88c18a26431598fd77c0e6f7 100644 --- a/lite/kernels/mlu/bridges/conv_op.cc +++ b/lite/kernels/mlu/bridges/conv_op.cc @@ -249,6 +249,10 @@ int ConvConverter(void* ctx, OpLite* op, KernelBase* kernel) { CNML_CALL(cnmlDestroyConvOpParam(&conv_param)); } else { cnmlConvOpParam_t conv_param; + VLOG(5) << "conv param (" << input_var_name << ")" + << "stride: " << strides[0] << ',' << strides[1] << '\t' + << "dilations: " << dilations[0] << ',' << dilations[1] << '\t' + << "paddings: " << paddings[0] << ',' << paddings[2] << std::endl; CNML_CALL(cnmlCreateConvOpParam(&conv_param, strides[0], strides[1], @@ -272,7 +276,7 @@ int ConvConverter(void* ctx, OpLite* op, KernelBase* kernel) { graph->SetComputingDataType( conv_op, filter_tensor->mlu_tensor(), - 1 / *min_element(weight_scale.begin(), weight_scale.end())); + 1 / *max_element(weight_scale.begin(), weight_scale.end())); } CNML_CALL(cnmlSetOperationComputingLayout(conv_op, CNML_NHWC)); if (HasInputArg(op_info, scope, "Bias")) { diff --git a/lite/kernels/mlu/bridges/fc_op.cc b/lite/kernels/mlu/bridges/fc_op.cc index bb0af27d4d59602dd587167ed8f0c8c43dcfb86f..17eded9a75a90e3da0370493c005a13ff7717278 100644 --- a/lite/kernels/mlu/bridges/fc_op.cc +++ b/lite/kernels/mlu/bridges/fc_op.cc @@ -157,7 +157,7 @@ int FCConverter(void* ctx, OpLite* op, KernelBase* kernel) { graph->SetComputingDataType( fc_op, w_tensor->mlu_tensor(), - 1 / *min_element(weight_scale.begin(), weight_scale.end())); + 1 / *max_element(weight_scale.begin(), weight_scale.end())); graph->FuseOp(fc_op); CNML_CALL(cnmlDestroyBaseOp(&fc_op)); diff --git a/lite/kernels/mlu/bridges/graph.h b/lite/kernels/mlu/bridges/graph.h index c4fb10bdb581b97d42e16ec6c9cce38465a84f93..8bf4f4e5d1e92adcaab7af4466e0aed3ec8d42ec 100644 --- a/lite/kernels/mlu/bridges/graph.h +++ b/lite/kernels/mlu/bridges/graph.h @@ -215,8 +215,11 @@ class Graph { float scale, cnmlDataType_t data_type = CNML_DATA_INT8) { cnmlQuantizedParam_t quant_param; - CNML_CALL( - cnmlCreateQuantizedParam(&quant_param, scale2position(scale), 1, 0.0)); + int pos = scale2position(scale); + auto cnml_scale = pow(2, pos) * scale; + VLOG(5) << "[cnml quantized param] pos: " << pos + << "\tscale: " << cnml_scale << std::endl; + CNML_CALL(cnmlCreateQuantizedParam(&quant_param, pos, cnml_scale, 0.0)); CNML_CALL( cnmlSetOperationComputingDataType(op, tensor, data_type, quant_param)); CNML_CALL(cnmlDestroyQuantizedParam(&quant_param)); diff --git a/lite/kernels/mlu/bridges/utility.cc b/lite/kernels/mlu/bridges/utility.cc index a8a19ec94ad04fac8d3c57b6b444cfbf455ca22a..9c8bc91f39c5f43fbc526bdb397c4b0f8f5089c7 100644 --- a/lite/kernels/mlu/bridges/utility.cc +++ b/lite/kernels/mlu/bridges/utility.cc @@ -60,8 +60,6 @@ void transpose(float* input_data, } } -int scale2position(float scale) { return static_cast(-std::log2(scale)); } - void dequant(float* dst, int8_t* src, size_t size, float scale) { for (size_t i = 0; i < size; ++i) { dst[i] = static_cast(src[i]) * scale; diff --git a/lite/kernels/mlu/bridges/utility.h b/lite/kernels/mlu/bridges/utility.h index cc28ea892e8235f2227de832dc317a63e8d0ba44..20671221dc7294fa07a31af6e183539f49397305 100644 --- a/lite/kernels/mlu/bridges/utility.h +++ b/lite/kernels/mlu/bridges/utility.h @@ -36,7 +36,9 @@ void transpose(float* input_data, float* output_data, std::vector input_shape, std::vector axis); -int scale2position(float scale); + +inline int scale2position(float scale) { return std::floor(-std::log2(scale)); } + void dequant(float* dst, int8_t* src, size_t size, float scale); void dequant(float* dst,