未验证 提交 b0b60f4f 编写于 作者: Y Yuan Shuai 提交者: GitHub

[LITE][OPENCL] Fix OpenCL API/Backend misc. test=develop (#3376)

1. clean code;
2. change `cl::Kernel` from unique to shared ptr;
3. `reset` `cl::Program` and `clear` `device_info_` in destroyed of CLRuntime;
4. remove clFlush in destroyed of CLRuntime.
上级 58a0d6ab
......@@ -141,9 +141,6 @@ void LightPredictor::BuildRuntimeProgram(const cpp::ProgramDesc& prog) {
// 2. Create Instructs
#ifdef LITE_WITH_OPENCL
using WaitListType =
std::unordered_map<decltype(static_cast<const void*>(nullptr)),
std::shared_ptr<cl::Event>>;
using OpenCLContext = Context<TargetType::kOpenCL>;
std::unique_ptr<KernelContext> local_ctx(new KernelContext());
local_ctx->As<OpenCLContext>().InitOnce();
......
......@@ -58,7 +58,7 @@ void CLContext::AddKernel(const std::string &kernel_name,
auto program = GetProgram(file_name, options);
VLOG(3) << " --- end get program --- ";
VLOG(3) << " --- to create kernel: " << kernel_name << " --- ";
std::unique_ptr<cl::Kernel> kernel(
std::shared_ptr<cl::Kernel> kernel(
new cl::Kernel(program, kernel_name.c_str(), &status));
CL_CHECK_FATAL(status);
VLOG(3) << " --- end create kernel --- ";
......
......@@ -36,6 +36,7 @@ class CLContext {
kernel_offset_.clear();
for (auto &p : programs_) {
clReleaseProgram(p.second->get());
p.second.reset();
}
programs_.clear();
LOG(INFO) << "release cl::Program, cl::Kernel finished.";
......@@ -66,9 +67,10 @@ class CLContext {
int divitor = 2);
// cl::NDRange LocalWorkSizeConv1x1(cl::NDRange global_work_size,
// size_t max_work_size);
private:
std::unordered_map<std::string, std::unique_ptr<cl::Program>> programs_;
std::vector<std::unique_ptr<cl::Kernel>> kernels_;
std::vector<std::shared_ptr<cl::Kernel>> kernels_;
std::map<std::string, int> kernel_offset_;
};
......
......@@ -29,12 +29,12 @@ CLRuntime::~CLRuntime() {
command_queue_->flush();
command_queue_->finish();
}
// For controlling the destruction order:
// For controlling the destruction order
command_queue_.reset();
context_.reset();
device_.reset();
platform_.reset();
LOG(INFO) << "release ~CLRuntime() ";
device_info_.clear();
}
bool CLRuntime::Init() {
......
......@@ -115,7 +115,6 @@ class IoCopykOpenCLToHostCompute
auto& event = *(it->second);
event.wait();
auto command_queue = CLRuntime::Global()->command_queue();
command_queue.flush();
command_queue.finish();
} else {
LOG(FATAL) << "Could not find the sync event for the target cl tensor.";
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册