!7359 fix quant dtype cast fp16 issue and free opParamter in creator
Merge pull request !7359 from zhaozhenlong/lite/issue/quant_dtype_cast_fp16_supportpull/7359/MERGE
commit
8528839e37
@ -0,0 +1,48 @@
|
||||
/**
|
||||
* Copyright 2020 Huawei Technologies Co., Ltd
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include <math.h>
|
||||
#include "nnacl/fp16/quant_dtype_cast_fp16.h"
|
||||
#include "nnacl/errorcode.h"
|
||||
|
||||
int DoDequantizeInt8ToFp16(int8_t *quant_values, float16_t *real_values, float scale, int32_t zp, int size) {
|
||||
if (quant_values == NULL || real_values == NULL) {
|
||||
return NNACL_PARAM_INVALID;
|
||||
}
|
||||
|
||||
for (int i = 0; i < size; ++i) {
|
||||
real_values[i] = (quant_values[i] - zp) * scale;
|
||||
}
|
||||
return NNACL_OK;
|
||||
}
|
||||
|
||||
int DoQuantizeToInt8FromFp16(float16_t *real_values, int8_t *quant_values, float scale, int32_t zp, int size) {
|
||||
if (quant_values == NULL || real_values == NULL) {
|
||||
return NNACL_PARAM_INVALID;
|
||||
}
|
||||
|
||||
for (int i = 0; i < size; ++i) {
|
||||
float temp = round((float)real_values[i] / scale + zp);
|
||||
if (temp > 127) {
|
||||
quant_values[i] = 127;
|
||||
} else if (temp < -128) {
|
||||
quant_values[i] = -128;
|
||||
} else {
|
||||
quant_values[i] = (int8_t)temp;
|
||||
}
|
||||
}
|
||||
return NNACL_OK;
|
||||
}
|
@ -0,0 +1,35 @@
|
||||
/**
|
||||
* Copyright 2020 Huawei Technologies Co., Ltd
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef MINDSPORE_LITE_NNACL_FP16_QUANTDTYPECAST_FP16_H_
|
||||
#define MINDSPORE_LITE_NNACL_FP16_QUANTDTYPECAST_FP16_H_
|
||||
|
||||
#include "nnacl/op_base.h"
|
||||
|
||||
#ifdef ENABLE_NEON
|
||||
#include <arm_neon.h>
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
int DoDequantizeInt8ToFp16(int8_t *quant_values, float16_t *real_values, float scale, int32_t zp, int size);
|
||||
int DoQuantizeToInt8FromFp16(float16_t *real_values, int8_t *quant_values, float scale, int32_t zp, int size);
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // MINDSPORE_LITE_NNACL_INT8_QUANTDTYPECAST_H_
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue