!31931 [lite]fix div-int8 bug

Merge pull request !31931 from 徐安越/master1
This commit is contained in:
i-robot 2022-03-26 11:44:09 +00:00 committed by Gitee
commit ce51331dc4
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
5 changed files with 29 additions and 12 deletions

View File

@ -21,7 +21,7 @@ using mindspore::lite::RET_ERROR;
using mindspore::lite::RET_OK;
namespace mindspore::kernel {
#ifdef SERVER_INFERENCE
#ifdef DYNAMIC_THREAD_DISTRIBUTE
constexpr int kMinCostPerThread = 16384;
#endif
int GatherRun(void *cdata, int task_id, float, float) {
@ -137,7 +137,7 @@ int GatherBaseCPUKernel::ChooseThreadCuttingstrategy() {
return RET_OK;
}
int64_t block_size = 1;
#ifdef SERVER_INFERENCE
#ifdef DYNAMIC_THREAD_DISTRIBUTE
auto all_bytes = static_cast<int64_t>(out_tensors_.front()->Size());
if (all_bytes <= static_cast<int64_t>(kMinCostPerThread)) {
block_boundary_infos_.emplace_back(BlockBoundaryInfo{0, 0, outer_size_, 0});

View File

@ -28,7 +28,7 @@ using mindspore::lite::RET_OK;
using mindspore::schema::PrimitiveType_BiasAdd;
namespace mindspore::kernel {
#ifdef SERVER_INFERENCE
#ifdef DYNAMIC_THREAD_DISTRIBUTE
constexpr int kMinCostPerThread = 1 << 16;
#endif
int BiasAddRun(void *cdata, int task_id, float lhs_scale, float rhs_scale) {
@ -81,7 +81,7 @@ int BiasCPUKernel::ReSize() {
int BiasCPUKernel::ChooseThreadCuttingstrategy() {
split_points_.clear();
int64_t block_size = 1;
#ifdef SERVER_INFERENCE
#ifdef DYNAMIC_THREAD_DISTRIBUTE
block_size = MSMAX(total_num_ / op_parameter_->thread_num_, kMinCostPerThread);
thread_num_ = MSMIN(UP_DIV(total_num_, block_size), op_parameter_->thread_num_);
#else

View File

@ -74,7 +74,7 @@ int MatmulFp32BaseCPUKernel::PackMatrixA() {
reinterpret_cast<float *>(ms_context_->allocator->Malloc(matrix_a_.pack_size * sizeof(float)));
}
} else {
#ifdef SERVER_INFERENCE
#ifdef SHARING_MODEL_WEIGHT
auto a_packed = lite::PackWeightManager::GetInstance()->GetPackedTensor(
in_tensors()[FIRST_INPUT], static_cast<size_t>(matrix_a_.pack_size) * sizeof(float));
matrix_a_.pack_ptr = reinterpret_cast<float *>(a_packed.second);
@ -125,7 +125,7 @@ int MatmulFp32BaseCPUKernel::PackMatrixB() {
reinterpret_cast<float *>(ms_context_->allocator->Malloc(matrix_b_.pack_size * sizeof(float)));
}
} else {
#ifdef SERVER_INFERENCE
#ifdef SHARING_MODEL_WEIGHT
auto b_packed = lite::PackWeightManager::GetInstance()->GetPackedTensor(
in_tensors()[SECOND_INPUT], static_cast<size_t>(matrix_b_.pack_size) * sizeof(float));
matrix_b_.pack_ptr = reinterpret_cast<float *>(b_packed.second);

View File

@ -19,7 +19,7 @@
#include <vector>
#include "src/inner_kernel.h"
#ifdef SERVER_INFERENCE
#ifdef SHARING_MODEL_WEIGHT
#include "src/pack_weight_manager.h"
#endif
#include "nnacl/matmul_parameter.h"

View File

@ -158,11 +158,28 @@ int DivInt8CPUKernel::Run() {
if (broadcast_) {
ArithmeticParameter tile_para;
tile_para.ndim_ = out_tensors_.at(0)->shape().size();
for (size_t i = 0; i < tile_para.ndim_; i++) {
tile_para.in_shape0_[i] = in_tensors_.at(0)->DimensionSize(i);
tile_para.in_shape1_[i] = in_tensors_.at(1)->DimensionSize(i);
tile_para.out_shape_[i] = out_tensors_.at(0)->DimensionSize(i);
auto out_shape = out_tensors_[FIRST_INPUT]->shape();
tile_para.ndim_ = out_shape.size();
auto in_shape0 = in_tensors_[FIRST_INPUT]->shape();
MS_CHECK_TRUE_MSG(out_shape.size() >= in_shape0.size(), RET_ERROR,
"Sub first-input shape size is larger than out.");
for (size_t i = 0; i < out_shape.size() - in_shape0.size(); ++i) {
tile_para.in_shape0_[i] = 1;
}
for (size_t i = 0; i < in_shape0.size(); ++i) {
tile_para.in_shape0_[i + out_shape.size() - in_shape0.size()] = in_shape0[i];
}
auto in_shape1 = in_tensors_[SECOND_INPUT]->shape();
MS_CHECK_TRUE_MSG(out_shape.size() >= in_shape1.size(), RET_ERROR,
"Sub second-input shape size is larger than out.");
for (size_t i = 0; i < out_shape.size() - in_shape1.size(); ++i) {
tile_para.in_shape1_[i] = 1;
}
for (size_t i = 0; i < in_shape1.size(); ++i) {
tile_para.in_shape1_[i + out_shape.size() - in_shape1.size()] = in_shape1[i];
}
for (size_t i = 0; i < out_shape.size(); ++i) {
tile_para.out_shape_[i] = out_shape[i];
}
tile0_data_ = static_cast<int8_t *>(ms_context_->allocator->Malloc(out_tensors_.at(0)->Size()));
tile1_data_ = static_cast<int8_t *>(ms_context_->allocator->Malloc(out_tensors_.at(0)->Size()));