提交 667ae00a 编写于 作者: Y yejianwu

modify cl::event pointer in opencl_runtime to smart pointer

上级 e8537af6
...@@ -33,7 +33,7 @@ bool ReadSourceFile(const std::string &filename, std::string *content) { ...@@ -33,7 +33,7 @@ bool ReadSourceFile(const std::string &filename, std::string *content) {
} // namespace } // namespace
bool OpenCLRuntime::enable_profiling_ = false; bool OpenCLRuntime::enable_profiling_ = false;
cl::Event* OpenCLRuntime::profiling_ev_ = NULL; std::unique_ptr<cl::Event> OpenCLRuntime::profiling_ev_ = NULL;
OpenCLRuntime *OpenCLRuntime::Get() { OpenCLRuntime *OpenCLRuntime::Get() {
static std::once_flag init_once; static std::once_flag init_once;
...@@ -82,23 +82,25 @@ OpenCLRuntime *OpenCLRuntime::Get() { ...@@ -82,23 +82,25 @@ OpenCLRuntime *OpenCLRuntime::Get() {
// a context is like a "runtime link" to the device and platform; // a context is like a "runtime link" to the device and platform;
// i.e. communication is possible // i.e. communication is possible
cl::Context context({gpu_device}); cl::Context context({gpu_device});
cl::CommandQueue command_queue(context, gpu_device, cl_command_queue_properties properties = 0;
enable_profiling_ ? CL_QUEUE_PROFILING_ENABLE : 0); if (enable_profiling_) {
profiling_ev_.reset(new cl::Event());
properties = CL_QUEUE_PROFILING_ENABLE;
}
cl::CommandQueue command_queue(context, gpu_device, properties);
instance = new OpenCLRuntime(context, gpu_device, command_queue); instance = new OpenCLRuntime(context, gpu_device, command_queue);
}); });
return instance; return instance;
} }
void OpenCLRuntime::EnableProfiling() { void OpenCLRuntime::EnableProfiling() {
if (!enable_profiling_) { enable_profiling_ = true;
enable_profiling_ = true;
profiling_ev_ = new cl::Event();
}
} }
cl::Event* OpenCLRuntime::GetDefaultEvent() { cl::Event* OpenCLRuntime::GetDefaultEvent() {
return profiling_ev_; return profiling_ev_.get();
} }
cl_ulong OpenCLRuntime::GetEventProfilingStartInfo() { cl_ulong OpenCLRuntime::GetEventProfilingStartInfo() {
...@@ -119,10 +121,7 @@ OpenCLRuntime::OpenCLRuntime(cl::Context context, ...@@ -119,10 +121,7 @@ OpenCLRuntime::OpenCLRuntime(cl::Context context,
kernel_path_ = std::string(kernel_path == nullptr ? "" : kernel_path) + "/"; kernel_path_ = std::string(kernel_path == nullptr ? "" : kernel_path) + "/";
} }
OpenCLRuntime::~OpenCLRuntime() { OpenCLRuntime::~OpenCLRuntime() {}
if (profiling_ev_)
delete profiling_ev_;
}
cl::Context &OpenCLRuntime::context() { return context_; } cl::Context &OpenCLRuntime::context() { return context_; }
......
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
#define MACE_CORE_RUNTIME_OPENCL_OPENCL_RUNTIME_H_ #define MACE_CORE_RUNTIME_OPENCL_OPENCL_RUNTIME_H_
#include <map> #include <map>
#include <memory>
#include <mutex> #include <mutex>
#include <set> #include <set>
...@@ -49,7 +50,7 @@ class OpenCLRuntime { ...@@ -49,7 +50,7 @@ class OpenCLRuntime {
private: private:
static bool enable_profiling_; static bool enable_profiling_;
static cl::Event* profiling_ev_; static std::unique_ptr<cl::Event> profiling_ev_;
cl::Context context_; cl::Context context_;
cl::Device device_; cl::Device device_;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册