!29283 [MSLITE] fix mem leak and diverse wide deep networks compatibility in tensorrt delegate

Merge pull request !29283 from Liu_Xuu/trt_0118_fullfusion
This commit is contained in:
i-robot 2022-01-20 03:33:34 +00:00 committed by Gitee
commit a929f44664
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
6 changed files with 26 additions and 2 deletions

View File

@ -29,6 +29,13 @@ constexpr size_t kGatherInputsSize = 3;
}
namespace mindspore {
namespace cache {
HostCacheModel::~HostCacheModel() {
if (cache_model_ != nullptr) {
delete cache_model_;
MS_LOG(ERROR) << "delete cache_model_";
cache_model_ = nullptr;
}
}
MSTensor *SchemaTensorToMSTensor(lite::SchemaTensorWrapper *schema_tensor_wrapper,
mindspore::schema::Tensor *schema_tensor) {
std::vector<int64_t> shape;

View File

@ -30,7 +30,8 @@ namespace mindspore {
namespace cache {
class HostCacheModel {
public:
HostCacheModel() {}
HostCacheModel() = default;
~HostCacheModel();
Status LoadCache(const std::string &model_path);
Status LoadCache(DelegateModel<schema::Primitive> *model);
bool CheckIsCacheKernel(kernel::Kernel *kernel);

View File

@ -49,6 +49,12 @@ int MatMulTensorRT::AddInnerOp(nvinfer1::INetworkDefinition *network) {
transpose_b_ = primitive->transpose_b() ? nvinfer1::MatrixOperation::kTRANSPOSE : nvinfer1::MatrixOperation::kNONE;
activation_ = primitive->activation_type();
} else if (type_ == schema::PrimitiveType_FullConnection) {
auto primitive = this->GetPrimitive()->value_as_FullConnection();
if (primitive == nullptr) {
MS_LOG(ERROR) << "convert to primitive FullConnection failed for " << op_name_;
return RET_ERROR;
}
activation_ = primitive->activation_type();
transpose_a_ = nvinfer1::MatrixOperation::kNONE;
transpose_b_ = nvinfer1::MatrixOperation::kTRANSPOSE;
}

View File

@ -36,6 +36,7 @@ nvinfer1::ICudaEngine *TensorRTSerializer::GetSerializedEngine() {
return nullptr;
}
nvinfer1::ICudaEngine *engine = runtime->deserializeCudaEngine(trt_model_stream, size, nullptr);
delete[] trt_model_stream;
runtime->destroy();
return engine;
}

View File

@ -940,6 +940,8 @@ int LiteSession::DelegateInit() {
int LiteSession::Init(InnerContext *context) {
bool expected = false;
if (!is_running_.compare_exchange_strong(expected, true)) {
delete context;
context = nullptr;
MS_LOG(ERROR) << "Not support multi-threading";
return RET_ERROR;
}
@ -1784,6 +1786,7 @@ int lite::LiteSession::LoadModelAndCompileByPath(const std::string &model_path,
(reinterpret_cast<lite::LiteModel *>(model))->set_keep_model_buf(true);
auto ret = CompileGraph(model);
if (ret != lite::RET_OK) {
delete model;
MS_LOG(ERROR) << "Compile model failed";
return RET_ERROR;
}
@ -1808,6 +1811,7 @@ int lite::LiteSession::LoadModelAndCompileByPath(const std::string &model_path,
(reinterpret_cast<lite::LiteModel *>(model))->set_keep_model_buf(true);
auto ret = CompileGraph(model);
if (ret != lite::RET_OK) {
delete model;
MS_LOG(ERROR) << "Compile model failed";
return RET_ERROR;
}

View File

@ -515,7 +515,12 @@ int Scheduler::InitDelegateKernels(std::vector<kernel::LiteKernel *> *dst_kernel
}
auto ret = ReplaceDelegateKernels(&tmp_kernels);
if (ret != RET_OK) {
MS_LOG(ERROR) << "NPU delegate replace delegate kernels failed.";
dst_kernels->insert(dst_kernels->end(), src_kernels.begin(), src_kernels.end());
dst_kernels->insert(dst_kernels->end(), tmp_kernels.begin(), tmp_kernels.end());
if (remain_kernel != nullptr) {
dst_kernels->push_back(remain_kernel);
}
MS_LOG(ERROR) << "Inner delegate replace delegate kernels failed.";
return ret;
}