Browse Source

!10478 [MS][LITE][GPU]fix memory leak bug

From: @chenzupeng
Reviewed-by: @zhanghaibo5,@ddwsky
Signed-off-by: @ddwsky
tags/v1.2.0-rc1
mindspore-ci-bot Gitee 5 years ago
parent
commit
b072dc83ed
4 changed files with 11 additions and 7 deletions
  1. +1
    -1
      build.sh
  2. +1
    -1
      mindspore/lite/src/lite_session.cc
  3. +1
    -1
      mindspore/lite/src/lite_session.h
  4. +8
    -4
      mindspore/lite/src/runtime/opencl/opencl_runtime.cc

+ 1
- 1
build.sh View File

@@ -503,7 +503,7 @@ build_lite()


LITE_ENABLE_GPU=${ENABLE_GPU} LITE_ENABLE_GPU=${ENABLE_GPU}
LITE_ENABLE_NPU=${ENABLE_NPU} LITE_ENABLE_NPU=${ENABLE_NPU}
if [ "${DEVICE}" == "" ] && [ "${LITE_PLATFORM}" == "arm64" ]; then
if [[ "${DEVICE}" == "" && "${LITE_PLATFORM}" == "arm64" ]]; then
LITE_ENABLE_GPU="on" LITE_ENABLE_GPU="on"
LITE_ENABLE_NPU="on" LITE_ENABLE_NPU="on"
fi fi


+ 1
- 1
mindspore/lite/src/lite_session.cc View File

@@ -670,7 +670,7 @@ int LiteSession::Resize(const std::vector<mindspore::tensor::MSTensor *> &inputs
} }


int LiteSession::InitGPURuntime() { int LiteSession::InitGPURuntime() {
#if SUPPORT_GPU
#if SUPPORT_GPU && !SUPPORT_TRAIN
if (this->context_->IsGpuEnabled()) { if (this->context_->IsGpuEnabled()) {
auto gpu_device_info = this->context_->GetGpuInfo(); auto gpu_device_info = this->context_->GetGpuInfo();
auto opencl_runtime = ocl_runtime_wrap_.GetInstance(); auto opencl_runtime = ocl_runtime_wrap_.GetInstance();


+ 1
- 1
mindspore/lite/src/lite_session.h View File

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


+ 8
- 4
mindspore/lite/src/runtime/opencl/opencl_runtime.cc View File

@@ -234,8 +234,7 @@ int OpenCLRuntime::Init() {
MS_LOG(INFO) << "Compute Unit: " << compute_units_; MS_LOG(INFO) << "Compute Unit: " << compute_units_;
MS_LOG(INFO) << "Clock Frequency: " << max_freq_ << " MHz"; 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) { if (ret != CL_SUCCESS) {
delete device_; delete device_;
delete context_; delete context_;
@@ -243,8 +242,7 @@ int OpenCLRuntime::Init() {
return RET_ERROR; 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) { if (ret != CL_SUCCESS) {
delete device_; delete device_;
delete context_; delete context_;
@@ -258,6 +256,7 @@ int OpenCLRuntime::Init() {
delete device_; delete device_;
delete context_; delete context_;
delete default_command_queue_; delete default_command_queue_;
delete profiling_command_queue_;
MS_LOG(ERROR) << "Command OpenCL allocator failed!"; MS_LOG(ERROR) << "Command OpenCL allocator failed!";
return RET_ERROR; return RET_ERROR;
} }
@@ -275,6 +274,9 @@ int OpenCLRuntime::Init() {
} }


int OpenCLRuntime::Uninit() { int OpenCLRuntime::Uninit() {
if (!init_done_) {
return RET_OK;
}
if (enable_cache_ && !binary_map_.empty()) { if (enable_cache_ && !binary_map_.empty()) {
StoreCache(); StoreCache();
} }
@@ -282,10 +284,12 @@ int OpenCLRuntime::Uninit() {
program_map_.clear(); program_map_.clear();
delete allocator_; delete allocator_;
delete default_command_queue_; delete default_command_queue_;
delete profiling_command_queue_;
delete context_; delete context_;
delete device_; delete device_;
allocator_ = nullptr; allocator_ = nullptr;
default_command_queue_ = nullptr; default_command_queue_ = nullptr;
profiling_command_queue_ = nullptr;
context_ = nullptr; context_ = nullptr;
device_ = nullptr; device_ = nullptr;
#ifdef USE_OPENCL_WRAPPER #ifdef USE_OPENCL_WRAPPER


Loading…
Cancel
Save