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

Fix opencl runtime bug.

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