From e421f0c79eada99fd722cd022a1a8f5a52069439 Mon Sep 17 00:00:00 2001 From: Liangliang He Date: Thu, 15 Mar 2018 13:01:42 +0800 Subject: [PATCH] Fix cpplint warning for core/runtime/opencl --- mace/core/runtime/opencl/opencl_allocator.cc | 4 +- mace/core/runtime/opencl/opencl_allocator.h | 2 + .../core/runtime/opencl/opencl_development.cc | 8 ++- mace/core/runtime/opencl/opencl_extension.h | 6 +- mace/core/runtime/opencl/opencl_production.cc | 8 ++- mace/core/runtime/opencl/opencl_runtime.cc | 57 ++++++++++--------- mace/core/runtime/opencl/opencl_runtime.h | 5 +- mace/core/runtime/opencl/opencl_wrapper.cc | 12 ++-- mace/kernels/opencl/cl/conv_2d.cl | 2 +- 9 files changed, 60 insertions(+), 44 deletions(-) diff --git a/mace/core/runtime/opencl/opencl_allocator.cc b/mace/core/runtime/opencl/opencl_allocator.cc index 891d460d..76bc437d 100644 --- a/mace/core/runtime/opencl/opencl_allocator.cc +++ b/mace/core/runtime/opencl/opencl_allocator.cc @@ -29,7 +29,7 @@ static cl_channel_type DataTypeToCLChannelType(const DataType t) { return 0; } } -} +} // namespace OpenCLAllocator::OpenCLAllocator() {} @@ -93,7 +93,7 @@ void *OpenCLAllocator::Map(void *buffer, size_t offset, size_t nbytes) const { return mapped_ptr; } -// TODO : there is something wrong with half type. +// TODO(liuqi) there is something wrong with half type. void *OpenCLAllocator::MapImage(void *buffer, const std::vector &image_shape, std::vector *mapped_image_pitch) const { diff --git a/mace/core/runtime/opencl/opencl_allocator.h b/mace/core/runtime/opencl/opencl_allocator.h index 7065b132..b8014767 100644 --- a/mace/core/runtime/opencl/opencl_allocator.h +++ b/mace/core/runtime/opencl/opencl_allocator.h @@ -5,6 +5,8 @@ #ifndef MACE_CORE_RUNTIME_OPENCL_OPENCL_ALLOCATOR_H_ #define MACE_CORE_RUNTIME_OPENCL_OPENCL_ALLOCATOR_H_ +#include + #include "mace/core/allocator.h" namespace mace { diff --git a/mace/core/runtime/opencl/opencl_development.cc b/mace/core/runtime/opencl/opencl_development.cc index 71130cf4..036a97ed 100644 --- a/mace/core/runtime/opencl/opencl_development.cc +++ b/mace/core/runtime/opencl/opencl_development.cc @@ -1,3 +1,7 @@ +// +// Copyright (c) 2017 XiaoMi All rights reserved. +// + #include #include #include @@ -12,8 +16,8 @@ namespace mace { bool GetSourceOrBinaryProgram(const std::string &program_name, const std::string &binary_file_name_prefix, - cl::Context &context, - cl::Device &device, + const cl::Context &context, + const cl::Device &device, cl::Program *program, bool *is_binary) { extern const std::map> diff --git a/mace/core/runtime/opencl/opencl_extension.h b/mace/core/runtime/opencl/opencl_extension.h index d2e22d9a..a18f921e 100644 --- a/mace/core/runtime/opencl/opencl_extension.h +++ b/mace/core/runtime/opencl/opencl_extension.h @@ -2,8 +2,8 @@ // Copyright (c) 2017 XiaoMi All rights reserved. // -#ifndef MACE_CORE_RUNTIME_OPENCL_EXTENSION_H_ -#define MACE_CORE_RUNTIME_OPENCL_EXTENSION_H_ +#ifndef MACE_CORE_RUNTIME_OPENCL_OPENCL_EXTENSION_H_ +#define MACE_CORE_RUNTIME_OPENCL_OPENCL_EXTENSION_H_ #include "mace/core/runtime/opencl/cl2_header.h" @@ -25,4 +25,4 @@ typedef cl_uint cl_priority_hint; #define CL_PRIORITY_HINT_NORMAL_QCOM 0x40CB #define CL_PRIORITY_HINT_LOW_QCOM 0x40CC -#endif // MACE_CORE_RUNTIME_OPENCL_EXTENSION_H_ +#endif // MACE_CORE_RUNTIME_OPENCL_OPENCL_EXTENSION_H_ diff --git a/mace/core/runtime/opencl/opencl_production.cc b/mace/core/runtime/opencl/opencl_production.cc index 78aa5bcf..f4df016f 100644 --- a/mace/core/runtime/opencl/opencl_production.cc +++ b/mace/core/runtime/opencl/opencl_production.cc @@ -1,3 +1,7 @@ +// +// Copyright (c) 2017 XiaoMi All rights reserved. +// + #include #include #include @@ -10,8 +14,8 @@ namespace mace { bool GetSourceOrBinaryProgram(const std::string &program_name, const std::string &binary_file_name_prefix, - cl::Context &context, - cl::Device &device, + const cl::Context &context, + const cl::Device &device, cl::Program *program, bool *is_binary) { extern const std::map> diff --git a/mace/core/runtime/opencl/opencl_runtime.cc b/mace/core/runtime/opencl/opencl_runtime.cc index d3c2c2cd..793b53fe 100644 --- a/mace/core/runtime/opencl/opencl_runtime.cc +++ b/mace/core/runtime/opencl/opencl_runtime.cc @@ -2,13 +2,16 @@ // Copyright (c) 2017 XiaoMi All rights reserved. // +#include "mace/core/runtime/opencl/opencl_runtime.h" + #include #include #include -#include +#include // NOLINT(build/c++11) +#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" @@ -78,48 +81,48 @@ OpenCLRuntime *OpenCLRuntime::CreateGlobal(GPUType gpu_type, return opencl_runtime_instance; } -void ParseOpenCLRuntimeConfig(cl_context_properties *properties, +void ParseOpenCLRuntimeConfig(std::vector *properties, GPUType gpu_type, GPUPerfHint gpu_perf_hint, GPUPriorityHint gpu_priority_hint) { - int index = 0; + MACE_CHECK_NOTNULL(properties); if (gpu_type == GPUType::ADRENO) { switch (gpu_perf_hint) { case GPUPerfHint::PERF_LOW: - properties[index++] = CL_CONTEXT_PERF_HINT_QCOM; - properties[index++] = CL_PERF_HINT_LOW_QCOM; + properties->push_back(CL_CONTEXT_PERF_HINT_QCOM); + properties->push_back(CL_PERF_HINT_LOW_QCOM); break; case GPUPerfHint::PERF_NORMAL: - properties[index++] = CL_CONTEXT_PERF_HINT_QCOM; - properties[index++] = CL_PERF_HINT_NORMAL_QCOM; + properties->push_back(CL_CONTEXT_PERF_HINT_QCOM); + properties->push_back(CL_PERF_HINT_NORMAL_QCOM); break; case GPUPerfHint::PERF_HIGH: - properties[index++] = CL_CONTEXT_PERF_HINT_QCOM; - properties[index++] = CL_PERF_HINT_HIGH_QCOM; + properties->push_back(CL_CONTEXT_PERF_HINT_QCOM); + properties->push_back(CL_PERF_HINT_HIGH_QCOM); break; default:break; } switch (gpu_priority_hint) { case GPUPriorityHint::PRIORITY_LOW: - properties[index++] = CL_CONTEXT_PRIORITY_HINT_QCOM; - properties[index++] = CL_PRIORITY_HINT_LOW_QCOM; + properties->push_back(CL_CONTEXT_PRIORITY_HINT_QCOM); + properties->push_back(CL_PRIORITY_HINT_LOW_QCOM); break; case GPUPriorityHint::PRIORITY_NORMAL: - properties[index++] = CL_CONTEXT_PRIORITY_HINT_QCOM; - properties[index++] = CL_PRIORITY_HINT_NORMAL_QCOM; + properties->push_back(CL_CONTEXT_PRIORITY_HINT_QCOM); + properties->push_back(CL_PRIORITY_HINT_NORMAL_QCOM); break; case GPUPriorityHint::PRIORITY_HIGH: - properties[index++] = CL_CONTEXT_PRIORITY_HINT_QCOM; - properties[index++] = CL_PRIORITY_HINT_HIGH_QCOM; + properties->push_back(CL_CONTEXT_PRIORITY_HINT_QCOM); + properties->push_back(CL_PRIORITY_HINT_HIGH_QCOM); break; default:break; } } else { - // TODO: support Mali GPU context properties + LOG(WARNING) << "GPU options are only supported by Adreno GPU"; } // The properties list should be terminated with 0 - properties[index] = 0; + properties->push_back(0); } OpenCLRuntime::OpenCLRuntime(GPUType gpu_type, GPUPerfHint gpu_perf_hint, @@ -165,12 +168,12 @@ OpenCLRuntime::OpenCLRuntime(GPUType gpu_type, GPUPerfHint gpu_perf_hint, properties |= CL_QUEUE_PROFILING_ENABLE; } - std::unique_ptr context_properties( - new cl_context_properties[5]); - ParseOpenCLRuntimeConfig(context_properties.get(), gpu_type, gpu_perf_hint, + std::vector context_properties; + context_properties.reserve(5); + ParseOpenCLRuntimeConfig(&context_properties, gpu_type, gpu_perf_hint, gpu_priority_hint); - cl::Context context({gpu_device}, context_properties.get()); + cl::Context context({gpu_device}, context_properties.data()); cl::CommandQueue command_queue(context, gpu_device, properties); const char *kernel_path = getenv("MACE_KERNEL_PATH"); @@ -198,7 +201,7 @@ cl::CommandQueue &OpenCLRuntime::command_queue() { return *command_queue_; } std::string OpenCLRuntime::GenerateCLBinaryFilenamePrefix( const std::string &filename_msg) { - // TODO This can be long and slow, fix it + // TODO(heliangliang) This can be long and slow, fix it std::string filename_prefix = filename_msg; for (auto it = filename_prefix.begin(); it != filename_prefix.end(); ++it) { if (*it == ' ' || *it == '-' || *it == '=') { @@ -210,8 +213,8 @@ std::string OpenCLRuntime::GenerateCLBinaryFilenamePrefix( extern bool GetSourceOrBinaryProgram(const std::string &program_name, const std::string &binary_file_name_prefix, - cl::Context &context, - cl::Device &device, + const cl::Context &context, + const cl::Device &device, cl::Program *program, bool *is_opencl_binary); @@ -317,13 +320,13 @@ void OpenCLRuntime::GetCallStats(const cl::Event &event, CallStats *stats) { } uint32_t OpenCLRuntime::GetDeviceMaxWorkGroupSize() { - unsigned long long size = 0; + uint64_t size = 0; device_->getInfo(CL_DEVICE_MAX_WORK_GROUP_SIZE, &size); return static_cast(size); } uint32_t OpenCLRuntime::GetKernelMaxWorkGroupSize(const cl::Kernel &kernel) { - unsigned long long size = 0; + uint64_t size = 0; kernel.getWorkGroupInfo(*device_, CL_KERNEL_WORK_GROUP_SIZE, &size); return static_cast(size); } diff --git a/mace/core/runtime/opencl/opencl_runtime.h b/mace/core/runtime/opencl/opencl_runtime.h index e816439d..faa81838 100644 --- a/mace/core/runtime/opencl/opencl_runtime.h +++ b/mace/core/runtime/opencl/opencl_runtime.h @@ -7,8 +7,9 @@ #include #include -#include +#include // NOLINT(build/c++11) #include +#include #include "mace/core/future.h" #include "mace/core/runtime/opencl/cl2_header.h" @@ -20,7 +21,7 @@ namespace mace { class OpenCLProfilingTimer : public Timer { public: explicit OpenCLProfilingTimer(const cl::Event *event) - : event_(event), accumulated_micros_(0) {}; + : event_(event), accumulated_micros_(0) {} void StartTiming() override; void StopTiming() override; void AccumulateTiming() override; diff --git a/mace/core/runtime/opencl/opencl_wrapper.cc b/mace/core/runtime/opencl/opencl_wrapper.cc index 15ebc601..cecde585 100644 --- a/mace/core/runtime/opencl/opencl_wrapper.cc +++ b/mace/core/runtime/opencl/opencl_wrapper.cc @@ -2,12 +2,14 @@ // Copyright (c) 2017 XiaoMi All rights reserved. // -#include "CL/opencl.h" - #include "mace/core/runtime/opencl/opencl_wrapper.h" -#include "mace/utils/logging.h" +#include #include +#include +#include + +#include "mace/utils/logging.h" /** * Wrapper of OpenCL 2.0 (based on 1.2) @@ -51,13 +53,13 @@ class OpenCLLibraryImpl final { const cl_context_properties *, cl_uint, const cl_device_id *, - void(CL_CALLBACK *)(const char *, const void *, size_t, void *), + void (CL_CALLBACK *)(const char *, const void *, size_t, void *), // NOLINT void *, cl_int *); using clCreateContextFromTypeFunc = cl_context (*)( const cl_context_properties *, cl_device_type, - void(CL_CALLBACK *)(const char *, const void *, size_t, void *), + void (CL_CALLBACK *)(const char *, const void *, size_t, void *), // NOLINT void *, cl_int *); using clReleaseContextFunc = cl_int (*)(cl_context); diff --git a/mace/kernels/opencl/cl/conv_2d.cl b/mace/kernels/opencl/cl/conv_2d.cl index 11253d69..8ed3073f 100644 --- a/mace/kernels/opencl/cl/conv_2d.cl +++ b/mace/kernels/opencl/cl/conv_2d.cl @@ -54,7 +54,7 @@ __kernel void conv_2d(__read_only image2d_t input, /* [c%4 * w * c/4, h * b] */ const int in_idx = mul24(in_ch_blk, in_width); int filter_x_part0 = in_ch_blk << 2; for (short hb_idx = 0; hb_idx < filter_height; ++hb_idx) { - // TODO (heliangliang) optimize out these muls + // TODO(heliangliang) optimize out these muls int in_hb_value = height_idx + mul24(hb_idx, dilation_h); in_hb_value = select(in_hb_value + batch_idx, -1, -- GitLab