diff --git a/mindspore/lite/tools/converter/micro/coder/generator/component/common_component.cc b/mindspore/lite/tools/converter/micro/coder/generator/component/common_component.cc index ed779fbbe39..c3893e70f39 100644 --- a/mindspore/lite/tools/converter/micro/coder/generator/component/common_component.cc +++ b/mindspore/lite/tools/converter/micro/coder/generator/component/common_component.cc @@ -97,7 +97,8 @@ void CodeMSModelCalcWorkspaceSize(std::ofstream &ofs, const std::unique_ptrGetCurModelIndex() + << "(),4) + UP_ROUND(WEIGHT_BUF_SIZE,4) + shape_size + " << "(UP_ROUND(sizeof(MicroTensor),4) + UP_ROUND(sizeof(MicroTensor *),4)) * " << (ctx->graph_inputs().size() + ctx->graph_outputs().size()) << ";\n}\n"; } else { @@ -158,13 +159,11 @@ void CodeMSModelSetWorkspace(std::ofstream &ofs, const std::unique_ptr workspace_size) { - micro_model->runtime_buffer = NULL; - SetBuffer(NULL); - return; - } -)RAW"; + ofs << " if (buffer_size > workspace_size) {\n" + << " micro_model->runtime_buffer = NULL;\n" + << " SetBuffer" << ctx->GetCurModelIndex() << "(NULL);\n" + << " return;\n" + << " }\n"; auto array_tostring = [&ofs](Tensor *tensor, const std::string &prefix, size_t index) { ofs << kAlignedString << prefix << "_tensors[" << index << "]->type = " << EnumNameMSDataType(tensor->data_type()) << ";\n";