fix opencl mem leak

pull/6804/head
wandongdong 5 years ago
parent 9c511204a6
commit 595c96afa7

@ -133,11 +133,10 @@ int ActivationOpenClKernel::GetImageSize(size_t idx, std::vector<size_t> *img_si
return RET_OK;
}
kernel::LiteKernel *OpenClActivationFp32KernelCreator(const std::vector<lite::Tensor *> &inputs,
const std::vector<lite::Tensor *> &outputs,
OpParameter *opParameter, const lite::InnerContext *ctx,
const kernel::KernelKey &desc,
const mindspore::lite::PrimitiveC *primitive) {
kernel::LiteKernel *OpenClActivationKernelCreator(const std::vector<lite::Tensor *> &inputs,
const std::vector<lite::Tensor *> &outputs, OpParameter *opParameter,
const lite::InnerContext *ctx, const kernel::KernelKey &desc,
const mindspore::lite::PrimitiveC *primitive) {
if (inputs.empty()) {
MS_LOG(ERROR) << "Input data size must be greater than 0, but your size is " << inputs.size();
return nullptr;
@ -160,5 +159,6 @@ kernel::LiteKernel *OpenClActivationFp32KernelCreator(const std::vector<lite::Te
}
return kernel;
}
REG_KERNEL(kGPU, kNumberTypeFloat32, PrimitiveType_Activation, OpenClActivationFp32KernelCreator)
REG_KERNEL(kGPU, kNumberTypeFloat16, PrimitiveType_Activation, OpenClActivationKernelCreator)
REG_KERNEL(kGPU, kNumberTypeFloat32, PrimitiveType_Activation, OpenClActivationKernelCreator)
} // namespace mindspore::kernel

@ -83,16 +83,16 @@ int OpenCLRuntime::Init() {
MS_LOG(INFO) << "CL_HPP_MINIMUM_OPENCL_VERSION " << CL_HPP_MINIMUM_OPENCL_VERSION;
#ifdef USE_OPENCL_WRAPPER
if (OpenCLWrapper::GetInstance()->LoadOpenCLLibrary() == false) {
if (lite::opencl::LoadOpenCLLibrary(handle_) == false) {
MS_LOG(ERROR) << "Load OpenCL symbols failed!";
return RET_ERROR;
}
#endif // USE_OPENCL_WRAPPER
std::vector<cl::Platform> platforms;
cl::Platform::get(&platforms);
cl_int ret = cl::Platform::get(&platforms);
if (platforms.size() == 0) {
MS_LOG(ERROR) << "OpenCL Platform not found!";
MS_LOG(ERROR) << "OpenCL Platform not found!" << CLErrorCode(ret);
return RET_ERROR;
}
@ -137,7 +137,7 @@ int OpenCLRuntime::Init() {
<< max_work_item_sizes_[2];
gpu_info_ = ParseGpuInfo(device_name, device_version);
cl_int ret;
// cl_int ret;
#if defined(SHARING_MEM_WITH_OPENGL) && (CL_HPP_TARGET_OPENCL_VERSION >= 120)
// create context from glcontext
MS_LOG(INFO) << "Create special opencl context to share with OpenGL";
@ -235,7 +235,8 @@ int OpenCLRuntime::Uninit() {
context_ = nullptr;
device_ = nullptr;
#ifdef USE_OPENCL_WRAPPER
OpenCLWrapper::GetInstance()->UnLoadOpenCLLibrary();
lite::opencl::UnLoadOpenCLLibrary(handle_);
handle_ = nullptr;
#endif
init_done_ = false;
return RET_OK;

@ -166,6 +166,7 @@ class OpenCLRuntime {
cl_device_svm_capabilities svm_capabilities_{0};
cl_uint image_pitch_align_{0};
std::vector<size_t> max_work_item_sizes_;
void *handle_{nullptr};
};
} // namespace mindspore::lite::opencl

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff
Loading…
Cancel
Save