forked from mindspore-Ecosystem/mindspore
!48240 [MS][LITE][parallel predict] pack weight: bug fix , not support grop convolution
Merge pull request !48240 from yefeng/513-fix_grop_convolution_packweight
This commit is contained in:
commit
c63e226f0c
|
@ -50,7 +50,11 @@ ConvolutionBaseCPUKernel::~ConvolutionBaseCPUKernel() {
|
|||
if (addr_map.find(reinterpret_cast<uintptr_t>(packed_weight_)) != addr_map.end()) {
|
||||
FreeAlignedData(reinterpret_cast<void **>(&packed_weight_));
|
||||
} else if (!op_parameter_->is_train_session_) {
|
||||
lite::PackWeightManager::GetInstance()->Free(packed_weight_);
|
||||
if (!is_sharing_pack_) {
|
||||
free(packed_weight_);
|
||||
} else {
|
||||
lite::PackWeightManager::GetInstance()->Free(packed_weight_);
|
||||
}
|
||||
packed_weight_ = nullptr;
|
||||
}
|
||||
if (addr_map.find(reinterpret_cast<uintptr_t>(bias_data_)) != addr_map.end()) {
|
||||
|
|
|
@ -82,6 +82,7 @@ class ConvolutionBaseCPUKernel : public LiteKernel {
|
|||
std::unordered_map<uintptr_t, void *> addr_map;
|
||||
void *packed_weight_ = nullptr;
|
||||
bool weight_is_packed_ = false;
|
||||
bool is_sharing_pack_ = true;
|
||||
void *bias_data_ = nullptr;
|
||||
const InnerContext *ctx_ = nullptr;
|
||||
ConvParameter *conv_param_ = nullptr;
|
||||
|
|
|
@ -33,6 +33,7 @@ class ConvolutionSW1x1CPUKernel : public LiteKernel {
|
|||
float *origin_weight, float *origin_bias)
|
||||
: LiteKernel(parameter, inputs, outputs, ctx), origin_weight_(origin_weight), origin_bias_(origin_bias) {
|
||||
matmul_base_ = CreateMatmulFp32CPUKernel(parameter, inputs, outputs, ctx);
|
||||
matmul_base_->SetSharingPack(false);
|
||||
}
|
||||
~ConvolutionSW1x1CPUKernel() {
|
||||
if (matmul_base_ != nullptr) {
|
||||
|
|
|
@ -260,8 +260,14 @@ int ConvolutionWinogradBaseCPUKernel::MallocWeightBiasData() {
|
|||
if (!op_parameter_->is_train_session_) {
|
||||
if (packed_weight_ == nullptr) {
|
||||
CHECK_LESS_RETURN(MAX_MALLOC_SIZE, trans_matrix_data_size);
|
||||
packed_weight_ = lite::PackWeightManager::GetInstance()->GetPackData(in_tensors_[1]->data(),
|
||||
trans_matrix_data_size, &weight_is_packed_);
|
||||
if (reinterpret_cast<ConvParameter *>(op_parameter_)->group_ > 1) {
|
||||
packed_weight_ = malloc(trans_matrix_data_size);
|
||||
weight_is_packed_ = false;
|
||||
is_sharing_pack_ = false;
|
||||
} else {
|
||||
packed_weight_ = lite::PackWeightManager::GetInstance()->GetPackData(
|
||||
in_tensors_[1]->data(), trans_matrix_data_size, &weight_is_packed_);
|
||||
}
|
||||
if (packed_weight_ == nullptr) {
|
||||
MS_LOG(ERROR) << "malloc matrix_buffer failed.";
|
||||
return RET_MEMORY_FAILED;
|
||||
|
|
|
@ -54,10 +54,18 @@ MatmulFp32BaseCPUKernel::~MatmulFp32BaseCPUKernel() {
|
|||
matrix_c_.pack_ptr = nullptr;
|
||||
}
|
||||
if (params_->a_const_) {
|
||||
lite::PackWeightManager::GetInstance()->Free(matrix_a_.pack_ptr);
|
||||
if (is_sharing_pack_) {
|
||||
lite::PackWeightManager::GetInstance()->Free(matrix_a_.pack_ptr);
|
||||
} else {
|
||||
free(matrix_a_.pack_ptr);
|
||||
}
|
||||
}
|
||||
if (params_->b_const_) {
|
||||
lite::PackWeightManager::GetInstance()->Free(matrix_b_.pack_ptr);
|
||||
if (is_sharing_pack_) {
|
||||
lite::PackWeightManager::GetInstance()->Free(matrix_b_.pack_ptr);
|
||||
} else {
|
||||
free(matrix_b_.pack_ptr);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -172,8 +180,13 @@ int MatmulFp32BaseCPUKernel::PackMatrixA() {
|
|||
}
|
||||
} else {
|
||||
bool is_packed = false;
|
||||
void *data = lite::PackWeightManager::GetInstance()->GetPackData(
|
||||
in_tensors()[FIRST_INPUT]->data(), static_cast<size_t>(matrix_a_.pack_size) * sizeof(float), &is_packed);
|
||||
void *data = nullptr;
|
||||
if (is_sharing_pack_) {
|
||||
data = lite::PackWeightManager::GetInstance()->GetPackData(
|
||||
in_tensors()[FIRST_INPUT]->data(), static_cast<size_t>(matrix_a_.pack_size) * sizeof(float), &is_packed);
|
||||
} else {
|
||||
data = malloc(static_cast<size_t>(matrix_a_.pack_size) * sizeof(float));
|
||||
}
|
||||
matrix_a_.pack_ptr = reinterpret_cast<float *>(data);
|
||||
if (matrix_a_.pack_ptr == nullptr) {
|
||||
MS_LOG(ERROR) << "matrix a pack ptr is nullptr.";
|
||||
|
@ -228,8 +241,13 @@ int MatmulFp32BaseCPUKernel::PackMatrixB() {
|
|||
}
|
||||
} else {
|
||||
bool is_packed = false;
|
||||
void *data = lite::PackWeightManager::GetInstance()->GetPackData(
|
||||
in_tensors()[SECOND_INPUT]->data(), static_cast<size_t>(matrix_b_.pack_size) * sizeof(float), &is_packed);
|
||||
void *data = nullptr;
|
||||
if (is_sharing_pack_) {
|
||||
data = lite::PackWeightManager::GetInstance()->GetPackData(
|
||||
in_tensors()[SECOND_INPUT]->data(), static_cast<size_t>(matrix_b_.pack_size) * sizeof(float), &is_packed);
|
||||
} else {
|
||||
data = malloc(static_cast<size_t>(matrix_b_.pack_size) * sizeof(float));
|
||||
}
|
||||
matrix_b_.pack_ptr = reinterpret_cast<float *>(data);
|
||||
if (matrix_b_.pack_ptr == nullptr) {
|
||||
MS_LOG(ERROR) << "matrix b pack ptr is nullptr.";
|
||||
|
|
|
@ -55,6 +55,7 @@ class MatmulFp32BaseCPUKernel : public LiteKernel {
|
|||
static int InitBroadcastParams(const std::vector<int> &a_shape_const, const std::vector<int> &b_shape_const,
|
||||
MatMulParameter *params, std::vector<int> *a_offsets, std::vector<int> *b_offsets);
|
||||
int PackMatrixBParallelRunByBatch(int task_id) const;
|
||||
inline void SetSharingPack(bool is_sharing) { is_sharing_pack_ = is_sharing; }
|
||||
|
||||
using ParallelRun = int (MatmulFp32BaseCPUKernel::*)(int task_id) const;
|
||||
ParallelRun parallel_fun_ = nullptr;
|
||||
|
@ -138,6 +139,7 @@ class MatmulFp32BaseCPUKernel : public LiteKernel {
|
|||
MatrixPackFun matrix_b_pack_fun_ = nullptr;
|
||||
float *conv1x1_origin_weight_ = nullptr;
|
||||
float *conv1x1_origin_bias_ = nullptr;
|
||||
bool is_sharing_pack_ = true;
|
||||
};
|
||||
} // namespace mindspore::kernel
|
||||
#endif // MINDSPORE_LITE_SRC_RUNTIME_KERNEL_CPU_FP32_MATMUL_FP32_BASE_H_
|
||||
|
|
Loading…
Reference in New Issue