From 776748e3be66f635f7c610840b6a5627e63ae468 Mon Sep 17 00:00:00 2001 From: Liangliang He Date: Thu, 8 Mar 2018 11:03:01 +0800 Subject: [PATCH] Add Adreno performance hints --- mace/core/runtime/opencl/opencl_extension.h | 28 +++++++++++++++++++++ mace/core/runtime/opencl/opencl_runtime.cc | 13 +++++++--- 2 files changed, 38 insertions(+), 3 deletions(-) create mode 100644 mace/core/runtime/opencl/opencl_extension.h diff --git a/mace/core/runtime/opencl/opencl_extension.h b/mace/core/runtime/opencl/opencl_extension.h new file mode 100644 index 00000000..d2e22d9a --- /dev/null +++ b/mace/core/runtime/opencl/opencl_extension.h @@ -0,0 +1,28 @@ +// +// Copyright (c) 2017 XiaoMi All rights reserved. +// + +#ifndef MACE_CORE_RUNTIME_OPENCL_EXTENSION_H_ +#define MACE_CORE_RUNTIME_OPENCL_EXTENSION_H_ + +#include "mace/core/runtime/opencl/cl2_header.h" + +// Adreno extensions +// Adreno performance hints +typedef cl_uint cl_perf_hint; + +#define CL_CONTEXT_PERF_HINT_QCOM 0x40C2 +#define CL_PERF_HINT_HIGH_QCOM 0x40C3 +#define CL_PERF_HINT_NORMAL_QCOM 0x40C4 +#define CL_PERF_HINT_LOW_QCOM 0x40C5 + +// Adreno priority hints +typedef cl_uint cl_priority_hint; + +#define CL_PRIORITY_HINT_NONE_QCOM 0 +#define CL_CONTEXT_PRIORITY_HINT_QCOM 0x40C9 +#define CL_PRIORITY_HINT_HIGH_QCOM 0x40CA +#define CL_PRIORITY_HINT_NORMAL_QCOM 0x40CB +#define CL_PRIORITY_HINT_LOW_QCOM 0x40CC + +#endif // MACE_CORE_RUNTIME_OPENCL_EXTENSION_H_ diff --git a/mace/core/runtime/opencl/opencl_runtime.cc b/mace/core/runtime/opencl/opencl_runtime.cc index 4a18f630..ec297881 100644 --- a/mace/core/runtime/opencl/opencl_runtime.cc +++ b/mace/core/runtime/opencl/opencl_runtime.cc @@ -7,6 +7,7 @@ #include #include +#include "mace/core/runtime/opencl/opencl_extension.h" #include "mace/core/runtime/opencl/opencl_runtime.h" #include "mace/public/mace.h" #include "mace/utils/tuner.h" @@ -108,9 +109,15 @@ OpenCLRuntime::OpenCLRuntime() { properties |= CL_QUEUE_PROFILING_ENABLE; } - // a context is like a "runtime link" to the device and platform; - // i.e. communication is possible - cl::Context context({gpu_device}); + // TODO (heliangliang) Make this configurable (e.g.HIGH for benchmark, + // disabled for Mali) + cl_context_properties context_properties[] = { + // Set context perf hint to normal + CL_CONTEXT_PERF_HINT_QCOM, CL_PERF_HINT_NORMAL_QCOM, + // Set context priority hint to low + CL_CONTEXT_PRIORITY_HINT_QCOM, CL_PRIORITY_HINT_LOW_QCOM, 0}; + + cl::Context context({gpu_device}, context_properties); cl::CommandQueue command_queue(context, gpu_device, properties); const char *kernel_path = getenv("MACE_KERNEL_PATH"); -- GitLab