|
|
|
@@ -23,13 +23,13 @@ |
|
|
|
#include "coder/opcoders/serializers/nnacl_serializer/nnacl_int8_serializer.h" |
|
|
|
|
|
|
|
namespace mindspore::lite::micro::nnacl { |
|
|
|
constexpr auto int8_range = 256; |
|
|
|
constexpr auto kInt8Range = 256; |
|
|
|
|
|
|
|
void CalculateTableList(int8_t *table, const float input_scale, const int32_t input_zp) { |
|
|
|
int32_t min_value = std::numeric_limits<int8_t>::min(); |
|
|
|
int32_t max_value = std::numeric_limits<int8_t>::max(); |
|
|
|
const float output_scale = 1.0f / int8_range; |
|
|
|
const int32_t output_zp = -128; |
|
|
|
constexpr int32_t min_value = std::numeric_limits<int8_t>::min(); |
|
|
|
constexpr int32_t max_value = std::numeric_limits<int8_t>::max(); |
|
|
|
constexpr float output_scale = 1.0f / kInt8Range; |
|
|
|
constexpr int32_t output_zp = std::numeric_limits<int8_t>::min(); |
|
|
|
|
|
|
|
for (int i = min_value; i < max_value; ++i) { |
|
|
|
const float real_input_value = input_scale * (i - input_zp); |
|
|
|
@@ -42,15 +42,15 @@ void CalculateTableList(int8_t *table, const float input_scale, const int32_t in |
|
|
|
} |
|
|
|
|
|
|
|
int SigmodInt8Coder::Prepare(CoderContext *const context) { |
|
|
|
table_list_ = static_cast<int8_t *>(allocator_->Malloc(kNumberTypeInt8, int8_range, kOfflinePackWeight)); |
|
|
|
table_list_ = static_cast<int8_t *>(allocator_->Malloc(kNumberTypeInt8, kInt8Range, kOfflinePackWeight)); |
|
|
|
MS_CHECK_PTR(table_list_); |
|
|
|
|
|
|
|
const float input_scale = input_tensor_->quant_params().at(0).scale; |
|
|
|
const int32_t input_zp = input_tensor_->quant_params().at(0).zeroPoint; |
|
|
|
const float output_scale = output_tensor_->quant_params().at(0).scale; |
|
|
|
const int32_t output_zp = output_tensor_->quant_params().at(0).zeroPoint; |
|
|
|
if (output_scale != (1.0f / int8_range) || output_zp != -128) { |
|
|
|
MS_LOG(ERROR) << "Output scale is : " << output_scale << ", should be 1/int8_range. Output zp is : " << output_zp |
|
|
|
if (output_scale != (1.0f / kInt8Range) || output_zp != static_cast<int32_t>(std::numeric_limits<int8_t>::min())) { |
|
|
|
MS_LOG(ERROR) << "Output scale is : " << output_scale << ", should be 1/kInt8Range. Output zp is : " << output_zp |
|
|
|
<< ", should be -128."; |
|
|
|
return RET_ERROR; |
|
|
|
} |
|
|
|
|