!49070 codegen support multi-model predict: cortex

Merge pull request !49070 from zhangyanhui/mas_zyh0206
This commit is contained in:
i-robot 2023-02-17 14:12:50 +00:00 committed by Gitee
commit b84d81527a
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
1 changed files with 7 additions and 8 deletions

View File

@ -97,7 +97,8 @@ void CodeMSModelCalcWorkspaceSize(std::ofstream &ofs, const std::unique_ptr<Code
for (size_t i = 0; i < outputs.size(); ++i) { for (size_t i = 0; i < outputs.size(); ++i) {
ofs << " shape_size += " << outputs[i]->shape().size() << " * sizeof(int64_t);\n"; ofs << " shape_size += " << outputs[i]->shape().size() << " * sizeof(int64_t);\n";
} }
ofs << " return UP_ROUND(GetBufferSize(),4) + UP_ROUND(WEIGHT_BUF_SIZE,4) + shape_size + " ofs << " return UP_ROUND(GetBufferSize" << ctx->GetCurModelIndex()
<< "(),4) + UP_ROUND(WEIGHT_BUF_SIZE,4) + shape_size + "
<< "(UP_ROUND(sizeof(MicroTensor),4) + UP_ROUND(sizeof(MicroTensor *),4)) * " << "(UP_ROUND(sizeof(MicroTensor),4) + UP_ROUND(sizeof(MicroTensor *),4)) * "
<< (ctx->graph_inputs().size() + ctx->graph_outputs().size()) << ";\n}\n"; << (ctx->graph_inputs().size() + ctx->graph_outputs().size()) << ";\n}\n";
} else { } else {
@ -158,13 +159,11 @@ void CodeMSModelSetWorkspace(std::ofstream &ofs, const std::unique_ptr<CoderCont
<< " buffer_size = UP_ROUND(buffer_size,4);\n"; << " buffer_size = UP_ROUND(buffer_size,4);\n";
} }
ofs << " }\n"; ofs << " }\n";
ofs << R"RAW( ofs << " if (buffer_size > workspace_size) {\n"
if (buffer_size > workspace_size) { << " micro_model->runtime_buffer = NULL;\n"
micro_model->runtime_buffer = NULL; << " SetBuffer" << ctx->GetCurModelIndex() << "(NULL);\n"
SetBuffer(NULL); << " return;\n"
return; << " }\n";
}
)RAW";
auto array_tostring = [&ofs](Tensor *tensor, const std::string &prefix, size_t index) { auto array_tostring = [&ofs](Tensor *tensor, const std::string &prefix, size_t index) {
ofs << kAlignedString << prefix << "_tensors[" << index << "]->type = " << EnumNameMSDataType(tensor->data_type()) ofs << kAlignedString << prefix << "_tensors[" << index << "]->type = " << EnumNameMSDataType(tensor->data_type())
<< ";\n"; << ";\n";