提交 4557aa1b 编写于 作者: L liuqi

Fix opencl runtime bug.

上级 595003f9
...@@ -355,7 +355,7 @@ void ConfigOpenCLRuntime(GPUPerfHint gpu_perf_hint, ...@@ -355,7 +355,7 @@ void ConfigOpenCLRuntime(GPUPerfHint gpu_perf_hint,
GPUPriorityHint gpu_priority_hint) { GPUPriorityHint gpu_priority_hint) {
VLOG(1) << "Set GPU configurations, gpu_perf_hint: " << gpu_perf_hint VLOG(1) << "Set GPU configurations, gpu_perf_hint: " << gpu_perf_hint
<< ", gpu_priority_hint: " << gpu_priority_hint; << ", gpu_priority_hint: " << gpu_priority_hint;
OpenCLRuntime::CreateGlobal(gpu_perf_hint, gpu_priority_hint); OpenCLRuntime::Configure(gpu_perf_hint, gpu_priority_hint);
} }
void ConfigOmpThreadsAndAffinity(int omp_num_threads, void ConfigOmpThreadsAndAffinity(int omp_num_threads,
......
...@@ -65,23 +65,19 @@ void OpenCLProfilingTimer::ClearTiming() { ...@@ -65,23 +65,19 @@ void OpenCLProfilingTimer::ClearTiming() {
accumulated_micros_ = 0; accumulated_micros_ = 0;
} }
std::unique_ptr<OpenCLRuntime> OpenCLRuntime::runtime_instance_ = nullptr; GPUPerfHint OpenCLRuntime::gpu_perf_hint_ = GPUPerfHint::PERF_DEFAULT;
GPUPriorityHint OpenCLRuntime::gpu_priority_hint_ =
GPUPriorityHint::PRIORITY_DEFAULT;
OpenCLRuntime *OpenCLRuntime::Global() { OpenCLRuntime *OpenCLRuntime::Global() {
// FIXME: not thread safe static OpenCLRuntime runtime(gpu_perf_hint_, gpu_priority_hint_);
if (runtime_instance_ == nullptr) { return &runtime;
return CreateGlobal(GPUPerfHint::PERF_DEFAULT,
GPUPriorityHint::PRIORITY_DEFAULT);
}
return runtime_instance_.get();
} }
OpenCLRuntime *OpenCLRuntime::CreateGlobal(GPUPerfHint gpu_perf_hint, void OpenCLRuntime::Configure(GPUPerfHint gpu_perf_hint,
GPUPriorityHint gpu_priority_hint) { GPUPriorityHint gpu_priority_hint) {
runtime_instance_ = OpenCLRuntime::gpu_perf_hint_ = gpu_perf_hint;
std::unique_ptr<OpenCLRuntime>(new OpenCLRuntime(gpu_perf_hint, OpenCLRuntime::gpu_priority_hint_ = gpu_priority_hint;
gpu_priority_hint));
return runtime_instance_.get();
} }
void GetAdrenoContextProperties(std::vector<cl_context_properties> *properties, void GetAdrenoContextProperties(std::vector<cl_context_properties> *properties,
......
...@@ -39,7 +39,7 @@ class OpenCLProfilingTimer : public Timer { ...@@ -39,7 +39,7 @@ class OpenCLProfilingTimer : public Timer {
class OpenCLRuntime { class OpenCLRuntime {
public: public:
static OpenCLRuntime *Global(); static OpenCLRuntime *Global();
static OpenCLRuntime *CreateGlobal(GPUPerfHint, GPUPriorityHint); static void Configure(GPUPerfHint, GPUPriorityHint);
cl::Context &context(); cl::Context &context();
cl::Device &device(); cl::Device &device();
...@@ -52,10 +52,10 @@ class OpenCLRuntime { ...@@ -52,10 +52,10 @@ class OpenCLRuntime {
cl::Kernel BuildKernel(const std::string &program_name, cl::Kernel BuildKernel(const std::string &program_name,
const std::string &kernel_name, const std::string &kernel_name,
const std::set<std::string> &build_options); const std::set<std::string> &build_options);
~OpenCLRuntime();
private: private:
OpenCLRuntime(GPUPerfHint, GPUPriorityHint); OpenCLRuntime(GPUPerfHint, GPUPriorityHint);
~OpenCLRuntime();
OpenCLRuntime(const OpenCLRuntime &) = delete; OpenCLRuntime(const OpenCLRuntime &) = delete;
OpenCLRuntime &operator=(const OpenCLRuntime &) = delete; OpenCLRuntime &operator=(const OpenCLRuntime &) = delete;
...@@ -74,7 +74,9 @@ class OpenCLRuntime { ...@@ -74,7 +74,9 @@ class OpenCLRuntime {
std::map<std::string, cl::Program> built_program_map_; std::map<std::string, cl::Program> built_program_map_;
std::mutex program_build_mutex_; std::mutex program_build_mutex_;
std::string kernel_path_; std::string kernel_path_;
static std::unique_ptr<OpenCLRuntime> runtime_instance_;
static GPUPerfHint gpu_perf_hint_;
static GPUPriorityHint gpu_priority_hint_;
}; };
} // namespace mace } // namespace mace
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册