From 315d77e08d6e19056894b91ef5719de21bfaccea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E5=AF=85?= Date: Thu, 15 Mar 2018 18:51:37 +0800 Subject: [PATCH] Fix cpplint for mace core --- mace/core/allocator.h | 5 ++- mace/core/arg_helper.cc | 3 ++ mace/core/arg_helper.h | 2 + mace/core/buffer.h | 30 +++++++------ mace/core/mace.cc | 4 +- mace/core/net.cc | 2 + mace/core/net.h | 4 ++ mace/core/operator.cc | 3 ++ mace/core/operator.h | 9 +++- mace/core/preallocated_pooled_allocator.h | 3 ++ mace/core/registry.h | 2 +- mace/core/runtime/cpu/cpu_runtime.cc | 32 ++++++------- mace/core/runtime/cpu/cpu_runtime.h | 6 +-- .../hexagon/hexagon_control_wrapper.cc | 9 ++-- .../runtime/hexagon/hexagon_control_wrapper.h | 4 +- .../core/runtime/hexagon/hexagon_controller.h | 11 +++-- mace/core/runtime/hexagon/hexagon_nn.h | 45 ++++++++++++++++--- mace/core/runtime/hexagon/hexagon_nn_ops.h | 12 ++--- mace/core/runtime/hexagon/ops.h | 37 +++++++++++++++ mace/core/runtime/hexagon/quantize.cc | 5 ++- mace/core/runtime/hexagon/quantize.h | 8 ++-- mace/core/tensor.h | 14 +++--- mace/core/testing/test_benchmark.cc | 2 +- mace/core/testing/test_benchmark_main.cc | 1 - mace/core/types.h | 1 + mace/core/workspace.cc | 25 ++++++----- mace/core/workspace.h | 5 +++ 27 files changed, 205 insertions(+), 79 deletions(-) diff --git a/mace/core/allocator.h b/mace/core/allocator.h index eebbb32b..a9f76fca 100644 --- a/mace/core/allocator.h +++ b/mace/core/allocator.h @@ -7,6 +7,9 @@ #define MACE_CORE_ALLOCATOR_H_ #include +#include +#include +#include #include "mace/core/registry.h" #include "mace/core/types.h" @@ -81,7 +84,7 @@ class CPUAllocator : public Allocator { free(data); }; void *Map(void *buffer, size_t offset, size_t nbytes) const override { - return (char *)buffer + offset; + return reinterpret_cast(buffer) + offset; } void *MapImage(void *buffer, const std::vector &image_shape, diff --git a/mace/core/arg_helper.cc b/mace/core/arg_helper.cc index 8b6d57fb..207d2de9 100644 --- a/mace/core/arg_helper.cc +++ b/mace/core/arg_helper.cc @@ -2,6 +2,9 @@ // Copyright (c) 2017 XiaoMi All rights reserved. // +#include +#include + #include "mace/core/arg_helper.h" #include "mace/utils/logging.h" diff --git a/mace/core/arg_helper.h b/mace/core/arg_helper.h index 25137804..ab8e14b9 100644 --- a/mace/core/arg_helper.h +++ b/mace/core/arg_helper.h @@ -5,6 +5,8 @@ #ifndef MACE_CORE_ARG_HELPER_H_ #define MACE_CORE_ARG_HELPER_H_ +#include +#include #include #include "mace/public/mace.h" diff --git a/mace/core/buffer.h b/mace/core/buffer.h index 38c577a5..e6d433e6 100644 --- a/mace/core/buffer.h +++ b/mace/core/buffer.h @@ -6,6 +6,8 @@ #define MACE_CORE_BUFFER_H_ #include +#include + #include "mace/core/allocator.h" #include "mace/core/types.h" @@ -14,7 +16,7 @@ namespace mace { class BufferBase { public: BufferBase() : size_(0) {} - BufferBase(index_t size) : size_(size) {} + explicit BufferBase(index_t size) : size_(size) {} virtual ~BufferBase() {} virtual void *buffer() = 0; @@ -39,7 +41,7 @@ class BufferBase { virtual bool OnHost() const = 0; - virtual index_t offset() const { return 0; }; + virtual index_t offset() const { return 0; } template const T *data() const { @@ -59,7 +61,7 @@ class BufferBase { class Buffer : public BufferBase { public: - Buffer(Allocator *allocator) + explicit Buffer(Allocator *allocator) : BufferBase(0), allocator_(allocator), buf_(nullptr), @@ -93,7 +95,7 @@ class Buffer : public BufferBase { void *buffer() { MACE_CHECK_NOTNULL(buf_); return buf_; - }; + } const void *raw_data() const { if (OnHost()) { @@ -129,7 +131,7 @@ class Buffer : public BufferBase { void Map(std::vector *pitch) { MACE_CHECK(mapped_buf_ == nullptr, "buf has been already mapped"); mapped_buf_ = Map(0, size_, pitch); - }; + } void UnMap() { UnMap(mapped_buf_); @@ -151,7 +153,7 @@ class Buffer : public BufferBase { void Copy(void *src, index_t offset, index_t length) { MACE_CHECK_NOTNULL(mapped_buf_); MACE_CHECK(length <= size_, "out of buffer"); - memcpy(mapped_buf_, (char *)src + offset, length); + memcpy(mapped_buf_, reinterpret_cast(src) + offset, length); } bool OnHost() const { return allocator_->OnHost(); } @@ -197,7 +199,7 @@ class Image : public BufferBase { void *buffer() { MACE_CHECK_NOTNULL(buf_); return buf_; - }; + } const void *raw_data() const { MACE_CHECK_NOTNULL(mapped_buf_); @@ -227,12 +229,12 @@ class Image : public BufferBase { MACE_CHECK(mapped_buf_ == nullptr, "buf has been already mapped"); MACE_CHECK_NOTNULL(pitch); mapped_buf_ = allocator_->MapImage(buf_, shape_, pitch); - }; + } void UnMap() { UnMap(mapped_buf_); mapped_buf_ = nullptr; - }; + } void Resize(index_t size) { MACE_NOT_IMPLEMENTED; } @@ -276,12 +278,12 @@ class BufferSlice : public BufferBase { void *buffer() { MACE_CHECK_NOTNULL(buffer_); return buffer_->buffer(); - }; + } const void *raw_data() const { if (OnHost()) { MACE_CHECK_NOTNULL(buffer_); - return (char *)buffer_->raw_data() + offset_; + return reinterpret_cast(buffer_->raw_data()) + offset_; } else { MACE_CHECK_NOTNULL(mapped_buf_); return mapped_buf_; @@ -304,13 +306,13 @@ class BufferSlice : public BufferBase { MACE_CHECK_NOTNULL(buffer_); MACE_CHECK(mapped_buf_ == nullptr, "mapped buf is not null"); mapped_buf_ = buffer_->Map(offset_, length_, pitch); - }; + } void UnMap() { MACE_CHECK_NOTNULL(mapped_buf_); buffer_->UnMap(mapped_buf_); mapped_buf_ = nullptr; - }; + } void Resize(index_t size) { MACE_NOT_IMPLEMENTED; } @@ -326,6 +328,6 @@ class BufferSlice : public BufferBase { index_t offset_; index_t length_; }; -} +} // namespace mace #endif // MACE_CORE_BUFFER_H_ diff --git a/mace/core/mace.cc b/mace/core/mace.cc index e4d25c7d..f1f0d59a 100644 --- a/mace/core/mace.cc +++ b/mace/core/mace.cc @@ -459,7 +459,7 @@ MaceEngine::~MaceEngine() { MACE_CHECK(hexagon_controller_->TeardownGraph(), "hexagon teardown error"); MACE_CHECK(hexagon_controller_->Finalize(), "hexagon finalize error"); } -}; +} bool MaceEngine::Run(const float *input, const std::vector &input_shape, @@ -493,7 +493,6 @@ bool MaceEngine::Run(const float *input, auto shape = output_tensor->shape(); int64_t output_size = std::accumulate(shape.begin(), shape.end(), 1, std::multiplies()); - // TODO: check for overflow exception. std::memcpy(output, output_tensor->data(), output_size * sizeof(float)); return true; @@ -530,7 +529,6 @@ bool MaceEngine::Run(const std::vector &inputs, int64_t output_size = std::accumulate(shape.begin(), shape.end(), 1, std::multiplies()); MACE_CHECK(!shape.empty()) << "Output's shape must greater than 0"; - // TODO: check for overflow exception. std::memcpy(output.second, output_tensor->data(), output_size * sizeof(float)); } else { diff --git a/mace/core/net.cc b/mace/core/net.cc index 2439a67f..02efc1a4 100644 --- a/mace/core/net.cc +++ b/mace/core/net.cc @@ -2,6 +2,8 @@ // Copyright (c) 2017 XiaoMi All rights reserved. // +#include + #include "mace/core/net.h" #include "mace/utils/memory_logging.h" #include "mace/utils/timer.h" diff --git a/mace/core/net.h b/mace/core/net.h index 3b625393..e1429722 100644 --- a/mace/core/net.h +++ b/mace/core/net.h @@ -5,6 +5,10 @@ #ifndef MACE_CORE_NET_H_ #define MACE_CORE_NET_H_ +#include +#include +#include + #include "mace/core/operator.h" #include "mace/public/mace.h" diff --git a/mace/core/operator.cc b/mace/core/operator.cc index c670d9aa..ae6ca107 100644 --- a/mace/core/operator.cc +++ b/mace/core/operator.cc @@ -3,6 +3,9 @@ // #include +#include +#include +#include #include "mace/core/operator.h" diff --git a/mace/core/operator.h b/mace/core/operator.h index a163c0c8..59986cad 100644 --- a/mace/core/operator.h +++ b/mace/core/operator.h @@ -5,6 +5,11 @@ #ifndef MACE_CORE_OPERATOR_H #define MACE_CORE_OPERATOR_H +#include +#include +#include +#include + #include "mace/core/arg_helper.h" #include "mace/core/future.h" #include "mace/core/registry.h" @@ -100,7 +105,7 @@ class Operator : public OperatorBase { } } } - virtual bool Run(StatsFuture *future) override = 0; + bool Run(StatsFuture *future) override = 0; ~Operator() noexcept override {} }; @@ -150,7 +155,7 @@ class OperatorRegistry { RegistryType; OperatorRegistry(); ~OperatorRegistry() = default; - RegistryType *registry() { return ®istry_; }; + RegistryType *registry() { return ®istry_; } std::unique_ptr CreateOperator(const OperatorDef &operator_def, Workspace *ws, DeviceType type, diff --git a/mace/core/preallocated_pooled_allocator.h b/mace/core/preallocated_pooled_allocator.h index 0299d2f4..80e7fa65 100644 --- a/mace/core/preallocated_pooled_allocator.h +++ b/mace/core/preallocated_pooled_allocator.h @@ -5,7 +5,10 @@ #ifndef MACE_CORE_PREALLOCATED_POOLED_ALLOCATOR_H_ #define MACE_CORE_PREALLOCATED_POOLED_ALLOCATOR_H_ +#include +#include #include + #include "mace/core/allocator.h" #include "mace/core/buffer.h" diff --git a/mace/core/registry.h b/mace/core/registry.h index 07eaa01b..0e1e85d2 100644 --- a/mace/core/registry.h +++ b/mace/core/registry.h @@ -7,7 +7,7 @@ #include #include -#include +#include // NOLINT(build/c++11) #include #include diff --git a/mace/core/runtime/cpu/cpu_runtime.cc b/mace/core/runtime/cpu/cpu_runtime.cc index 4c2cd851..cc8e214e 100644 --- a/mace/core/runtime/cpu/cpu_runtime.cc +++ b/mace/core/runtime/cpu/cpu_runtime.cc @@ -2,19 +2,21 @@ // Copyright (c) 2017 XiaoMi All rights reserved. // -#include "mace/public/mace.h" -#include "mace/utils/logging.h" #include #include #include +#include +#include "mace/core/runtime/cpu/cpu_runtime.h" +#include "mace/public/mace.h" +#include "mace/utils/logging.h" namespace mace { namespace { -static int GetCPUMaxFreq(int cpu_id) { +int GetCPUMaxFreq(int cpu_id) { char path[64]; - sprintf(path, + snprintf(path, sizeof(path), "/sys/devices/system/cpu/cpu%d/cpufreq/cpuinfo_max_freq", cpu_id); FILE *fp = fopen(path, "rb"); @@ -26,24 +28,24 @@ static int GetCPUMaxFreq(int cpu_id) { return freq; } -static void SortCPUIdsByMaxFreqAsc(std::vector &cpu_ids) { - int cpu_count = cpu_ids.size(); +void SortCPUIdsByMaxFreqAsc(std::vector *cpu_ids) { + int cpu_count = cpu_ids->size(); std::vector cpu_max_freq; cpu_max_freq.resize(cpu_count); // set cpu max frequency for (int i = 0; i < cpu_count; ++i) { cpu_max_freq[i] = GetCPUMaxFreq(i); - cpu_ids[i] = i; + (*cpu_ids)[i] = i; } // sort cpu ids by max frequency asc, bubble sort for (int i = 0; i < cpu_count - 1; ++i) { for (int j = i + 1; j < cpu_count; ++j) { if (cpu_max_freq[i] > cpu_max_freq[j]) { - int tmp = cpu_ids[i]; - cpu_ids[i] = cpu_ids[j]; - cpu_ids[j] = tmp; + int tmp = (*cpu_ids)[i]; + (*cpu_ids)[i] = (*cpu_ids)[j]; + (*cpu_ids)[j] = tmp; tmp = cpu_max_freq[i]; cpu_max_freq[i] = cpu_max_freq[j]; @@ -53,11 +55,12 @@ static void SortCPUIdsByMaxFreqAsc(std::vector &cpu_ids) { } } -static void SetThreadAffinity(cpu_set_t mask) { +void SetThreadAffinity(cpu_set_t mask) { int sys_call_res; pid_t pid = gettid(); - // TODO: when set omp num threads to 1, sometiomes return EINVAL(22) error + // TODO(chenghui): when set omp num threads to 1, + // sometiomes return EINVAL(22) error. // https://linux.die.net/man/2/sched_setaffinity sys_call_res = syscall(__NR_sched_setaffinity, pid, sizeof(mask), &mask); if (sys_call_res != 0) { @@ -68,12 +71,11 @@ static void SetThreadAffinity(cpu_set_t mask) { } // namespace void SetCPURuntime(int omp_num_threads, CPUPowerOption power_option) { - int cpu_count = omp_get_num_procs(); LOG(INFO) << "cpu_count: " << cpu_count; std::vector sorted_cpu_ids; sorted_cpu_ids.resize(cpu_count); - SortCPUIdsByMaxFreqAsc(sorted_cpu_ids); + SortCPUIdsByMaxFreqAsc(&sorted_cpu_ids); std::vector use_cpu_ids; if (power_option == CPUPowerOption::DEFAULT || omp_num_threads >= cpu_count) { @@ -92,7 +94,7 @@ void SetCPURuntime(int omp_num_threads, CPUPowerOption power_option) { // compute mask cpu_set_t mask; CPU_ZERO(&mask); - for (auto cpu_id: use_cpu_ids) { + for (auto cpu_id : use_cpu_ids) { CPU_SET(cpu_id, &mask); } LOG(INFO) << "use cpus mask: " << mask.__bits[0]; diff --git a/mace/core/runtime/cpu/cpu_runtime.h b/mace/core/runtime/cpu/cpu_runtime.h index 13dfd680..f80ca1b8 100644 --- a/mace/core/runtime/cpu/cpu_runtime.h +++ b/mace/core/runtime/cpu/cpu_runtime.h @@ -3,8 +3,8 @@ // -#ifndef MACE_CORE_RUNTIME_CPU_CPU_RUNTIME_H -#define MACE_CORE_RUNTIME_CPU_CPU_RUNTIME_H +#ifndef MACE_CORE_RUNTIME_CPU_CPU_RUNTIME_H_ +#define MACE_CORE_RUNTIME_CPU_CPU_RUNTIME_H_ #include "mace/public/mace.h" @@ -14,4 +14,4 @@ void SetCPURuntime(int omp_num_threads, CPUPowerOption power_option); } -#endif //MACE_CORE_RUNTIME_CPU_CPU_RUNTIME_H +#endif // MACE_CORE_RUNTIME_CPU_CPU_RUNTIME_H_ diff --git a/mace/core/runtime/hexagon/hexagon_control_wrapper.cc b/mace/core/runtime/hexagon/hexagon_control_wrapper.cc index 2828ffa0..138fd933 100644 --- a/mace/core/runtime/hexagon/hexagon_control_wrapper.cc +++ b/mace/core/runtime/hexagon/hexagon_control_wrapper.cc @@ -3,8 +3,11 @@ // #include -#include +#include // NOLINT(build/c++11) #include +#include +#include +#include #include "mace/core/runtime/hexagon/hexagon_control_wrapper.h" #include "mace/core/runtime/hexagon/hexagon_nn_ops.h" @@ -324,7 +327,7 @@ bool HexagonControlWrapper::ExecuteGraph(const Tensor &input_tensor, MACE_ASSERT(output_bytes == output_tensor->raw_size(), "wrong output bytes inferred."); return res == 0; -}; +} bool HexagonControlWrapper::ExecuteGraphNew( const std::vector &input_tensors, @@ -374,7 +377,7 @@ bool HexagonControlWrapper::ExecuteGraphNew( delete[] inputs; delete[] outputs; return res == 0; -}; +} bool HexagonControlWrapper::ExecuteGraphPreQuantize(const Tensor &input_tensor, Tensor *output_tensor) { diff --git a/mace/core/runtime/hexagon/hexagon_control_wrapper.h b/mace/core/runtime/hexagon/hexagon_control_wrapper.h index 8cb3b359..9f17ca96 100644 --- a/mace/core/runtime/hexagon/hexagon_control_wrapper.h +++ b/mace/core/runtime/hexagon/hexagon_control_wrapper.h @@ -16,7 +16,7 @@ namespace mace { class HexagonControlWrapper { public: - HexagonControlWrapper(){}; + HexagonControlWrapper() {} int GetVersion(); bool Config(); bool Init(); @@ -53,6 +53,6 @@ class HexagonControlWrapper { DISABLE_COPY_AND_ASSIGN(HexagonControlWrapper); }; -} +} // namespace mace #endif // MACE_DSP_HEXAGON_CONTROL_WRAPPER_H_ diff --git a/mace/core/runtime/hexagon/hexagon_controller.h b/mace/core/runtime/hexagon/hexagon_controller.h index 0e7d7596..2b8b20be 100644 --- a/mace/core/runtime/hexagon/hexagon_controller.h +++ b/mace/core/runtime/hexagon/hexagon_controller.h @@ -1,5 +1,9 @@ -#ifndef MACE_DSP_HEXAGON_DSP_CONTROLLER_H_ -#define MACE_DSP_HEXAGON_DSP_CONTROLLER_H_ +// +// Copyright (c) 2017 XiaoMi All rights reserved. +// + +#ifndef MACE_CORE_RUNTIME_HEXAGON_CONTROLLER_H_ +#define MACE_CORE_RUNTIME_HEXAGON_CONTROLLER_H_ #include "mace/core/runtime/hexagon/hexagon_nn.h" @@ -18,4 +22,5 @@ int hexagon_controller_DeInitHexagon(); } #endif // __cplusplus -#endif // MACE_DSP_HEXAGON_DSP_CONTROLLER_H_ \ No newline at end of file +#endif // MACE_CORE_RUNTIME_HEXAGON_CONTROLLER_H_ + diff --git a/mace/core/runtime/hexagon/hexagon_nn.h b/mace/core/runtime/hexagon/hexagon_nn.h index 0baafd8c..82cfb3de 100644 --- a/mace/core/runtime/hexagon/hexagon_nn.h +++ b/mace/core/runtime/hexagon/hexagon_nn.h @@ -1,8 +1,43 @@ -#ifndef _HEXAGON_NN_H -#define _HEXAGON_NN_H +/* + * Copyright (c) 2016-2017, The Linux Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted (subject to the limitations in the + * disclaimer below) provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * + * * Neither the name of The Linux Foundation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE + * GRANTED BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT + * HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE + * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER + * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#ifndef MACE_CORE_RUNTIME_HEXAGON_NN_H_ +#define MACE_CORE_RUNTIME_HEXAGON_NN_H_ #ifndef __QAIC_HEADER #define __QAIC_HEADER(ff) ff -#endif //__QAIC_HEADER +#endif // __QAIC_HEADER #ifndef __QAIC_HEADER_EXPORT #define __QAIC_HEADER_EXPORT @@ -14,7 +49,7 @@ #ifndef __QAIC_IMPL #define __QAIC_IMPL(ff) ff -#endif //__QAIC_IMPL +#endif // __QAIC_IMPL #ifndef __QAIC_IMPL_EXPORT #define __QAIC_IMPL_EXPORT @@ -186,4 +221,4 @@ __QAIC_HEADER_EXPORT int __QAIC_HEADER(hexagon_nn_execute_new)( #ifdef __cplusplus } #endif -#endif //_HEXAGON_NN_H +#endif // MACE_CORE_RUNTIME_HEXAGON_NN_H_ diff --git a/mace/core/runtime/hexagon/hexagon_nn_ops.h b/mace/core/runtime/hexagon/hexagon_nn_ops.h index 8704ce80..74cdb32d 100644 --- a/mace/core/runtime/hexagon/hexagon_nn_ops.h +++ b/mace/core/runtime/hexagon/hexagon_nn_ops.h @@ -2,10 +2,12 @@ // Copyright (c) 2018 XiaoMi All rights reserved. // -#ifndef LIBMACE_HEXAGON_NN_OPS_H -#define LIBMACE_HEXAGON_NN_OPS_H +#ifndef MACE_CORE_RUNTIME_HEXAGON_NN_OPS_H_ +#define MACE_CORE_RUNTIME_HEXAGON_NN_OPS_H_ +#include #include + #include "mace/utils/logging.h" namespace mace { @@ -15,7 +17,7 @@ namespace mace { typedef enum op_type_enum { #define DEF_OP(NAME, ...) OP_##NAME, -#include "mace/core/runtime/hexagon/ops.h" +#include "mace/core/runtime/hexagon/ops.h" // NOLINT(build/include) NN_OPS_MAX #undef DEF_OP @@ -26,7 +28,7 @@ class OpMap { void Init() { #define DEF_OP(NAME) op_map_[#NAME] = OP_##NAME; -#include "mace/core/runtime/hexagon/ops.h" +#include "mace/core/runtime/hexagon/ops.h" // NOLINT(build/include) #undef DEF_OP } @@ -45,4 +47,4 @@ class OpMap { }; } // namespace mace -#endif // LIBMACE_HEXAGON_NN_OPS_H +#endif // MACE_CORE_RUNTIME_HEXAGON_NN_OPS_H_ diff --git a/mace/core/runtime/hexagon/ops.h b/mace/core/runtime/hexagon/ops.h index 55b40413..a01e71ac 100644 --- a/mace/core/runtime/hexagon/ops.h +++ b/mace/core/runtime/hexagon/ops.h @@ -1,3 +1,38 @@ +/* + * Copyright (c) 2016-2017, The Linux Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted (subject to the limitations in the + * disclaimer below) provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * + * * Neither the name of The Linux Foundation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE + * GRANTED BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT + * HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE + * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER + * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + /* * You probably want to * @@ -42,6 +77,8 @@ * * otherwise the interface becomes incompatible. */ +// NOLINT(build/header_guard) + DEF_OP(INPUT) DEF_OP(OUTPUT) DEF_OP(Nop) diff --git a/mace/core/runtime/hexagon/quantize.cc b/mace/core/runtime/hexagon/quantize.cc index c4548bcb..7330424a 100644 --- a/mace/core/runtime/hexagon/quantize.cc +++ b/mace/core/runtime/hexagon/quantize.cc @@ -2,6 +2,8 @@ // Copyright (c) 2017 XiaoMi All rights reserved. // +#include + #include "mace/core/runtime/hexagon/quantize.h" namespace mace { @@ -93,4 +95,5 @@ void Quantizer::DeQuantize(const Tensor &in_tensor, } } -} // namespace mace \ No newline at end of file + +} // namespace mace diff --git a/mace/core/runtime/hexagon/quantize.h b/mace/core/runtime/hexagon/quantize.h index 216e0c6b..8e98f3be 100644 --- a/mace/core/runtime/hexagon/quantize.h +++ b/mace/core/runtime/hexagon/quantize.h @@ -2,8 +2,8 @@ // Copyright (c) 2017 XiaoMi All rights reserved. // -#ifndef MACE_DSP_UTIL_QUANTIZE_H_ -#define MACE_DSP_UTIL_QUANTIZE_H_ +#ifndef MACE_CORE_RUNTIME_HEXAGON_QUANTIZE_H_ +#define MACE_CORE_RUNTIME_HEXAGON_QUANTIZE_H_ #include "mace/core/tensor.h" @@ -40,6 +40,6 @@ class Quantizer { DISABLE_COPY_AND_ASSIGN(Quantizer); }; -} // mace +} // namespace mace -#endif // MACE_DSP_UTIL_QUANTIZE_H_ +#endif // MACE_CORE_RUNTIME_HEXAGON_QUANTIZE_H_ diff --git a/mace/core/tensor.h b/mace/core/tensor.h index 66c9c195..1d7d5deb 100644 --- a/mace/core/tensor.h +++ b/mace/core/tensor.h @@ -5,6 +5,10 @@ #ifndef MACE_CORE_TENSOR_H_ #define MACE_CORE_TENSOR_H_ +#include +#include +#include + #include "mace/core/buffer.h" #include "mace/core/preallocated_pooled_allocator.h" #include "mace/core/runtime/opencl/cl2_header.h" @@ -60,7 +64,7 @@ inline std::ostream &operator<<(std::ostream &os, signed char c) { inline std::ostream &operator<<(std::ostream &os, unsigned char c) { return os << static_cast(c); } -} +} // namespace numerical_chars class Tensor { public: @@ -69,7 +73,7 @@ class Tensor { dtype_(type), buffer_(nullptr), is_buffer_owner_(true), - name_(""){}; + name_("") {} Tensor(BufferBase *buffer, DataType dtype) : dtype_(dtype), @@ -240,7 +244,7 @@ class Tensor { inline void SetSourceOpName(const std::string name) { name_ = name; } inline void DebugPrint() const { - using namespace numerical_chars; + using namespace numerical_chars; // NOLINT(build/namespaces) std::stringstream os; for (index_t i : shape_) { os << i << ", "; @@ -262,7 +266,7 @@ class Tensor { class MappingGuard { public: - MappingGuard(const Tensor *tensor) : tensor_(tensor) { + explicit MappingGuard(const Tensor *tensor) : tensor_(tensor) { if (tensor_ != nullptr) { tensor_->buffer_->Map(&mapped_image_pitch_); } @@ -301,6 +305,6 @@ class Tensor { DISABLE_COPY_AND_ASSIGN(Tensor); }; -} // namespace tensor +} // namespace mace #endif // MACE_CORE_TENSOR_H_ diff --git a/mace/core/testing/test_benchmark.cc b/mace/core/testing/test_benchmark.cc index 7dcf2a27..4a894a1d 100644 --- a/mace/core/testing/test_benchmark.cc +++ b/mace/core/testing/test_benchmark.cc @@ -6,7 +6,7 @@ #include #include -#include +#include // NOLINT(build/c++11) #include #include "mace/core/testing/test_benchmark.h" diff --git a/mace/core/testing/test_benchmark_main.cc b/mace/core/testing/test_benchmark_main.cc index 91302d78..76b7d15f 100644 --- a/mace/core/testing/test_benchmark_main.cc +++ b/mace/core/testing/test_benchmark_main.cc @@ -14,7 +14,6 @@ int main(int argc, char **argv) { mace::ConfigOpenCLRuntime(mace::GPUType::ADRENO, mace::GPUPerfHint::PERF_HIGH, mace::GPUPriorityHint::PRIORITY_HIGH); - // TODO Use gflags if (argc == 2) { mace::testing::Benchmark::Run(argv[1]); } else { diff --git a/mace/core/types.h b/mace/core/types.h index 5eb7b536..e7a078f6 100644 --- a/mace/core/types.h +++ b/mace/core/types.h @@ -6,6 +6,7 @@ #define MACE_CORE_TYPES_H_ #include +#include #include "mace/public/mace.h" #include "include/half.hpp" diff --git a/mace/core/workspace.cc b/mace/core/workspace.cc index 2cb5e237..1aabb5de 100644 --- a/mace/core/workspace.cc +++ b/mace/core/workspace.cc @@ -4,6 +4,7 @@ #include #include +#include #include "mace/core/arg_helper.h" #include "mace/core/workspace.h" @@ -52,16 +53,16 @@ void Workspace::LoadModelTensor(const NetDef &net_def, DeviceType type) { unsigned char *model_data_ptr = nullptr; for (auto &const_tensor : net_def.tensors()) { if (model_data_ptr == nullptr || - reinterpret_cast(const_tensor.data()) < - reinterpret_cast(model_data_ptr)) { + reinterpret_cast(const_tensor.data()) < + reinterpret_cast(model_data_ptr)) { model_data_ptr = const_cast(const_tensor.data()); } } for (auto &const_tensor : net_def.tensors()) { model_data_size = std::max( model_data_size, - static_cast((reinterpret_cast(const_tensor.data()) - - reinterpret_cast(model_data_ptr)) + + static_cast((reinterpret_cast(const_tensor.data()) - + reinterpret_cast(model_data_ptr)) + const_tensor.data_size() * GetEnumTypeSize(const_tensor.data_type()))); } @@ -89,7 +90,8 @@ void Workspace::LoadModelTensor(const NetDef &net_def, DeviceType type) { dims.push_back(d); } - index_t offset = (long long)const_tensor.data() - (long long)model_data_ptr; + index_t offset = reinterpret_cast(const_tensor.data()) + - reinterpret_cast(model_data_ptr); std::unique_ptr tensor( new Tensor(BufferSlice(tensor_buffer_.get(), offset, const_tensor.data_size() * @@ -116,7 +118,7 @@ void Workspace::CreateImageOutputTensor(const NetDef &net_def) { // As DSP may have different data output type for each op, // we stick to the same concept. for (auto &op : net_def.op()) { - if (! op.mem_id().empty()){ + if (!op.mem_id().empty()) { const DataType op_dtype = static_cast( ArgumentHelper::GetSingleArgument( op, "T", static_cast(DT_FLOAT))); @@ -142,11 +144,14 @@ void Workspace::CreateImageOutputTensor(const NetDef &net_def) { std::unique_ptr tensor (new Tensor(preallocated_allocator_.GetBuffer(mem_ids[i]), dtype)); tensor->SetSourceOpName(op.name()); - VLOG(3) << "Tensor: " << op.name() << "(" << op.type() << ")" << "; Mem: " - << mem_ids[i] << "; Image shape: " - << dynamic_cast(tensor->UnderlyingBuffer())->image_shape()[0] + VLOG(3) << "Tensor: " << op.name() << "(" << op.type() << ")" + << " Mem: " << mem_ids[i] + << " Image shape: " + << dynamic_cast(tensor->UnderlyingBuffer()) + ->image_shape()[0] << ", " - << dynamic_cast(tensor->UnderlyingBuffer())->image_shape()[1]; + << dynamic_cast(tensor->UnderlyingBuffer()) + ->image_shape()[1]; tensor_map_[op.output(i)] = std::move(tensor); } } diff --git a/mace/core/workspace.h b/mace/core/workspace.h index 5e990d82..1e101267 100644 --- a/mace/core/workspace.h +++ b/mace/core/workspace.h @@ -5,6 +5,11 @@ #ifndef MACE_CORE_WORKSPACE_H_ #define MACE_CORE_WORKSPACE_H_ +#include +#include +#include +#include + #include "mace/core/preallocated_pooled_allocator.h" #include "mace/core/tensor.h" #include "mace/public/mace.h" -- GitLab