fix memory leak bug

This commit is contained in:
chenzupeng 2020-12-25 16:24:39 +08:00
parent 8f2b70261a
commit 660d2d1e97
4 changed files with 11 additions and 7 deletions

View File

@ -503,7 +503,7 @@ build_lite()
LITE_ENABLE_GPU=${ENABLE_GPU}
LITE_ENABLE_NPU=${ENABLE_NPU}
if [ "${DEVICE}" == "" ] && [ "${LITE_PLATFORM}" == "arm64" ]; then
if [[ "${DEVICE}" == "" && "${LITE_PLATFORM}" == "arm64" ]]; then
LITE_ENABLE_GPU="on"
LITE_ENABLE_NPU="on"
fi

View File

@ -670,7 +670,7 @@ int LiteSession::Resize(const std::vector<mindspore::tensor::MSTensor *> &inputs
}
int LiteSession::InitGPURuntime() {
#if SUPPORT_GPU
#if SUPPORT_GPU && !SUPPORT_TRAIN
if (this->context_->IsGpuEnabled()) {
auto gpu_device_info = this->context_->GetGpuInfo();
auto opencl_runtime = ocl_runtime_wrap_.GetInstance();

View File

@ -124,7 +124,7 @@ class LiteSession : public session::LiteSession {
std::unordered_map<std::string, mindspore::tensor::MSTensor *> output_tensor_map_;
Executor *executor_ = nullptr;
std::atomic<bool> is_running_ = false;
#if SUPPORT_GPU
#if SUPPORT_GPU && !SUPPORT_TRAIN
opencl::OpenCLRuntimeWrapper ocl_runtime_wrap_;
#endif
};

View File

@ -234,8 +234,7 @@ int OpenCLRuntime::Init() {
MS_LOG(INFO) << "Compute Unit: " << compute_units_;
MS_LOG(INFO) << "Clock Frequency: " << max_freq_ << " MHz";
const cl_command_queue_properties properties = 0;
default_command_queue_ = new (std::nothrow) cl::CommandQueue(*context_, *device_, properties, &ret);
default_command_queue_ = new (std::nothrow) cl::CommandQueue(*context_, *device_, 0, &ret);
if (ret != CL_SUCCESS) {
delete device_;
delete context_;
@ -243,8 +242,7 @@ int OpenCLRuntime::Init() {
return RET_ERROR;
}
const cl_command_queue_properties profiling_properties = CL_QUEUE_PROFILING_ENABLE;
profiling_command_queue_ = new (std::nothrow) cl::CommandQueue(*context_, *device_, profiling_properties, &ret);
profiling_command_queue_ = new (std::nothrow) cl::CommandQueue(*context_, *device_, CL_QUEUE_PROFILING_ENABLE, &ret);
if (ret != CL_SUCCESS) {
delete device_;
delete context_;
@ -258,6 +256,7 @@ int OpenCLRuntime::Init() {
delete device_;
delete context_;
delete default_command_queue_;
delete profiling_command_queue_;
MS_LOG(ERROR) << "Command OpenCL allocator failed!";
return RET_ERROR;
}
@ -275,6 +274,9 @@ int OpenCLRuntime::Init() {
}
int OpenCLRuntime::Uninit() {
if (!init_done_) {
return RET_OK;
}
if (enable_cache_ && !binary_map_.empty()) {
StoreCache();
}
@ -282,10 +284,12 @@ int OpenCLRuntime::Uninit() {
program_map_.clear();
delete allocator_;
delete default_command_queue_;
delete profiling_command_queue_;
delete context_;
delete device_;
allocator_ = nullptr;
default_command_queue_ = nullptr;
profiling_command_queue_ = nullptr;
context_ = nullptr;
device_ = nullptr;
#ifdef USE_OPENCL_WRAPPER