diff --git a/mace/core/BUILD b/mace/core/BUILD index 4714a0ebee50f86c7ee162e7cbf149cdeba8a8b6..f959ff0f19b0a2a351063b55a32cadcbf4637a6d 100644 --- a/mace/core/BUILD +++ b/mace/core/BUILD @@ -7,19 +7,31 @@ package( licenses(["notice"]) # Apache 2.0 -load("//mace:mace.bzl", "if_android", "if_profiling_enabled", "if_embed_binary_program") +load("//mace:mace.bzl", "if_android", "if_android_armv7", "if_android_arm64", + + "if_profiling_enabled", "if_embed_binary_program") cc_library( name = "core", srcs = glob([ "*.cc", "runtime/opencl/*.cc", + "runtime/hexagon/*.cc", + ], + exclude = [ + "*_test.cc", + "runtime/hexagon/hexagon_controller_dummy.cc", + ]) + if_android_armv7([ + "runtime/hexagon/libhexagon_controller.so", + ]) + if_android_arm64([ + "runtime/hexagon/hexagon_controller_dummy.cc", ]), hdrs = glob([ "*.h", "public/*.h", "runtime/opencl/cl2.hpp", "runtime/opencl/*.h", + "runtime/hexagon/*.h", ]), copts = ["-std=c++11", "-D_GLIBCXX_USE_C99_MATH_TR1", "-Werror=return-type"] + if_profiling_enabled(["-DMACE_OPENCL_PROFILING"]) + diff --git a/mace/core/allocator.cc b/mace/core/allocator.cc index fcf3ef6af23510ba9df048ddd7e3a4765c2992af..8f65fbc56c7ddf235d5ac4006bfa0e904afbbce2 100644 --- a/mace/core/allocator.cc +++ b/mace/core/allocator.cc @@ -24,5 +24,6 @@ Allocator *GetDeviceAllocator(DeviceType type) { MACE_REGISTER_ALLOCATOR(DeviceType::CPU, new CPUAllocator()); MACE_REGISTER_ALLOCATOR(DeviceType::NEON, new CPUAllocator()); MACE_REGISTER_ALLOCATOR(DeviceType::OPENCL, new OpenCLAllocator()); +MACE_REGISTER_ALLOCATOR(DeviceType::HEXAGON, new CPUAllocator()); } // namespace mace diff --git a/mace/core/mace.cc b/mace/core/mace.cc index c25deea3d2a88ebded71181b8f894882cc3de1e3..5b98f8b83887b75c8c91ad419249664f75dd519d 100644 --- a/mace/core/mace.cc +++ b/mace/core/mace.cc @@ -5,9 +5,7 @@ #include "mace/core/public/mace.h" #include "mace/core/types.h" #include "mace/core/net.h" -#include "mace/core/operator.h" -#include "mace/core/workspace.h" -#include "mace/utils/logging.h" +#include "mace/core/runtime/hexagon/hexagon_control_wrapper.h" namespace mace { @@ -16,26 +14,26 @@ ConstTensor::ConstTensor(const std::string &name, const std::vector &dims, const DataType data_type, uint32_t node_id) : - name_(name), - data_(data), - data_size_(std::accumulate(dims.begin(), dims.end(), 1, - std::multiplies())), - dims_(dims.begin(), dims.end()), - data_type_(data_type), - node_id_(node_id) {} + name_(name), + data_(data), + data_size_(std::accumulate(dims.begin(), dims.end(), 1, + std::multiplies())), + dims_(dims.begin(), dims.end()), + data_type_(data_type), + node_id_(node_id) {} ConstTensor::ConstTensor(const std::string &name, unsigned char *data, const std::vector &dims, const int data_type, uint32_t node_id) : - name_(name), - data_(data), - data_size_(std::accumulate(dims.begin(), dims.end(), 1, - std::multiplies())), - dims_(dims.begin(), dims.end()), - data_type_(static_cast(data_type)), - node_id_(node_id) {} + name_(name), + data_(data), + data_size_(std::accumulate(dims.begin(), dims.end(), 1, + std::multiplies())), + dims_(dims.begin(), dims.end()), + data_type_(static_cast(data_type)), + node_id_(node_id) {} const std::string &ConstTensor::name() const { return name_; @@ -152,6 +150,8 @@ void Argument::set_strings(const std::vector &value) { } // Node Input +NodeInput::NodeInput(int node_id, int output_port) + : node_id_(node_id), output_port_(output_port) {} void NodeInput::CopyFrom(const NodeInput &from) { node_id_ = from.node_id(); output_port_ = from.output_port(); @@ -159,14 +159,20 @@ void NodeInput::CopyFrom(const NodeInput &from) { int NodeInput::node_id() const { return node_id_; } +void NodeInput::set_node_id(int node_id) { + node_id_ = node_id; +} int NodeInput::output_port() const { return output_port_; } +void NodeInput::set_output_port(int output_port) { + output_port_ = output_port; +} // OutputShape OutputShape::OutputShape() {} -OutputShape::OutputShape(const std::vector &dims): - dims_(dims.begin(), dims.end()) {} +OutputShape::OutputShape(const std::vector &dims) : + dims_(dims.begin(), dims.end()) {} void OutputShape::CopyFrom(const OutputShape &from) { auto from_dims = from.dims(); dims_.resize(from_dims.size()); @@ -214,7 +220,9 @@ void OperatorDef::CopyFrom(const OperatorDef &from) { } auto from_out_max_byte_size = from.out_max_byte_size(); out_max_byte_size_.resize(from_out_max_byte_size.size()); - std::copy(from_out_max_byte_size.begin(), from_out_max_byte_size.end(), out_max_byte_size_.begin()); + std::copy(from_out_max_byte_size.begin(), + from_out_max_byte_size.end(), + out_max_byte_size_.begin()); has_bits_ = from.has_bits_; @@ -262,18 +270,30 @@ void OperatorDef::set_has_mem_id() { uint32_t OperatorDef::node_id() const { return node_id_; } +void OperatorDef::set_node_id(uint32_t node_id) { + node_id_ = node_id; +} uint32_t OperatorDef::op_id() const { return op_id_; } uint32_t OperatorDef::padding() const { return padding_; } +void OperatorDef::set_padding(uint32_t padding) { + padding_ = padding; +} const std::vector &OperatorDef::node_input() const { return node_input_; } +void OperatorDef::add_node_input(const NodeInput &value) { + node_input_.push_back(value); +} const std::vector &OperatorDef::out_max_byte_size() const { return out_max_byte_size_; } +void OperatorDef::add_out_max_byte_size(int value) { + out_max_byte_size_.push_back(value); +} const std::vector &OperatorDef::input() const { return input_; } @@ -339,7 +359,7 @@ void OperatorDef::set_output_type(const std::vector &value) { // MemoryBlock MemoryBlock::MemoryBlock(int mem_id, uint32_t x, uint32_t y) : - mem_id_(mem_id), x_(x), y_(y) {} + mem_id_(mem_id), x_(x), y_(y) {} int MemoryBlock::mem_id() const { return mem_id_; @@ -392,9 +412,15 @@ int32_t OutputInfo::max_byte_size() const { DataType OutputInfo::data_type() const { return data_type_; } +void OutputInfo::set_data_type(DataType data_type) { + data_type_ = data_type; +} const std::vector &OutputInfo::dims() const { return dims_; } +void OutputInfo::set_dims(const std::vector &dims) { + dims_ = dims; +} // NetDef NetDef::NetDef() : has_bits_(0) {} @@ -470,6 +496,9 @@ const std::vector &NetDef::input_info() const { const std::vector &NetDef::output_info() const { return output_info_; } +std::vector &NetDef::mutable_output_info() { + return output_info_; +} int NetDef::op_size() const { return op_.size(); @@ -481,40 +510,66 @@ const OperatorDef &NetDef::op(const int idx) const { } // Mace Engine -MaceEngine::MaceEngine(const NetDef *net_def, DeviceType device_type): - op_registry_(new OperatorRegistry()), device_type_(device_type), - ws_(new Workspace()), net_(nullptr) { +MaceEngine::MaceEngine(const NetDef *net_def, DeviceType device_type) : + op_registry_(new OperatorRegistry()), device_type_(device_type), + ws_(new Workspace()), net_(nullptr), hexagon_controller_(nullptr) { - ws_->LoadModelTensor(*net_def, device_type); + if (device_type == HEXAGON) { + hexagon_controller_.reset(new HexagonControlWrapper()); + hexagon_controller_->Init(); + hexagon_controller_->SetDebugLevel(0); + hexagon_controller_->Config(); + hexagon_controller_->SetupGraph(*net_def); + hexagon_controller_->PrintGraph(); + } else { + ws_->LoadModelTensor(*net_def, device_type); - // Init model - auto net = CreateNet(op_registry_, *net_def, ws_.get(), - device_type, NetMode::INIT); - if(!net->Run()) { - LOG(FATAL) << "Net init run failed"; + // Init model + auto net = CreateNet(op_registry_, *net_def, ws_.get(), + device_type, NetMode::INIT); + if (!net->Run()) { + LOG(FATAL) << "Net init run failed"; + } + ws_->CreateTensor("mace_input_node:0", + GetDeviceAllocator(device_type_), + DT_FLOAT); + net_ = std::move(CreateNet(op_registry_, *net_def, ws_.get(), device_type)); } - ws_->CreateTensor("mace_input_node:0", GetDeviceAllocator(device_type_), DT_FLOAT); - net_ = std::move(CreateNet(op_registry_, *net_def, ws_.get(), device_type)); } -MaceEngine::~MaceEngine() = default; +MaceEngine::~MaceEngine() { + if (device_type_ == HEXAGON) { + hexagon_controller_->GetPerfInfo(); + hexagon_controller_->PrintLog(); + hexagon_controller_->TeardownGraph(); + hexagon_controller_->Finalize(); + } +}; bool MaceEngine::Run(const float *input, const std::vector &input_shape, float *output) { MACE_CHECK(output != nullptr, "output ptr cannot be NULL"); Tensor *input_tensor = - ws_->CreateTensor("mace_input_node:0", GetDeviceAllocator(device_type_), DT_FLOAT); + ws_->CreateTensor("mace_input_node:0", + GetDeviceAllocator(device_type_), + DT_FLOAT); + Tensor *output_tensor = + ws_->CreateTensor("mace_output_node:0", + GetDeviceAllocator(device_type_), + DT_FLOAT); input_tensor->Resize(input_shape); { Tensor::MappingGuard input_guard(input_tensor); float *input_data = input_tensor->mutable_data(); memcpy(input_data, input, input_tensor->size() * sizeof(float)); } - if(!net_->Run()) { - LOG(FATAL) << "Net run failed"; + if (device_type_ == HEXAGON) { + hexagon_controller_->ExecuteGraphPreQuantize(*input_tensor, output_tensor); + } else { + if (!net_->Run()) { + LOG(FATAL) << "Net run failed"; + } } // save output - const Tensor *output_tensor = ws_->GetTensor("mace_output_node:0"); - if (output_tensor != nullptr) { Tensor::MappingGuard output_guard(output_tensor); auto shape = output_tensor->shape(); diff --git a/mace/core/public/mace.h b/mace/core/public/mace.h index a363610f6f93d540d3235bcff332eeb92937fd39..fb0cd06d57a6712b21cef76d433dfa3a94261e98 100644 --- a/mace/core/public/mace.h +++ b/mace/core/public/mace.h @@ -19,7 +19,8 @@ enum NetMode { enum DeviceType { CPU = 0, NEON = 1, - OPENCL = 2 + OPENCL = 2, + HEXAGON = 3 }; enum DataType { @@ -70,33 +71,33 @@ class ConstTensor { class Argument { public: Argument(); - void CopyFrom(const Argument &from) ; + void CopyFrom(const Argument &from); public: const std::string &name() const; - void set_name(const std::string& value); + void set_name(const std::string &value); bool has_f() const; - float f() const ; - void set_f(float value) ; - bool has_i() const ; - int64_t i() const ; + float f() const; + void set_f(float value); + bool has_i() const; + int64_t i() const; void set_i(int64_t value); - bool has_s() const ; - std::string s() const ; - void set_s(const std::string& value) ; - const std::vector &floats() const ; - void add_floats(float value) ; + bool has_s() const; + std::string s() const; + void set_s(const std::string &value); + const std::vector &floats() const; + void add_floats(float value); void set_floats(const std::vector &value); - const std::vector &ints() const ; - void add_ints(int64_t value) ; + const std::vector &ints() const; + void add_ints(int64_t value); void set_ints(const std::vector &value); - const std::vector &strings() const ; - void add_strings(const ::std::string& value) ; + const std::vector &strings() const; + void add_strings(const ::std::string &value); void set_strings(const std::vector &value); private: - void set_has_f() ; - void set_has_i() ; - void set_has_s() ; + void set_has_f(); + void set_has_i(); + void set_has_s(); private: std::string name_; @@ -104,17 +105,21 @@ class Argument { int64_t i_; std::string s_; std::vector floats_; - std::vector ints_; + std::vector ints_; std::vector strings_; uint32_t has_bits_; }; class NodeInput { public: + NodeInput() {} + NodeInput(int node_id, int output_port); void CopyFrom(const NodeInput &from); public: int node_id() const; + void set_node_id(int node_id); int output_port() const; + void set_output_port(int output_port); private: int node_id_; int output_port_; @@ -146,24 +151,28 @@ class OperatorDef { void set_mem_id(const int mem_id); bool has_mem_id() const; uint32_t node_id() const; + void set_node_id(uint32_t node_id); uint32_t op_id() const; uint32_t padding() const; + void set_padding(uint32_t padding); const std::vector &node_input() const; + void add_node_input(const NodeInput &value); const std::vector &out_max_byte_size() const; + void add_out_max_byte_size(int value); const std::vector &input() const; - const std::string& input(int index) const; - std::string* add_input(); - void add_input(const ::std::string& value); - void add_input(::std::string&& value); + const std::string &input(int index) const; + std::string *add_input(); + void add_input(const ::std::string &value); + void add_input(::std::string &&value); void set_input(const std::vector &value); const std::vector &output() const; - const std::string& output(int index) const; - std::string* add_output(); - void add_output(const ::std::string& value); - void add_output(::std::string&& value); + const std::string &output(int index) const; + std::string *add_output(); + void add_output(const ::std::string &value); + void add_output(::std::string &&value); void set_output(const std::vector &value); const std::vector &arg() const; - Argument* add_arg(); + Argument *add_arg(); const std::vector &output_shape() const; void add_output_shape(const OutputShape &value); const std::vector &output_type() const; @@ -241,7 +250,9 @@ class OutputInfo { int32_t node_id() const; int32_t max_byte_size() const; DataType data_type() const; + void set_data_type(DataType data_type); const std::vector &dims() const; + void set_dims(const std::vector &dims); private: std::string name_; int32_t node_id_; @@ -259,13 +270,13 @@ class NetDef { public: const std::string &name() const; bool has_name() const; - void set_name(const std::string& value); + void set_name(const std::string &value); const std::string &version() const; bool has_version() const; - void set_version(const std::string& value); + void set_version(const std::string &value); const std::vector &op() const; - OperatorDef* add_op(); + OperatorDef *add_op(); std::vector &mutable_op(); const std::vector &arg() const; Argument *add_arg(); @@ -277,6 +288,7 @@ class NetDef { MemoryArena &mutable_mem_arena(); const std::vector &input_info() const; const std::vector &output_info() const; + std::vector &mutable_output_info(); private: void set_has_name(); @@ -303,6 +315,7 @@ class NetDef { class Workspace; class NetBase; class OperatorRegistry; +class HexagonControlWrapper; class MaceEngine { public: @@ -312,14 +325,15 @@ class MaceEngine { bool Run(const float *input, const std::vector &input_shape, float *output); - MaceEngine(const MaceEngine&) = delete; - MaceEngine &operator=(const MaceEngine&) = delete; + MaceEngine(const MaceEngine &) = delete; + MaceEngine &operator=(const MaceEngine &) = delete; private: std::shared_ptr op_registry_; DeviceType device_type_; std::unique_ptr ws_; std::unique_ptr net_; + std::unique_ptr hexagon_controller_; }; } // namespace mace diff --git a/mace/dsp/hexagon_control_wrapper.cc b/mace/core/runtime/hexagon/hexagon_control_wrapper.cc similarity index 93% rename from mace/dsp/hexagon_control_wrapper.cc rename to mace/core/runtime/hexagon/hexagon_control_wrapper.cc index c89d2726e17048f479d637e97f0c74e820e26bd5..89c09c91e78cc24b8558949067d3a4a48facb553 100644 --- a/mace/dsp/hexagon_control_wrapper.cc +++ b/mace/core/runtime/hexagon/hexagon_control_wrapper.cc @@ -2,8 +2,9 @@ // Copyright (c) 2017 XiaoMi All rights reserved. // -#include "mace/dsp/hexagon_control_wrapper.h" +#include "mace/core/runtime/hexagon/hexagon_control_wrapper.h" #include +#include namespace mace { @@ -45,7 +46,7 @@ bool HexagonControlWrapper::Finalize() { bool HexagonControlWrapper::SetupGraph(const NetDef& net_def) { LOG(INFO) << "Hexagon setup graph"; // const node - for (const TensorProto& tensor_proto: net_def.tensors()) { + for (const ConstTensor& tensor_proto: net_def.tensors()) { vector tensor_shape(tensor_proto.dims().begin(), tensor_proto.dims().end()); while (tensor_shape.size() < 4) { @@ -53,7 +54,7 @@ bool HexagonControlWrapper::SetupGraph(const NetDef& net_def) { } if (tensor_proto.data_type() == DataType::DT_INT32 - && tensor_proto.int32_data_size() == 0) { + && tensor_proto.data_size() == 0) { hexagon_nn_append_const_node(nn_id_, node_id(tensor_proto.node_id()), tensor_shape[0], tensor_shape[1], tensor_shape[2], tensor_shape[3], @@ -81,14 +82,14 @@ bool HexagonControlWrapper::SetupGraph(const NetDef& net_def) { unsigned int op_id; MACE_CHECK(hexagon_nn_op_name_to_id(op.type().data(), &op_id) == 0, "invalid op: ", op.name(), ", type: ", op.type()); - vector inputs(op.node_input_size()); - for (size_t i = 0; i < op.node_input_size(); ++i) { - inputs[i].src_id = node_id(op.node_input(i).node_id()); - inputs[i].output_idx = op.node_input(i).output_port(); + vector inputs(op.node_input().size()); + for (size_t i = 0; i < op.node_input().size(); ++i) { + inputs[i].src_id = node_id(op.node_input()[i].node_id()); + inputs[i].output_idx = op.node_input()[i].output_port(); } - vector outputs(op.out_max_byte_size_size()); - for (size_t i = 0; i < op.out_max_byte_size_size(); ++i) { - outputs[i].max_size = op.out_max_byte_size(i); + vector outputs(op.out_max_byte_size().size()); + for (size_t i = 0; i < op.out_max_byte_size().size(); ++i) { + outputs[i].max_size = op.out_max_byte_size()[i]; } hexagon_nn_padding_type padding_type = static_cast( @@ -136,20 +137,18 @@ bool HexagonControlWrapper::SetupGraph(const NetDef& net_def) { output_shapes_.push_back(output_shape); output_data_types_.push_back(output_info.data_type()); num_outputs_ += 1; + VLOG(0) << "OutputInfo: " + << "\n\t shape: " << output_shape[0] << " " << output_shape[1] + << " " << output_shape[2] << " " << output_shape[3] + << "\n\t type: " << output_info.data_type(); } + VLOG(0) << "Magic"; + bool res = hexagon_nn_prepare(nn_id_) == 0; return res; } -bool HexagonControlWrapper::SetupGraph(const std::string& model_file) { - std::ifstream file_stream(model_file, std::ios::in | std::ios::binary); - NetDef net_def; - net_def.ParseFromIstream(&file_stream); - file_stream.close(); - return SetupGraph(net_def); -} - bool HexagonControlWrapper::TeardownGraph() { LOG(INFO) << "Hexagon teardown graph"; return hexagon_nn_teardown(nn_id_) == 0; diff --git a/mace/dsp/hexagon_control_wrapper.h b/mace/core/runtime/hexagon/hexagon_control_wrapper.h similarity index 87% rename from mace/dsp/hexagon_control_wrapper.h rename to mace/core/runtime/hexagon/hexagon_control_wrapper.h index fa9f47b1bc7fbbb08e58b70ab15f5cb8e884f847..f1b0a8c01af627989959d44cf6d175543048e11e 100644 --- a/mace/dsp/hexagon_control_wrapper.h +++ b/mace/core/runtime/hexagon/hexagon_control_wrapper.h @@ -5,12 +5,11 @@ #ifndef MACE_DSP_HEXAGON_CONTROL_WRAPPER_H_ #define MACE_DSP_HEXAGON_CONTROL_WRAPPER_H_ -#include "mace/dsp/hexagon/hexagon_controller.h" -#include "mace/dsp/hexagon_nn_ops.h" -#include "mace/dsp/util/quantize.h" +#include "mace/core/runtime/hexagon/hexagon_controller.h" +#include "mace/core/runtime/hexagon/quantize.h" #include "mace/core/common.h" #include "mace/core/tensor.h" -#include "mace/proto/mace.pb.h" +#include "mace/core/public/mace.h" #include "mace/core/serializer.h" namespace mace { @@ -23,7 +22,6 @@ class HexagonControlWrapper { bool Init(); bool Finalize(); bool SetupGraph(const NetDef& net_def); - bool SetupGraph(const std::string &model_file); bool ExecuteGraph(const Tensor &input_tensor, Tensor *output_tensor); bool ExecuteGraphNew(const vector& input_tensors, vector *output_tensors); diff --git a/mace/dsp/hexagon/hexagon_controller.h b/mace/core/runtime/hexagon/hexagon_controller.h similarity index 80% rename from mace/dsp/hexagon/hexagon_controller.h rename to mace/core/runtime/hexagon/hexagon_controller.h index 3558f2aafe4a832c087af9a8f535ff78e5784e90..0e7d7596ca6e36218e7d6ed7e82112e63607dd97 100644 --- a/mace/dsp/hexagon/hexagon_controller.h +++ b/mace/core/runtime/hexagon/hexagon_controller.h @@ -1,7 +1,7 @@ #ifndef MACE_DSP_HEXAGON_DSP_CONTROLLER_H_ #define MACE_DSP_HEXAGON_DSP_CONTROLLER_H_ -#include "hexagon_nn.h" +#include "mace/core/runtime/hexagon/hexagon_nn.h" #ifdef __cplusplus extern "C" { diff --git a/mace/core/runtime/hexagon/hexagon_controller_dummy.cc b/mace/core/runtime/hexagon/hexagon_controller_dummy.cc new file mode 100644 index 0000000000000000000000000000000000000000..6077c37314b8e2c8663be6490cbb4cb764cf293c --- /dev/null +++ b/mace/core/runtime/hexagon/hexagon_controller_dummy.cc @@ -0,0 +1,37 @@ +// +// Copyright (c) 2018 XiaoMi All rights reserved. +// + +#include "mace/core/runtime/hexagon/hexagon_controller.h" +#include "mace/core/runtime/hexagon/hexagon_nn.h" + +int hexagon_controller_InitHexagonWithMaxAttributes(int enable_dcvs, + int bus_usage) { + return 0; +} + +int hexagon_controller_DeInitHexagon() { + return 0; +} + +__QAIC_HEADER_EXPORT int __QAIC_HEADER(hexagon_nn_config)(void) __QAIC_HEADER_ATTRIBUTE { return 0; } +__QAIC_HEADER_EXPORT int __QAIC_HEADER(hexagon_nn_init)(void) __QAIC_HEADER_ATTRIBUTE { return 0; } +__QAIC_HEADER_EXPORT int __QAIC_HEADER(hexagon_nn_set_debug_level)(hexagon_nn_nn_id id, int level) __QAIC_HEADER_ATTRIBUTE { return 0; } +__QAIC_HEADER_EXPORT int __QAIC_HEADER(hexagon_nn_snpprint)(hexagon_nn_nn_id id, unsigned char* buf, int bufLen) __QAIC_HEADER_ATTRIBUTE { return 0; } +__QAIC_HEADER_EXPORT int __QAIC_HEADER(hexagon_nn_getlog)(hexagon_nn_nn_id id, unsigned char* buf, int bufLen) __QAIC_HEADER_ATTRIBUTE { return 0; } +__QAIC_HEADER_EXPORT int __QAIC_HEADER(hexagon_nn_append_node)(hexagon_nn_nn_id id, unsigned int node_id, unsigned int operation, hexagon_nn_padding_type padding, const hexagon_nn_input* inputs, int inputsLen, const hexagon_nn_output* outputs, int outputsLen) __QAIC_HEADER_ATTRIBUTE { return 0; } +__QAIC_HEADER_EXPORT int __QAIC_HEADER(hexagon_nn_append_const_node)(hexagon_nn_nn_id id, unsigned int node_id, unsigned int batches, unsigned int height, unsigned int width, unsigned int depth, const unsigned char* data, int dataLen) __QAIC_HEADER_ATTRIBUTE { return 0; } +__QAIC_HEADER_EXPORT int __QAIC_HEADER(hexagon_nn_prepare)(hexagon_nn_nn_id id) __QAIC_HEADER_ATTRIBUTE { return 0; } +__QAIC_HEADER_EXPORT int __QAIC_HEADER(hexagon_nn_execute)(hexagon_nn_nn_id id, unsigned int batches_in, unsigned int height_in, unsigned int width_in, unsigned int depth_in, const unsigned char* data_in, int data_inLen, unsigned int* batches_out, unsigned int* height_out, unsigned int* width_out, unsigned int* depth_out, unsigned char* data_out, int data_outLen, unsigned int* data_len_out) __QAIC_HEADER_ATTRIBUTE { return 0; } +__QAIC_HEADER_EXPORT int __QAIC_HEADER(hexagon_nn_teardown)(hexagon_nn_nn_id id) __QAIC_HEADER_ATTRIBUTE { return 0; } +__QAIC_HEADER_EXPORT int __QAIC_HEADER(hexagon_nn_set_powersave_level)(unsigned int level) __QAIC_HEADER_ATTRIBUTE { return 0; } +__QAIC_HEADER_EXPORT int __QAIC_HEADER(hexagon_nn_get_perfinfo)(hexagon_nn_nn_id id, hexagon_nn_perfinfo* info_out, int info_outLen, unsigned int* n_items) __QAIC_HEADER_ATTRIBUTE { return 0; } +__QAIC_HEADER_EXPORT int __QAIC_HEADER(hexagon_nn_reset_perfinfo)(hexagon_nn_nn_id id, unsigned int event) __QAIC_HEADER_ATTRIBUTE { return 0; } +__QAIC_HEADER_EXPORT int __QAIC_HEADER(hexagon_nn_last_execution_cycles)(hexagon_nn_nn_id id, unsigned int* cycles_lo, unsigned int* cycles_hi) __QAIC_HEADER_ATTRIBUTE { return 0; } +__QAIC_HEADER_EXPORT int __QAIC_HEADER(hexagon_nn_version)(int* ver) __QAIC_HEADER_ATTRIBUTE { return 0; } +__QAIC_HEADER_EXPORT int __QAIC_HEADER(hexagon_nn_op_name_to_id)(const char* name, unsigned int* node_id) __QAIC_HEADER_ATTRIBUTE { return 0; } +__QAIC_HEADER_EXPORT int __QAIC_HEADER(hexagon_nn_op_id_to_name)(unsigned int node_id, char* name, int nameLen) __QAIC_HEADER_ATTRIBUTE { return 0; } +__QAIC_HEADER_EXPORT int __QAIC_HEADER(hexagon_nn_disable_dcvs)(void) __QAIC_HEADER_ATTRIBUTE { return 0; } +__QAIC_HEADER_EXPORT int __QAIC_HEADER(hexagon_nn_GetHexagonBinaryVersion)(int* ver) __QAIC_HEADER_ATTRIBUTE { return 0; } +__QAIC_HEADER_EXPORT int __QAIC_HEADER(hexagon_nn_PrintLog)(const unsigned char* buf, int bufLen) __QAIC_HEADER_ATTRIBUTE { return 0; } +__QAIC_HEADER_EXPORT int __QAIC_HEADER(hexagon_nn_execute_new)(hexagon_nn_nn_id id, const hexagon_nn_tensordef* inputs, int inputsLen, hexagon_nn_tensordef* outputs, int outputsLen) __QAIC_HEADER_ATTRIBUTE { return 0; } diff --git a/mace/dsp/hexagon/hexagon_nn.h b/mace/core/runtime/hexagon/hexagon_nn.h similarity index 100% rename from mace/dsp/hexagon/hexagon_nn.h rename to mace/core/runtime/hexagon/hexagon_nn.h diff --git a/mace/dsp/hexagon/libhexagon_controller.so b/mace/core/runtime/hexagon/libhexagon_controller.so similarity index 100% rename from mace/dsp/hexagon/libhexagon_controller.so rename to mace/core/runtime/hexagon/libhexagon_controller.so diff --git a/mace/dsp/util/quantize.cc b/mace/core/runtime/hexagon/quantize.cc similarity index 97% rename from mace/dsp/util/quantize.cc rename to mace/core/runtime/hexagon/quantize.cc index 4d3ccec8b52cf0da0abc622ed78d61e96fee561e..d99ca6e2ca5a21c34a004ade8264a0afbf0c5ca6 100644 --- a/mace/dsp/util/quantize.cc +++ b/mace/core/runtime/hexagon/quantize.cc @@ -2,7 +2,7 @@ // Copyright (c) 2017 XiaoMi All rights reserved. // -#include "mace/dsp/util/quantize.h" +#include "mace/core/runtime/hexagon/quantize.h" namespace mace { diff --git a/mace/dsp/util/quantize.h b/mace/core/runtime/hexagon/quantize.h similarity index 100% rename from mace/dsp/util/quantize.h rename to mace/core/runtime/hexagon/quantize.h diff --git a/mace/core/serializer.cc b/mace/core/serializer.cc index a0e3bc59de523641ca96f70b3526a103eadf80d4..5d24e9b7b24b682751c86e7032f2b847eca6df03 100644 --- a/mace/core/serializer.cc +++ b/mace/core/serializer.cc @@ -40,8 +40,8 @@ unique_ptr Serializer::Deserialize(const ConstTensor &proto, proto.data_size()); break; case DT_UINT8: - tensor->CopyWithCast( - reinterpret_cast(proto.data()), proto.data_size()); + tensor->Copy(reinterpret_cast(proto.data()), + proto.data_size()); break; case DT_INT16: tensor->CopyWithCast( diff --git a/mace/dsp/BUILD b/mace/dsp/BUILD deleted file mode 100644 index cbe9f834a40dba000bf7da74320dae422bdf99e1..0000000000000000000000000000000000000000 --- a/mace/dsp/BUILD +++ /dev/null @@ -1,84 +0,0 @@ -# Description: -# Mace dsp. -# -# Only suport arm-v7a now -# bazel build -c opt mace/dsp:dsp --crosstool_top=//external:android/crosstool --host_crosstool_top=@bazel_tools//tools/cpp:toolchain --cpu=armeabi-v7a --verbose_failures - -package( - default_visibility = ["//visibility:public"], -) - -licenses(["notice"]) # Apache 2.0 - -load("//mace:mace.bzl", "if_android") - -cc_library( - name = "dsp", - srcs = glob([ - "*.cc", - "hexagon/libhexagon_controller.so", - ], exclude = [ - "*_test.cc", - ]), - hdrs = glob([ - "*.h", - "hexagon/*.h", - ]), - copts = ["-std=c++11", "-D_GLIBCXX_USE_C99_MATH_TR1"], - deps = [ - "//mace/proto:cc_proto", - "//mace/core:core", - "//mace/dsp/util:util", - ], -) - -cc_test( - name = "dsp_test", - testonly = 1, - srcs = glob(["*_test.cc"]), - copts = ["-std=c++11", "-D_GLIBCXX_USE_C99_MATH_TR1"], - linkopts = if_android([ - "-ldl", - "-lm", - ]), - linkstatic = 1, - deps = [ - "@gtest//:gtest_main", - ":dsp", - ], -) - -cc_test( - name = "dsp_op_test", - testonly = 1, - srcs = glob(["test/*_test.cc"]), - copts = ["-std=c++11", "-D_GLIBCXX_USE_C99_MATH_TR1"], - linkopts = if_android([ - "-ldl", - "-lm", - ]), - linkstatic = 1, - deps = [ - "@gtest//:gtest_main", - ":dsp", - "//mace/kernels:kernels", - ], -) - -cc_binary( - name = "mace_dsp_run", - srcs = [ - "tool/mace_dsp_run.cc", - ], - copts = ["-std=c++11", "-D_GLIBCXX_USE_C99_MATH_TR1"], - linkopts = if_android([ - "-ldl", - "-lm", - ]), - linkstatic = 1, - deps = [ - ":dsp", - "//mace/kernels:kernels", - "//mace/utils:command_line_flags", - ], -) \ No newline at end of file diff --git a/mace/dsp/hexagon_control_wrapper_test.cc b/mace/dsp/hexagon_control_wrapper_test.cc deleted file mode 100644 index e7268db3d32401c2a53c0714258610b43b926a6f..0000000000000000000000000000000000000000 --- a/mace/dsp/hexagon_control_wrapper_test.cc +++ /dev/null @@ -1,96 +0,0 @@ -// -// Copyright (c) 2017 XiaoMi All rights reserved. -// - -#include "mace/dsp/hexagon_control_wrapper.h" -#include "mace/utils/logging.h" -#include "mace/utils/env_time.h" -#include "gtest/gtest.h" - -using namespace mace; - -TEST(HexagonControlerWrapper, InputFloat) { - testing::internal::LogToStderr(); - HexagonControlWrapper wrapper; - VLOG(0) << "version: " << wrapper.GetVersion(); - wrapper.Init(); - wrapper.SetDebugLevel(0); - wrapper.Config(); - VLOG(0) << wrapper.SetupGraph("quantized_icnet_dsp.pb"); - wrapper.PrintGraph(); - - Tensor input_tensor; - Tensor output_tensor; - input_tensor.Resize({1, 480, 480, 3}); - float *input_data = input_tensor.mutable_data(); - for (int i = 0; i < input_tensor.size(); ++i) { - input_data[i] = i % 256; - } - - wrapper.ResetPerfInfo(); - int64_t start_micros = utils::NowMicros(); - int round = 10; - for (int i = 0; i < round; ++i) { - VLOG(0) << wrapper.ExecuteGraph(input_tensor, &output_tensor); - } - int64_t end_micros = utils::NowMicros(); - VLOG(0) << "avg duration: " << (end_micros - start_micros) / (double)round - << " ms"; - - wrapper.GetPerfInfo(); - wrapper.PrintLog(); - - const float *output_data = output_tensor.data(); - VLOG(0) << output_tensor.size() << output_tensor.dtype(); - for (int i = 0; i < output_tensor.size(); ++i) { - std::cout << output_data[i] << " "; - } - std::cout << std::endl; - - VLOG(0) << wrapper.TeardownGraph(); - wrapper.Finalize(); -} - -TEST(HexagonControlerWrapper, PreQuantize) { - testing::internal::LogToStderr(); - HexagonControlWrapper wrapper; - VLOG(0) << "version: " << wrapper.GetVersion(); - wrapper.Init(); - wrapper.SetDebugLevel(0); - wrapper.Config(); - VLOG(0) << wrapper.SetupGraph("quantized_icnet_dsp_u8.pb"); - wrapper.PrintGraph(); - - Tensor input_tensor; - Tensor output_tensor; - input_tensor.Resize({1, 480, 480, 3}); - float *input_data = input_tensor.mutable_data(); - for (int i = 0; i < input_tensor.size(); ++i) { - input_data[i] = i % 256; - } - - wrapper.ResetPerfInfo(); - timeval tv1, tv2; - gettimeofday(&tv1, NULL); - int round = 10; - for (int i = 0; i < round; ++i) { - VLOG(0) << wrapper.ExecuteGraphPreQuantize(input_tensor, &output_tensor); - } - gettimeofday(&tv2, NULL); - VLOG(0) << "avg duration: " - << ((tv2.tv_sec - tv1.tv_sec) * 1000 + - (tv2.tv_usec - tv1.tv_usec) / 1000) / - round; - - wrapper.GetPerfInfo(); - wrapper.PrintLog(); - - const float *output_data = output_tensor.data(); - for (int i = 0; i < output_tensor.size(); ++i) { - std::cout << output_data[i] << " "; - } - std::cout << std::endl; - - VLOG(0) << wrapper.TeardownGraph(); - wrapper.Finalize(); -} diff --git a/mace/dsp/hexagon_nn_ops.h b/mace/dsp/hexagon_nn_ops.h deleted file mode 100644 index 9ec9e197086e4c63523ebe8e4b404ec1ba1e895b..0000000000000000000000000000000000000000 --- a/mace/dsp/hexagon_nn_ops.h +++ /dev/null @@ -1,59 +0,0 @@ -// -// Copyright (c) 2017 XiaoMi All rights reserved. -// - -#ifndef MACE_HEXAGON_NN_OPS_H_ -#define MACE_HEXAGON_NN_OPS_H_ - -#include "mace/utils/logging.h" -#include - -namespace mace { - -#define OP_INVALID -1 - -// The following macros are deprecated unless we found cache op meta in stub -// is necessary for performance or other causes. - -typedef enum op_type_enum { -#define DEF_OP(NAME, ...) OP_##NAME, - -#include "mace/dsp/ops.h" - NN_OPS_MAX - -#undef DEF_OP -} op_type; - - -#define DEF_OP(NAME,...) #NAME, -static const char *hexagon_nn_op_names[NN_OPS_MAX] = { -#include "mace/dsp/ops.h" -}; -#undef DEF_OP - - -class OpMap { - public: - void Init() { -#define DEF_OP(NAME) \ - op_map_[#NAME] = OP_##NAME; - -#include "mace/dsp/ops.h" - -#undef DEF_OP - } - - int GetOpId(std::string op_type) { - if (op_map_.find(op_type) != end(op_map_)) { - return op_map_[op_type]; - } else { - LOG(ERROR) << "DSP unsupoorted op type: " << op_type; - return OP_INVALID; - } - } - private: - std::unordered_map op_map_; -}; -} // namespace mace - -#endif // MACE_HEXAGON_NN_OPS_H_ diff --git a/mace/dsp/ops.h b/mace/dsp/ops.h deleted file mode 100644 index c031e4663c9f835f839555f5b1a5f2cd6c3488e4..0000000000000000000000000000000000000000 --- a/mace/dsp/ops.h +++ /dev/null @@ -1,180 +0,0 @@ -/* - * You probably want to - * - * ## ##### ##### - * # # # # # # - * # # # # # # - * ###### # # # # - * # # # # # # - * # # ##### ##### - * - * - * # # #### ##### ###### #### - * ## # # # # # # # - * # # # # # # # ##### #### - * # # # # # # # # # - * # ## # # # # # # # - * # # #### ##### ###### #### - * - * - * ## ##### - * # # # - * # # # - * ###### # - * # # # - * # # # - * - * - * ##### # # ###### - * # # # # - * # ###### ##### - * # # # # - * # # # # - * # # # ###### - * - * - * ###### # # ##### - * # ## # # # - * ##### # # # # # - * # # # # # # - * # # ## # # - * ###### # # ##### - * - * otherwise the interface becomes incompatible. - */ -DEF_OP(INPUT) -DEF_OP(OUTPUT) -DEF_OP(Nop) -DEF_OP(Const) -DEF_OP(Check) -DEF_OP(Close_f) -DEF_OP(Close_quint8) -DEF_OP(Close_q_quint8) -DEF_OP(Close_int32) -DEF_OP(Close_qint32) -DEF_OP(PPrint_8) -DEF_OP(PPrint_32) -DEF_OP(PPrint_f) -DEF_OP(PreFree) -DEF_OP(Flatten) - -#ifndef DEF_OP_WREF -#define DEF_OP_WREF(NAME) DEF_OP(NAME) DEF_OP(NAME##_ref) -#define __SELF_DEF_OP_WREF -#endif - -DEF_OP_WREF(QuantizedConv2d_8x8to32) -DEF_OP_WREF(QuantizedMatMul_8x8to32) -DEF_OP_WREF(QuantizeDownAndShrinkRange_32to8) -DEF_OP_WREF(QuantizedRelu_8) -DEF_OP_WREF(QuantizedReluX_8) -DEF_OP_WREF(QuantizedMaxPool_8) -DEF_OP_WREF(QuantizedAvgPool_8) -DEF_OP_WREF(QuantizedConcat_8) -DEF_OP_WREF(QuantizedBiasAdd_8p8to32) -DEF_OP_WREF(Min_f) -DEF_OP_WREF(Max_f) -DEF_OP_WREF(Quantize) -DEF_OP_WREF(Dequantize) -DEF_OP_WREF(Supernode_8x8p8to8) - -DEF_OP(QuantizedFlatten) -DEF_OP(Softmax_f) -DEF_OP(Conv2d_f) -DEF_OP(MatMul_f) -DEF_OP(Relu_f) -DEF_OP(ReluX_f) -DEF_OP(AvgPool_f) -DEF_OP(MaxPool_f) -DEF_OP(Concat_f) -DEF_OP(BiasAdd_f) -DEF_OP(LRN_f) - -DEF_OP(Variable) -DEF_OP(Assign) -DEF_OP(Reshape) -DEF_OP(QuantizedReshape) -DEF_OP(Tanh_f) -DEF_OP(Sigmoid_f) -DEF_OP(Slice_8) -DEF_OP(Slice_f) -DEF_OP(QuantizedSlice_8) -DEF_OP(Add_f) -DEF_OP(Mul_f) -DEF_OP(Minimum_f) -DEF_OP(Maximum_f) - -DEF_OP_WREF(Requantize_32to8) -DEF_OP_WREF(RequantizationRange_32) - -DEF_OP(Neg_f) -DEF_OP(Sub_f) -DEF_OP(AddN_f) -DEF_OP(Range_int32) -DEF_OP(Rank_int32) -DEF_OP(Transpose_int32) -DEF_OP(Transpose_f) -DEF_OP(InstanceNorm_f) -DEF_OP_WREF(QuantizedInstanceNorm_8) -DEF_OP(Sub_int32) -DEF_OP(Add_int32) -DEF_OP(Split_f) -DEF_OP(Dequantize_qint32_f) -DEF_OP(PRelu_f) -DEF_OP_WREF(QuantizedPRelu_8) -DEF_OP(Sum_f) -DEF_OP(Prod_f) -DEF_OP(Mul_int32) -DEF_OP(LogicalAnd_int32) -DEF_OP(LogicalOr_int32) -DEF_OP(LogicalXor_int32) -DEF_OP(Shape_int32) -DEF_OP(Pack_int32) -DEF_OP(MirrorPad_f) -DEF_OP(ResizeNearestNeighbor_f) -DEF_OP(StridedSlice_int32) -DEF_OP(StridedSlice_f) -DEF_OP(ExpandDims_int32) -DEF_OP(ExpandDims_f) - -DEF_OP(LogSoftmax_f) -DEF_OP(Split_int32) -DEF_OP(QuantizedSplit_8) - -DEF_OP(Deconv_f) -DEF_OP_WREF(QuantizedDeconv_8x8to32) - -DEF_OP_WREF(QuantizedMul_8x8to32) -DEF_OP_WREF(QuantizedAdd_8p8to32) -DEF_OP_WREF(QuantizedSigmoid_8) -DEF_OP_WREF(QuantizedTanh_8) -DEF_OP_WREF(QuantizedSoftmax_8) -DEF_OP_WREF(QuantizedLRN_8) -DEF_OP_WREF(QuantizedSub_8p8to32) -DEF_OP_WREF(QuantizedMaximum_8) -DEF_OP_WREF(QuantizedMinimum_8) - -DEF_OP(Pad_f) -DEF_OP(SpaceToBatchND_f) -DEF_OP(BatchToSpaceND_f) -DEF_OP(QuantizedSpaceToBatchND_8) -DEF_OP(QuantizedBatchToSpaceND_8) -DEF_OP(QuantizedPad_8) -DEF_OP(ResizeBilinear_f) -DEF_OP(QuantizedResizeBilinear_8) -DEF_OP(ConcatV2_f) -DEF_OP(ConcatV2_int32) -DEF_OP(Prod_int32) -DEF_OP(Slice_int32) - -DEF_OP(QuantizedAdd_8p8to8) - -DEF_OP_WREF(AutoQuantize) -DEF_OP_WREF(QuantizedDepthwiseConv2d_8x8to32) -DEF_OP(DepthwiseConv2d_f) - -#ifdef __SELF_DEF_OP_WREF -#undef __SELF_DEF_OP_WREF -#undef DEF_OP_WREF -#endif - diff --git a/mace/dsp/test/quantized_add_test.cc b/mace/dsp/test/quantized_add_test.cc deleted file mode 100644 index f30d8424f68c1613064f3c7531b9685a41a0f215..0000000000000000000000000000000000000000 --- a/mace/dsp/test/quantized_add_test.cc +++ /dev/null @@ -1,186 +0,0 @@ -// -// Copyright (c) 2017 XiaoMi All rights reserved. -// - -#include "mace/dsp/hexagon_control_wrapper.h" -#include "gtest/gtest.h" -#include - -using namespace mace; - -static NetDef BuildNetDef() { - NetDef net; - net.set_name("quantized_add_test"); - // input op - OperatorDef *input_op = net.add_op(); - input_op->set_name("input_node"); - input_op->set_type("INPUT"); - input_op->set_node_id(0); - input_op->set_padding(0); - input_op->add_out_max_byte_size(1000); - - // add op - OperatorDef *add_op = net.add_op(); - add_op->set_name("add"); - add_op->set_type("QuantizedAdd_8p8to8"); - add_op->set_node_id(1); - add_op->set_padding(0); - add_op->add_input("input_node"); - add_op->add_input("add_num"); - add_op->add_input("input_min"); - add_op->add_input("input_max"); - add_op->add_input("add_num_min"); - add_op->add_input("add_num_max"); - add_op->add_output("add:0"); - add_op->add_output("add:1"); - add_op->add_output("add:2"); - NodeInput *input_node_input = add_op->add_node_input(); - input_node_input->set_node_id(0); - input_node_input->set_output_port(0); - input_node_input = add_op->add_node_input(); - input_node_input->set_node_id(10); - input_node_input->set_output_port(0); - input_node_input = add_op->add_node_input(); - input_node_input->set_node_id(11); - input_node_input->set_output_port(0); - input_node_input = add_op->add_node_input(); - input_node_input->set_node_id(12); - input_node_input->set_output_port(0); - input_node_input = add_op->add_node_input(); - input_node_input->set_node_id(13); - input_node_input->set_output_port(0); - input_node_input = add_op->add_node_input(); - input_node_input->set_node_id(14); - input_node_input->set_output_port(0); - input_node_input = add_op->add_node_input(); - input_node_input->set_node_id(15); - input_node_input->set_output_port(0); - input_node_input = add_op->add_node_input(); - input_node_input->set_node_id(16); - input_node_input->set_output_port(0); - - add_op->add_out_max_byte_size(1000); - add_op->add_out_max_byte_size(1000); - add_op->add_out_max_byte_size(1000); - - // output op - OperatorDef *output_op = net.add_op(); - output_op->set_name("__output__"); - output_op->set_type("OUTPUT"); - output_op->set_op_id(2); - input_node_input = output_op->add_node_input(); - input_node_input->set_node_id(1); - input_node_input->set_output_port(0); - - // tensor - TensorProto *add_num_tensor = net.add_tensors(); - add_num_tensor->set_name("add_num"); - add_num_tensor->add_dims(3); - add_num_tensor->set_data_type(DataType::DT_UINT8); - add_num_tensor->set_node_id(10); - add_num_tensor->add_int32_data(0); - add_num_tensor->add_int32_data(127); - add_num_tensor->add_int32_data(255); - - TensorProto *input_min_tensor = net.add_tensors(); - input_min_tensor->set_name("input_min"); - input_min_tensor->add_dims(1); - input_min_tensor->set_data_type(DataType::DT_FLOAT); - input_min_tensor->set_node_id(11); - input_min_tensor->add_float_data(-100); - - TensorProto *input_max_tensor = net.add_tensors(); - input_max_tensor->set_name("input_max"); - input_max_tensor->add_dims(1); - input_max_tensor->set_data_type(DataType::DT_FLOAT); - input_max_tensor->set_node_id(12); - input_max_tensor->add_float_data(50.0); - - TensorProto *add_num_min_tensor = net.add_tensors(); - add_num_min_tensor->set_name("add_num_min"); - add_num_min_tensor->add_dims(1); - add_num_min_tensor->set_data_type(DataType::DT_FLOAT); - add_num_min_tensor->set_node_id(13); - add_num_min_tensor->add_float_data(0); - - TensorProto *add_num_max_tensor = net.add_tensors(); - add_num_max_tensor->set_name("add_num_max"); - add_num_max_tensor->add_dims(1); - add_num_max_tensor->set_data_type(DataType::DT_FLOAT); - add_num_max_tensor->set_node_id(14); - add_num_max_tensor->add_float_data(100.0); - - TensorProto *output_min_tensor = net.add_tensors(); - output_min_tensor->set_name("output_min"); - output_min_tensor->add_dims(1); - output_min_tensor->set_data_type(DataType::DT_FLOAT); - output_min_tensor->set_node_id(15); - output_min_tensor->add_float_data(-INFINITY); - - TensorProto *output_max_tensor = net.add_tensors(); - output_max_tensor->set_name("output_max"); - output_max_tensor->add_dims(1); - output_max_tensor->set_data_type(DataType::DT_FLOAT); - output_max_tensor->set_node_id(16); - output_max_tensor->add_float_data(INFINITY); - - - // input & output info - InputInfo *input_info = net.add_input_info(); - input_info->set_name("input_node"); - input_info->set_node_id(0); - input_info->add_dims(1); - input_info->add_dims(1); - input_info->add_dims(1); - input_info->add_dims(3); - input_info->set_data_type(DataType::DT_UINT8); - input_info->set_max_byte_size(1000); - OutputInfo *output_info = net.add_output_info(); - output_info->set_name("output_node"); - output_info->set_node_id(1); - output_info->add_dims(1); - output_info->add_dims(1); - output_info->add_dims(1); - output_info->add_dims(3); - output_info->set_data_type(DataType::DT_UINT8); - output_info->set_max_byte_size(1000); - - return net; -} - -TEST(QuantizedAddTest, QuantizedAdd) { - testing::internal::LogToStderr(); - HexagonControlWrapper wrapper; - wrapper.Init(); - wrapper.SetDebugLevel(10); - wrapper.Config(); - - NetDef net = BuildNetDef(); - wrapper.SetupGraph(net); - - Allocator *cpu_allocator = GetDeviceAllocator(DeviceType::CPU); - Tensor input_tensor(cpu_allocator, DT_UINT8); - Tensor output_tensor(cpu_allocator, DT_UINT8); - input_tensor.Resize({1, 1, 1, 3}); - output_tensor.Resize({1, 1, 1, 3}); - uint8_t *input_data = input_tensor.mutable_data(); - const uint8_t *output_data = output_tensor.data(); - // [-100.0 0 50] + [0.0, 50.0, 100.0] = [-100.0, 50.0, 150.0] - // s=0.5859, q0=170, [0, 170, 255] - // s=0.3906, q0=0, [0, 127, 255] - input_data[0] = 0; - input_data[1] = 170; - input_data[2] = 250; - - VLOG(0) << wrapper.ExecuteGraph(input_tensor, &output_tensor); - wrapper.PrintLog(); - - // -120.0~176.47, [17, 146, 229] - vector expected {17, 146, 229}; - for (int i = 0; i < output_tensor.size(); ++i) { - EXPECT_EQ(expected[i], output_data[i]); - } - - VLOG(0) << wrapper.TeardownGraph(); - wrapper.Finalize(); -} \ No newline at end of file diff --git a/mace/dsp/test/quantized_maxpool_test.cc b/mace/dsp/test/quantized_maxpool_test.cc deleted file mode 100644 index 897d1ac432e955ebc3337424e708ad62d28ab2d9..0000000000000000000000000000000000000000 --- a/mace/dsp/test/quantized_maxpool_test.cc +++ /dev/null @@ -1,231 +0,0 @@ -// -// Copyright (c) 2017 XiaoMi All rights reserved. -// - -#include "mace/dsp/hexagon_control_wrapper.h" -#include "mace/dsp/util/quantize.h" -#include "mace/kernels/conv_pool_2d_util.h" -#include "mace/kernels/pooling.h" -#include "gtest/gtest.h" - -using namespace mace; - -static NetDef BuildNetDef(const vector &input_shape, - const vector &output_shape, - const vector &filter_shape, - const vector &stride, - Padding padding, - float input_min, float input_max) { - NetDef net; - net.set_name("quantized_maxpool_test"); - // input op - OperatorDef *input_op = net.add_op(); - input_op->set_name("input_node"); - input_op->set_type("INPUT"); - input_op->set_node_id(0); - input_op->set_padding(0); - input_op->add_out_max_byte_size(1000); - - // maxpool op - OperatorDef *maxpool_op = net.add_op(); - maxpool_op->set_name("maxpool"); - maxpool_op->set_type("QuantizedMaxPool_8"); - maxpool_op->set_node_id(1); - if (padding == Padding::SAME) { - maxpool_op->set_padding(1); - } else { - maxpool_op->set_padding(2); - } - maxpool_op->add_input("input_node"); - maxpool_op->add_input("input_min"); - maxpool_op->add_input("input_max"); - maxpool_op->add_input("ksize"); - maxpool_op->add_input("stride"); - maxpool_op->add_output("maxpool:0"); - maxpool_op->add_output("maxpool:1"); - maxpool_op->add_output("maxpool:2"); - NodeInput *input_node_input = maxpool_op->add_node_input(); - input_node_input->set_node_id(0); - input_node_input->set_output_port(0); - input_node_input = maxpool_op->add_node_input(); - input_node_input->set_node_id(10); - input_node_input->set_output_port(0); - input_node_input = maxpool_op->add_node_input(); - input_node_input->set_node_id(11); - input_node_input = maxpool_op->add_node_input(); - input_node_input->set_node_id(12); - input_node_input->set_output_port(0); - input_node_input = maxpool_op->add_node_input(); - input_node_input->set_node_id(13); - input_node_input->set_output_port(0); - maxpool_op->add_out_max_byte_size(1000); - maxpool_op->add_out_max_byte_size(1000); - maxpool_op->add_out_max_byte_size(1000); - - // output op - OperatorDef *output_op = net.add_op(); - output_op->set_name("__output__"); - output_op->set_type("OUTPUT"); - output_op->set_op_id(2); - input_node_input = output_op->add_node_input(); - input_node_input->set_node_id(1); - input_node_input->set_output_port(0); - - // tensor - TensorProto *input_min_tensor = net.add_tensors(); - input_min_tensor->set_name("input_min"); - input_min_tensor->add_dims(1); - input_min_tensor->set_data_type(DataType::DT_FLOAT); - input_min_tensor->set_node_id(10); - input_min_tensor->add_float_data(input_min); - - TensorProto *input_max_tensor = net.add_tensors(); - input_max_tensor->set_name("input_max"); - input_max_tensor->add_dims(1); - input_max_tensor->set_data_type(DataType::DT_FLOAT); - input_max_tensor->set_node_id(11); - input_max_tensor->add_float_data(input_max); - - TensorProto *ksize_tensor = net.add_tensors(); - ksize_tensor->set_name("ksize"); - ksize_tensor->add_dims(filter_shape[0]); - ksize_tensor->add_dims(filter_shape[1]); - ksize_tensor->add_dims(filter_shape[2]); - ksize_tensor->add_dims(filter_shape[3]); - ksize_tensor->set_data_type(DataType::DT_INT32); - ksize_tensor->set_node_id(12); - - TensorProto *stride_tensor = net.add_tensors(); - stride_tensor->set_name("stride"); - stride_tensor->add_dims(stride[0]); - stride_tensor->add_dims(stride[1]); - stride_tensor->add_dims(stride[2]); - stride_tensor->add_dims(stride[3]); - stride_tensor->set_data_type(DataType::DT_INT32); - stride_tensor->set_node_id(13); - - // input & output info - InputInfo *input_info = net.add_input_info(); - input_info->set_name("input_node"); - input_info->set_node_id(0); - input_info->add_dims(input_shape[0]); - input_info->add_dims(input_shape[1]); - input_info->add_dims(input_shape[2]); - input_info->add_dims(input_shape[3]); - input_info->set_data_type(DataType::DT_UINT8); - input_info->set_max_byte_size(1000); - OutputInfo *output_info = net.add_output_info(); - output_info->set_name("output_node"); - output_info->set_node_id(1); - output_info->add_dims(output_shape[0]); - output_info->add_dims(output_shape[1]); - output_info->add_dims(output_shape[2]); - output_info->add_dims(output_shape[3]); - output_info->set_data_type(DataType::DT_UINT8); - output_info->set_max_byte_size(1000); - - return net; -} - -static void TestQuantizedMaxPool(Padding padding, int kernel_size, int stride_size) { - testing::internal::LogToStderr(); - HexagonControlWrapper wrapper; - wrapper.Init(); - wrapper.SetDebugLevel(3); - wrapper.Config(); - - vector input_shape {1, 10, 10, 3}; - vector filter_shape {1, 3, 3, 1}; - vector stride {1, stride_size, stride_size, 1}; - vector dilation {1, 1, 1, 1}; - vector output_shape {input_shape[0], 0, 0, input_shape[3]}; - vector padding_size(2); - switch (padding) { - case VALID: - output_shape[1] = (input_shape[1] - filter_shape[1]) / stride[1] + 1; - output_shape[2] = (input_shape[2] - filter_shape[2]) / stride[2] + 1; - break; - case SAME: - output_shape[1] = (input_shape[1] - 1) / stride[1] + 1; - output_shape[2] = (input_shape[2] - 1) / stride[2] + 1; - break; - default: - ASSERT_TRUE(0); - } - for (int i = 0; i < 4; ++i) { - VLOG(0) << "! shape = " << output_shape[i]; - } - NetDef net = BuildNetDef(input_shape, output_shape, filter_shape, stride, - padding, -50, 100); - VLOG(0) << wrapper.SetupGraph(net); - - Allocator *cpu_allocator = GetDeviceAllocator(DeviceType::CPU); - Tensor original_tensor(cpu_allocator, DT_FLOAT); - Tensor input_tensor(cpu_allocator, DT_UINT8); - Tensor output_tensor(cpu_allocator, DT_UINT8); - Tensor dequantized_output_tensor(cpu_allocator, DT_FLOAT); - original_tensor.Resize(input_shape); - input_tensor.Resize(input_shape); - output_tensor.Resize(output_shape); - dequantized_output_tensor.Resize(output_shape); - float *original_data = original_tensor.mutable_data(); - uint8_t *input_data = input_tensor.mutable_data(); - const uint8_t *output_data = output_tensor.data(); - float *dequantized_output_data = dequantized_output_tensor.mutable_data(); - - std::random_device rd; - std::mt19937 gen(rd()); - std::normal_distribution nd(-50, 50); - std::generate(original_data, original_data + original_tensor.size(), - [&gen, &nd] { - return nd(gen); - }); - - Quantizer quantizer; - float min_in, min_out; - quantizer.Quantize(original_tensor, &input_tensor, &min_in, &min_out); - VLOG(0) << wrapper.ExecuteGraph(input_tensor, &output_tensor); - quantizer.DeQuantize(output_tensor, min_in, min_out, &dequantized_output_tensor); - - // debug original float input data - for (index_t c = 0; c < input_shape[3]; ++c) { - for (index_t i = 0; i < input_shape[1]; ++i) { - for (index_t j = 0; j < input_shape[2]; ++j) { - std::cout << original_data[i * input_shape[2] * input_shape[3] + j * input_shape[3] + c] << " "; - } - std::cout << std::endl; - } - std::cout << std::endl << std::endl; - } - - // debug dequantized float output data - for (index_t c = 0; c < output_shape[3]; ++c) { - for (index_t i = 0; i < output_shape[1]; ++i) { - for (index_t j = 0; j < output_shape[2]; ++j) { - std::cout << dequantized_output_data[i * output_shape[2] * output_shape[3] + j * output_shape[3] + c] << " "; - } - std::cout << std::endl; - } - std::cout << std::endl << std::endl; - } - - wrapper.PrintLog(); - VLOG(0) << wrapper.TeardownGraph(); - wrapper.Finalize(); -} - -TEST(QuantizedMaxPoolTest, QuantizedMaxPoolValidStride1) { - TestQuantizedMaxPool(Padding::VALID, 3, 1); -} - -TEST(QuantizedMaxPoolTest, QuantizedMaxPoolValidStride2) { - TestQuantizedMaxPool(Padding::VALID, 3, 2); -} - -TEST(QuantizedMaxPoolTest, QuantizedMaxPoolSameStride1) { - TestQuantizedMaxPool(Padding::SAME, 3, 1); -} - -TEST(QuantizedMaxPoolTest, QuantizedMaxPoolSameStride2) { - TestQuantizedMaxPool(Padding::SAME, 3, 2); -} \ No newline at end of file diff --git a/mace/dsp/test/quantized_relu_test.cc b/mace/dsp/test/quantized_relu_test.cc deleted file mode 100644 index 685be71d9b51ab3a833579654da568552d310a0f..0000000000000000000000000000000000000000 --- a/mace/dsp/test/quantized_relu_test.cc +++ /dev/null @@ -1,131 +0,0 @@ -// -// Copyright (c) 2017 XiaoMi All rights reserved. -// - -#include "mace/dsp/hexagon_control_wrapper.h" -#include "gtest/gtest.h" - -using namespace mace; - -static NetDef BuildNetDef() { - NetDef net; - net.set_name("quantized_relu_test"); - // input op - OperatorDef *input_op = net.add_op(); - input_op->set_name("input_node"); - input_op->set_type("INPUT"); - input_op->set_node_id(0); - input_op->set_padding(0); - input_op->add_out_max_byte_size(1000); - - // relu op - OperatorDef *relu_op = net.add_op(); - relu_op->set_name("relu"); - relu_op->set_type("QuantizedRelu_8"); - relu_op->set_node_id(1); - relu_op->set_padding(0); - relu_op->add_input("input_node"); - relu_op->add_input("input_min"); - relu_op->add_input("input_max"); - relu_op->add_output("relu:0"); - relu_op->add_output("relu:1"); - relu_op->add_output("relu:2"); - NodeInput *input_node_input = relu_op->add_node_input(); - input_node_input->set_node_id(0); - input_node_input->set_output_port(0); - input_node_input = relu_op->add_node_input(); - input_node_input->set_node_id(10); - input_node_input->set_output_port(0); - input_node_input = relu_op->add_node_input(); - input_node_input->set_node_id(11); - input_node_input->set_output_port(0); - relu_op->add_out_max_byte_size(1000); - relu_op->add_out_max_byte_size(1000); - relu_op->add_out_max_byte_size(1000); - - // output op - OperatorDef *output_op = net.add_op(); - output_op->set_name("__output__"); - output_op->set_type("OUTPUT"); - output_op->set_op_id(2); - input_node_input = output_op->add_node_input(); - input_node_input->set_node_id(1); - input_node_input->set_output_port(0); - - // tensor - TensorProto *input_min_tensor = net.add_tensors(); - input_min_tensor->set_name("input_min"); - input_min_tensor->add_dims(1); - input_min_tensor->set_data_type(DataType::DT_FLOAT); - input_min_tensor->set_node_id(10); - input_min_tensor->add_float_data(-100.0); - - TensorProto *input_max_tensor = net.add_tensors(); - input_max_tensor->set_name("input_max"); - input_max_tensor->add_dims(1); - input_max_tensor->set_data_type(DataType::DT_FLOAT); - input_max_tensor->set_node_id(11); - input_max_tensor->add_float_data(100.0); - - // input & output info - InputInfo *input_info = net.add_input_info(); - input_info->set_name("input_node"); - input_info->set_node_id(0); - input_info->add_dims(1); - input_info->add_dims(1); - input_info->add_dims(1); - input_info->add_dims(5); - input_info->set_data_type(DataType::DT_UINT8); - input_info->set_max_byte_size(1000); - OutputInfo *output_info = net.add_output_info(); - output_info->set_name("output_node"); - output_info->set_node_id(1); - output_info->add_dims(1); - output_info->add_dims(1); - output_info->add_dims(1); - output_info->add_dims(5); - output_info->set_data_type(DataType::DT_UINT8); - output_info->set_max_byte_size(1000); - - return net; -} - -TEST(QuantizedReluTest, QuantizedRelu) { - testing::internal::LogToStderr(); - HexagonControlWrapper wrapper; - wrapper.Init(); - wrapper.SetDebugLevel(3); - wrapper.Config(); - - NetDef net = BuildNetDef(); - wrapper.SetupGraph(net); - - Allocator *cpu_allocator = GetDeviceAllocator(DeviceType::CPU); - Tensor input_tensor(cpu_allocator, DT_UINT8); - Tensor output_tensor(cpu_allocator, DT_UINT8); - input_tensor.Resize({1, 1, 1, 5}); - output_tensor.Resize({1, 1, 1, 5}); - uint8_t *input_data = input_tensor.mutable_data(); - const uint8_t *output_data = output_tensor.data(); - // -100.0 -50.0 0 50.0 100.0 -> s=0.782, q0=int(-fmin/s)=128, - // q=q0+f/s -> 0, 64, 128, 192, 256 - input_data[0] = 0; - input_data[1] = 64; - input_data[2] = 128; - input_data[3] = 192; - input_data[4] = 255; - - // 0, 0, 0, 50, 100 -> s=0.782, q0=128 - // q -> 128, 128, 128, 192, 255 - - VLOG(0) << wrapper.ExecuteGraph(input_tensor, &output_tensor); - wrapper.PrintLog(); - - vector expected {128, 128, 128, 192, 255}; - for (int i = 0; i < output_tensor.size(); ++i) { - EXPECT_EQ(expected[i], output_data[i]); - } - - VLOG(0) << wrapper.TeardownGraph(); - wrapper.Finalize(); -} \ No newline at end of file diff --git a/mace/dsp/test/quantized_resize_bilinear_test.cc b/mace/dsp/test/quantized_resize_bilinear_test.cc deleted file mode 100644 index 12a2f8d34b94aeb21c8d3507be4ab4b545c26c2e..0000000000000000000000000000000000000000 --- a/mace/dsp/test/quantized_resize_bilinear_test.cc +++ /dev/null @@ -1,145 +0,0 @@ -// -// Copyright (c) 2017 XiaoMi All rights reserved. -// - -#include "mace/dsp/hexagon_control_wrapper.h" -#include "gtest/gtest.h" - -#define RESIZE_BILINEAR_TEST_CHANNELS 128 -using namespace mace; - -static NetDef BuildNetDef() { - std::cout << "Building net def" << std::endl; - NetDef net; - net.set_name("quantized_resize_bilinear_test"); - // input op - OperatorDef *input_op = net.add_op(); - input_op->set_name("input_node"); - input_op->set_type("INPUT"); - input_op->set_node_id(0); - input_op->set_padding(0); - input_op->add_out_max_byte_size(1200); - - // relu op - OperatorDef *resize_bilinear_op = net.add_op(); - resize_bilinear_op->set_name("relu"); - resize_bilinear_op->set_type("QuantizedResizeBilinear_8"); - resize_bilinear_op->set_node_id(1); - resize_bilinear_op->set_padding(0); - resize_bilinear_op->add_input("input_node"); - resize_bilinear_op->add_input("new_dim"); - resize_bilinear_op->add_input("input_min"); - resize_bilinear_op->add_input("input_max"); - resize_bilinear_op->add_output("resize_bilinear:0"); - resize_bilinear_op->add_output("resize_bilinear:1"); - resize_bilinear_op->add_output("resize_bilinear:2"); - - NodeInput *input_node_input = resize_bilinear_op->add_node_input(); - input_node_input->set_node_id(0); - input_node_input->set_output_port(0); - input_node_input = resize_bilinear_op->add_node_input(); - input_node_input->set_node_id(10); - input_node_input->set_output_port(0); - input_node_input = resize_bilinear_op->add_node_input(); - input_node_input->set_node_id(11); - input_node_input->set_output_port(0); - input_node_input = resize_bilinear_op->add_node_input(); - input_node_input->set_node_id(12); - input_node_input->set_output_port(0); - resize_bilinear_op->add_out_max_byte_size(1200); - resize_bilinear_op->add_out_max_byte_size(1000); - resize_bilinear_op->add_out_max_byte_size(1000); - - // output op - OperatorDef *output_op = net.add_op(); - output_op->set_name("__output__"); - output_op->set_type("OUTPUT"); - output_op->set_op_id(2); - input_node_input = output_op->add_node_input(); - input_node_input->set_node_id(1); - input_node_input->set_output_port(0); - - // tensor - TensorProto *new_dim_tensor = net.add_tensors(); - new_dim_tensor->set_name("new_dim"); - new_dim_tensor->add_dims(2); - new_dim_tensor->set_data_type(DataType::DT_INT32); - new_dim_tensor->set_node_id(10); - new_dim_tensor->add_int32_data(2); - new_dim_tensor->add_int32_data(2); - - TensorProto *input_min_tensor = net.add_tensors(); - input_min_tensor->set_name("input_min"); - input_min_tensor->add_dims(1); - input_min_tensor->set_data_type(DataType::DT_FLOAT); - input_min_tensor->set_node_id(11); - input_min_tensor->add_float_data(-100.0); - - TensorProto *input_max_tensor = net.add_tensors(); - input_max_tensor->set_name("input_max"); - input_max_tensor->add_dims(1); - input_max_tensor->set_data_type(DataType::DT_FLOAT); - input_max_tensor->set_node_id(12); - input_max_tensor->add_float_data(100.0); - - // input & output info - InputInfo *input_info = net.add_input_info(); - input_info->set_name("input_node"); - input_info->set_node_id(0); - input_info->add_dims(1); - input_info->add_dims(3); - input_info->add_dims(3); - input_info->add_dims(RESIZE_BILINEAR_TEST_CHANNELS); - input_info->set_data_type(DataType::DT_UINT8); - input_info->set_max_byte_size(1200); - OutputInfo *output_info = net.add_output_info(); - output_info->set_name("output_node"); - output_info->set_node_id(1); - output_info->add_dims(1); - output_info->add_dims(2); - output_info->add_dims(2); - output_info->add_dims(RESIZE_BILINEAR_TEST_CHANNELS); - output_info->set_data_type(DataType::DT_UINT8); - output_info->set_max_byte_size(1200); - - return net; -} - -TEST(QuantizedResizeBilinearTest, QuantizedResizeBilinear) { - testing::internal::LogToStderr(); - HexagonControlWrapper wrapper; - wrapper.Init(); - wrapper.SetDebugLevel(3); - wrapper.Config(); - - NetDef net = BuildNetDef(); - wrapper.SetupGraph(net); - - Allocator *cpu_allocator = GetDeviceAllocator(DeviceType::CPU); - Tensor input_tensor(cpu_allocator, DT_UINT8); - Tensor output_tensor(cpu_allocator, DT_UINT8); - input_tensor.Resize({1, 3, 3, RESIZE_BILINEAR_TEST_CHANNELS}); - output_tensor.Resize({1, 2, 2, RESIZE_BILINEAR_TEST_CHANNELS}); - uint8_t *input_data = input_tensor.mutable_data(); - const uint8_t *output_data = output_tensor.data(); - - for (int wh = 0; wh < 9; ++wh) { - for (int c = 0; c < RESIZE_BILINEAR_TEST_CHANNELS; ++c) { - input_data[wh * RESIZE_BILINEAR_TEST_CHANNELS + c] = 9 - wh; - } - } - - VLOG(0) << wrapper.ExecuteGraph(input_tensor, &output_tensor); - wrapper.PrintLog(); - - vector expected {9, 8, 5, 3}; - for (int i = 0; i < 4; ++i) { - for (int c = 0; c < RESIZE_BILINEAR_TEST_CHANNELS; ++c) - EXPECT_EQ(expected[i], - output_data[i * RESIZE_BILINEAR_TEST_CHANNELS + c]); - } - std::cout << std::endl; - - VLOG(0) << wrapper.TeardownGraph(); - wrapper.Finalize(); -} \ No newline at end of file diff --git a/mace/dsp/test/supernode_test.cc b/mace/dsp/test/supernode_test.cc deleted file mode 100644 index 634795ecf5beb6adbb3f255666537897be960436..0000000000000000000000000000000000000000 --- a/mace/dsp/test/supernode_test.cc +++ /dev/null @@ -1,240 +0,0 @@ -// -// Copyright (c) 2017 XiaoMi All rights reserved. -// - -#include "mace/dsp/hexagon_control_wrapper.h" -#include "gtest/gtest.h" -#include - -using namespace mace; - -static NetDef BuildNetDef() { - NetDef net; - net.set_name("supernode_test"); - // input op - OperatorDef *input_op = net.add_op(); - input_op->set_name("input_node"); - input_op->set_type("INPUT"); - input_op->set_node_id(0); - input_op->set_padding(0); - input_op->add_out_max_byte_size(1000); - - // add op - OperatorDef *supernode_op = net.add_op(); - supernode_op->set_name("supernode"); - supernode_op->set_type("Supernode_8x8p8to8"); - supernode_op->set_node_id(1); - supernode_op->set_padding(0); - supernode_op->add_input("input_node"); - supernode_op->add_input("filter_tensor"); - supernode_op->add_input("input_min"); - supernode_op->add_input("input_max"); - supernode_op->add_input("filter_min"); - supernode_op->add_input("filter_max"); - supernode_op->add_input("stride_tensor"); - supernode_op->add_input("bias_tensor"); - supernode_op->add_input("bias_min"); - supernode_op->add_input("bias_max"); - supernode_op->add_input("min_val"); - supernode_op->add_input("max_val"); - supernode_op->add_output("supernode:0"); - supernode_op->add_output("supernode:1"); - supernode_op->add_output("supernode:2"); - NodeInput *input_node_input = supernode_op->add_node_input(); - input_node_input->set_node_id(0); - input_node_input->set_output_port(0); - input_node_input = supernode_op->add_node_input(); - input_node_input->set_node_id(10); - input_node_input->set_output_port(0); - input_node_input = supernode_op->add_node_input(); - input_node_input->set_node_id(11); - input_node_input->set_output_port(0); - input_node_input = supernode_op->add_node_input(); - input_node_input->set_node_id(12); - input_node_input->set_output_port(0); - input_node_input = supernode_op->add_node_input(); - input_node_input->set_node_id(13); - input_node_input->set_output_port(0); - input_node_input = supernode_op->add_node_input(); - input_node_input->set_node_id(14); - input_node_input->set_output_port(0); - input_node_input = supernode_op->add_node_input(); - input_node_input->set_node_id(15); - input_node_input->set_output_port(0); - input_node_input = supernode_op->add_node_input(); - input_node_input->set_node_id(16); - input_node_input->set_output_port(0); - input_node_input = supernode_op->add_node_input(); - input_node_input->set_node_id(17); - input_node_input->set_output_port(0); - input_node_input = supernode_op->add_node_input(); - input_node_input->set_node_id(18); - input_node_input->set_output_port(0); - input_node_input = supernode_op->add_node_input(); - input_node_input->set_node_id(19); - input_node_input->set_output_port(0); - input_node_input = supernode_op->add_node_input(); - input_node_input->set_node_id(20); - input_node_input->set_output_port(0); - - supernode_op->add_out_max_byte_size(1000); - supernode_op->add_out_max_byte_size(1000); - supernode_op->add_out_max_byte_size(1000); - - // output op - OperatorDef *output_op = net.add_op(); - output_op->set_name("__output__"); - output_op->set_type("OUTPUT"); - output_op->set_op_id(2); - input_node_input = output_op->add_node_input(); - input_node_input->set_node_id(1); - input_node_input->set_output_port(0); - - // tensor - TensorProto *filter_tensor = net.add_tensors(); - filter_tensor->set_name("filter_tensor"); - filter_tensor->add_dims(2); - filter_tensor->add_dims(2); - filter_tensor->add_dims(1); - filter_tensor->add_dims(1); - filter_tensor->set_data_type(DataType::DT_UINT8); - filter_tensor->set_node_id(10); - filter_tensor->add_int32_data(0); - filter_tensor->add_int32_data(127); - filter_tensor->add_int32_data(127); - filter_tensor->add_int32_data(255); - - TensorProto *input_min_tensor = net.add_tensors(); - input_min_tensor->set_name("input_min"); - input_min_tensor->add_dims(1); - input_min_tensor->set_data_type(DataType::DT_FLOAT); - input_min_tensor->set_node_id(11); - input_min_tensor->add_float_data(-10.0); - - TensorProto *input_max_tensor = net.add_tensors(); - input_max_tensor->set_name("input_max"); - input_max_tensor->add_dims(1); - input_max_tensor->set_data_type(DataType::DT_FLOAT); - input_max_tensor->set_node_id(12); - input_max_tensor->add_float_data(10.0787402); - - TensorProto *filter_min_tensor = net.add_tensors(); - filter_min_tensor->set_name("filter_min"); - filter_min_tensor->add_dims(1); - filter_min_tensor->set_data_type(DataType::DT_FLOAT); - filter_min_tensor->set_node_id(13); - filter_min_tensor->add_float_data(-10.0); - - TensorProto *filter_max_tensor = net.add_tensors(); - filter_max_tensor->set_name("filter_max"); - filter_max_tensor->add_dims(1); - filter_max_tensor->set_data_type(DataType::DT_FLOAT); - filter_max_tensor->set_node_id(14); - filter_max_tensor->add_float_data(10.0787402); - - TensorProto *stride_tensor = net.add_tensors(); - stride_tensor->set_name("stride"); - stride_tensor->add_dims(1); - stride_tensor->add_dims(2); - stride_tensor->add_dims(2); - stride_tensor->add_dims(1); - stride_tensor->set_data_type(DataType::DT_INT32); - stride_tensor->set_node_id(15); - - TensorProto *bias_tensor = net.add_tensors(); - bias_tensor->set_name("bias"); - bias_tensor->add_dims(1); - bias_tensor->set_data_type(DataType::DT_UINT8); - bias_tensor->set_node_id(16); - bias_tensor->add_int32_data(127); - - TensorProto *bias_min_tensor = net.add_tensors(); - bias_min_tensor->set_name("bias_min"); - bias_min_tensor->add_dims(1); - bias_min_tensor->set_data_type(DataType::DT_FLOAT); - bias_min_tensor->set_node_id(17); - bias_min_tensor->add_float_data(-10.0); - - TensorProto *bias_max_tensor = net.add_tensors(); - bias_max_tensor->set_name("bias_max"); - bias_max_tensor->add_dims(1); - bias_max_tensor->set_data_type(DataType::DT_FLOAT); - bias_max_tensor->set_node_id(18); - bias_max_tensor->add_float_data(10.0787402); - - TensorProto *min_val_tensor = net.add_tensors(); - min_val_tensor->set_name("min_val"); - min_val_tensor->add_dims(1); - min_val_tensor->set_data_type(DataType::DT_FLOAT); - min_val_tensor->set_node_id(19); - min_val_tensor->add_float_data(-INFINITY); - - TensorProto *max_val_tensor = net.add_tensors(); - max_val_tensor->set_name("max_val"); - max_val_tensor->add_dims(1); - max_val_tensor->set_data_type(DataType::DT_FLOAT); - max_val_tensor->set_node_id(20); - max_val_tensor->add_float_data(INFINITY); - - // input & output info - InputInfo *input_info = net.add_input_info(); - input_info->set_name("input_node"); - input_info->set_node_id(0); - input_info->add_dims(1); - input_info->add_dims(4); - input_info->add_dims(4); - input_info->add_dims(1); - input_info->set_data_type(DataType::DT_UINT8); - input_info->set_max_byte_size(1000); - OutputInfo *output_info = net.add_output_info(); - output_info->set_name("output_node"); - output_info->set_node_id(1); - output_info->add_dims(1); - output_info->add_dims(2); - output_info->add_dims(2); - output_info->add_dims(1); - output_info->set_data_type(DataType::DT_UINT8); - output_info->set_max_byte_size(1000); - - return net; -} - -TEST(SupernodeTest, Supernode) { - testing::internal::LogToStderr(); - HexagonControlWrapper wrapper; - wrapper.Init(); - wrapper.SetDebugLevel(10); - wrapper.Config(); - - NetDef net = BuildNetDef(); - wrapper.SetupGraph(net); - - Allocator *cpu_allocator = GetDeviceAllocator(DeviceType::CPU); - Tensor input_tensor(cpu_allocator, DT_UINT8); - Tensor output_tensor(cpu_allocator, DT_UINT8); - input_tensor.Resize({1, 4, 4, 1}); - output_tensor.Resize({1, 2, 2, 1}); - uint8_t *input_data = input_tensor.mutable_data(); - const uint8_t *output_data = output_tensor.data(); - // input: [[-10, ..], [-5.03937, ..], [0, ..], [5.03937, ..]] - // filt: [[-10, 0], [0, 10.07874]] - // bias: 0.0 - for (int h = 0; h < 4; ++h) { - for (int w = 0; w < 4; ++w) - input_data[h * 4 + w] = (uint8_t)((h == 0) ? 0 : h * 64 - 1); - } - - VLOG(0) << wrapper.ExecuteGraph(input_tensor, &output_tensor); - wrapper.PrintLog(); - - // expect out: [[49.2095, 49.2095], [50.7905, 50.7905]] - // with output range(-0.5, 64.0), quantize to [[196, 196], [203, 203]] - vector expected {196, 196, 203, 203}; - for (int i = 0; i < output_tensor.size(); ++i) { - EXPECT_EQ(expected[i], output_data[i]); - } - std::cout << std::endl; - - VLOG(0) << wrapper.TeardownGraph(); - wrapper.Finalize(); -} diff --git a/mace/dsp/tool/mace_dsp_run.cc b/mace/dsp/tool/mace_dsp_run.cc deleted file mode 100644 index 2c8e7afae7acfccec8418b4b63da75d0a6d47af4..0000000000000000000000000000000000000000 --- a/mace/dsp/tool/mace_dsp_run.cc +++ /dev/null @@ -1,109 +0,0 @@ -// -// Copyright (c) 2017 XiaoMi All rights reserved. -// - -/** - * Usage: - * mace_dsp_run --model=mobi_mace.pb \ - * --input_shape=1,3,224,224 \ - * --input_file=input_data \ - * --output_file=mace.out - */ -#include -#include -#include "mace/dsp/hexagon_control_wrapper.h" -#include "mace/core/net.h" -#include "mace/utils/command_line_flags.h" - -using namespace std; -using namespace mace; - -void ParseShape(const string &str, vector *shape) { - string tmp = str; - while (!tmp.empty()) { - int dim = atoi(tmp.data()); - shape->push_back(dim); - size_t next_offset = tmp.find(","); - if (next_offset == string::npos) { - break; - } else { - tmp = tmp.substr(next_offset + 1); - } - } -} - -int main(int argc, char **argv) { - string model_file; - string input_shape; - string input_file; - string output_file; - int round = 1; - - std::vector flag_list = { - Flag("model", &model_file, "model file name"), - Flag("input_shape", &input_shape, "input shape, separated by comma"), - Flag("input_file", &input_file, "input file name"), - Flag("output_file", &output_file, "output file name"), - Flag("round", &round, "round"), - }; - - string usage = Flags::Usage(argv[0], flag_list); - const bool parse_result = Flags::Parse(&argc, argv, flag_list); - - if (!parse_result) { - LOG(ERROR) << usage; - return -1; - } - - VLOG(0) << "model: " << model_file << std::endl - << "input_shape: " << input_shape << std::endl - << "input_file: " << input_file << std::endl - << "output_file: " << output_file << std::endl - << "round: " << round << std::endl; - - vector shape; - ParseShape(input_shape, &shape); - - // load input - Tensor input_tensor; - input_tensor.Resize(shape); - float *input_data = input_tensor.mutable_data(); - ifstream in_file(input_file, ios::in | ios::binary); - in_file.read(reinterpret_cast(input_data), - input_tensor.size() * sizeof(float)); - in_file.close(); - - // execute - HexagonControlWrapper wrapper; - VLOG(0) << "version: " << wrapper.GetVersion(); - wrapper.Init(); - wrapper.SetDebugLevel(0); - wrapper.Config(); - VLOG(0) << wrapper.SetupGraph(model_file); - wrapper.PrintGraph(); - - Tensor output_tensor; - timeval tv1, tv2; - gettimeofday(&tv1, NULL); - for (int i = 0; i < round; ++i) { - VLOG(0) << wrapper.ExecuteGraph(input_tensor, &output_tensor); - } - gettimeofday(&tv2, NULL); - cout << "avg duration: " - << ((tv2.tv_sec - tv1.tv_sec) * 1000 + - (tv2.tv_usec - tv1.tv_usec) / 1000) / - round - << endl; - - wrapper.GetPerfInfo(); - wrapper.PrintLog(); - VLOG(0) << wrapper.TeardownGraph(); - wrapper.Finalize(); - - // save output - ofstream out_file(output_file, ios::binary); - out_file.write((const char *) (output_tensor.data()), - output_tensor.size() * sizeof(float)); - out_file.flush(); - out_file.close(); -} \ No newline at end of file diff --git a/mace/dsp/util/BUILD b/mace/dsp/util/BUILD deleted file mode 100644 index df699bb8eda504f256d0367dd50088ffd2f7d7d1..0000000000000000000000000000000000000000 --- a/mace/dsp/util/BUILD +++ /dev/null @@ -1,43 +0,0 @@ -# Description: -# Mace dsp util. -# - -package( - default_visibility = ["//visibility:public"], -) - -licenses(["notice"]) # Apache 2.0 - -load("//mace:mace.bzl", "if_android") - -cc_library( - name = "util", - srcs = glob([ - "*.cc", - ], exclude = [ - "*_test.cc", - ]), - hdrs = glob([ - "*.h", - ]), - copts = ["-std=c++11", "-D_GLIBCXX_USE_C99_MATH_TR1"], - deps = [ - "//mace/core:core", - ], -) - -cc_test( - name = "util_test", - testonly = 1, - srcs = glob(["*_test.cc"]), - copts = ["-std=c++11", "-D_GLIBCXX_USE_C99_MATH_TR1"], - linkopts = if_android([ - "-ldl", - "-lm", - ]), - linkstatic = 1, - deps = [ - "@gtest//:gtest_main", - ":util", - ], -) diff --git a/mace/dsp/util/quantize_test.cc b/mace/dsp/util/quantize_test.cc deleted file mode 100644 index aca1eadb98bd675b123967ca88638299a487ef74..0000000000000000000000000000000000000000 --- a/mace/dsp/util/quantize_test.cc +++ /dev/null @@ -1,45 +0,0 @@ -// -// Copyright (c) 2017 XiaoMi All rights reserved. -// - -#include "mace/dsp/util/quantize.h" -#include "gtest/gtest.h" - -using namespace mace; - -TEST(QuantizeTest, QuantizeAndDequantize) { - testing::internal::LogToStderr(); - - Quantizer quantizer; - Allocator *allocator = GetDeviceAllocator(DeviceType::CPU); - - Tensor in_tensor(allocator, DataType::DT_FLOAT); - vector shape {5}; - in_tensor.Resize(shape); - float *in_data = in_tensor.mutable_data(); - in_data[0] = -50.0; - in_data[1] = -10.0; - in_data[2] = 20.0; - in_data[3] = 80.0; - in_data[4] = 100.0; - - Tensor quantized_tensor(allocator, DataType::DT_UINT8); - quantized_tensor.Resize(shape); - uint8_t *quantized_data = quantized_tensor.mutable_data(); - float min_out, max_out; - quantizer.Quantize(in_tensor, -50.0, 100.0, &quantized_tensor, &min_out, &max_out); - vector expected_quantize_data {0, 68, 119, 220, 254}; - for (int i = 0; i < quantized_tensor.size(); ++i) { - EXPECT_EQ(expected_quantize_data[i], quantized_data[i]); - } - - Tensor dequantized_tensor(allocator, DataType::DT_FLOAT); - dequantized_tensor.Resize(shape); - float *dequantized_data = dequantized_tensor.mutable_data(); - quantizer.DeQuantize(quantized_tensor, min_out, max_out, &dequantized_tensor); - - for (int i = 0; i < dequantized_tensor.size(); ++i) { - EXPECT_NEAR(in_data[i], dequantized_data[i], 1); - } -} - diff --git a/mace/examples/mace_run.cc b/mace/examples/mace_run.cc index 3cfbcbf98bf3c215c7c9041eb8d2237f980c0673..bc548ff5c9fa6ee6fb043bf52ea7dd1a2d89b8a2 100644 --- a/mace/examples/mace_run.cc +++ b/mace/examples/mace_run.cc @@ -52,6 +52,8 @@ DeviceType ParseDeviceType(const string &device_str) { return DeviceType::NEON; } else if (device_str.compare("OPENCL") == 0) { return DeviceType::OPENCL; + } else if (device_str.compare("HEXAGON") == 0) { + return DeviceType ::HEXAGON; } else { return DeviceType::CPU; } @@ -105,9 +107,6 @@ struct mallinfo LogMallinfoChange(struct mallinfo prev) { } int main(int argc, char **argv) { - string model_file; - string input_node; - string output_node; string input_shape; string output_shape; string input_file; @@ -117,9 +116,6 @@ int main(int argc, char **argv) { int malloc_check_cycle = -1; std::vector flag_list = { - Flag("model", &model_file, "model file name"), - Flag("input", &input_node, "input node"), - Flag("output", &output_node, "output node"), Flag("input_shape", &input_shape, "input shape, separated by comma"), Flag("output_shape", &output_shape, "output shape, separated by comma"), Flag("input_file", &input_file, "input file name"), @@ -140,9 +136,6 @@ int main(int argc, char **argv) { VLOG(0) << "mace version: " << MaceVersion() << std::endl << "mace git version: " << MaceGitVersion() << std::endl - << "model: " << model_file << std::endl - << "input: " << input_node << std::endl - << "output: " << output_node << std::endl << "input_shape: " << input_shape << std::endl << "output_shape: " << output_shape << std::endl << "input_file: " << input_file << std::endl diff --git a/mace/python/tools/mace_pb2.py b/mace/python/tools/mace_pb2.py new file mode 100755 index 0000000000000000000000000000000000000000..dd3d25b6e564aa0adcb6b66555d33db4051ae5f3 --- /dev/null +++ b/mace/python/tools/mace_pb2.py @@ -0,0 +1,896 @@ +# Generated by the protocol buffer compiler. DO NOT EDIT! +# source: mace/proto/mace.proto + +import sys +_b=sys.version_info[0]<3 and (lambda x:x) or (lambda x:x.encode('latin1')) +from google.protobuf.internal import enum_type_wrapper +from google.protobuf import descriptor as _descriptor +from google.protobuf import message as _message +from google.protobuf import reflection as _reflection +from google.protobuf import symbol_database as _symbol_database +from google.protobuf import descriptor_pb2 +# @@protoc_insertion_point(imports) + +_sym_db = _symbol_database.Default() + + + + +DESCRIPTOR = _descriptor.FileDescriptor( + name='mace/proto/mace.proto', + package='mace', + syntax='proto2', + serialized_pb=_b('\n\x15mace/proto/mace.proto\x12\x04mace\"\xf0\x01\n\x0bTensorProto\x12\x0c\n\x04\x64ims\x18\x01 \x03(\x03\x12+\n\tdata_type\x18\x02 \x01(\x0e\x32\x0e.mace.DataType:\x08\x44T_FLOAT\x12\x16\n\nfloat_data\x18\x03 \x03(\x02\x42\x02\x10\x01\x12\x16\n\nint32_data\x18\x04 \x03(\x05\x42\x02\x10\x01\x12\x11\n\tbyte_data\x18\x05 \x01(\x0c\x12\x13\n\x0bstring_data\x18\x06 \x03(\x0c\x12\x17\n\x0b\x64ouble_data\x18\t \x03(\x01\x42\x02\x10\x01\x12\x16\n\nint64_data\x18\n \x03(\x03\x42\x02\x10\x01\x12\x0c\n\x04name\x18\x07 \x01(\t\x12\x0f\n\x07node_id\x18\x64 \x01(\r\"h\n\x08\x41rgument\x12\x0c\n\x04name\x18\x01 \x01(\t\x12\t\n\x01\x66\x18\x02 \x01(\x02\x12\t\n\x01i\x18\x03 \x01(\x03\x12\t\n\x01s\x18\x04 \x01(\x0c\x12\x0e\n\x06\x66loats\x18\x05 \x03(\x02\x12\x0c\n\x04ints\x18\x06 \x03(\x03\x12\x0f\n\x07strings\x18\x07 \x03(\x0c\"1\n\tNodeInput\x12\x0f\n\x07node_id\x18\x01 \x01(\x05\x12\x13\n\x0boutput_port\x18\x02 \x01(\x05\"\x1b\n\x0bOutputShape\x12\x0c\n\x04\x64ims\x18\x01 \x03(\x03\"\xb8\x02\n\x0bOperatorDef\x12\r\n\x05input\x18\x01 \x03(\t\x12\x0e\n\x06output\x18\x02 \x03(\t\x12\x0c\n\x04name\x18\x03 \x01(\t\x12\x0c\n\x04type\x18\x04 \x01(\t\x12\x1b\n\x03\x61rg\x18\x05 \x03(\x0b\x32\x0e.mace.Argument\x12\'\n\x0coutput_shape\x18\x06 \x03(\x0b\x32\x11.mace.OutputShape\x12#\n\x0boutput_type\x18\x07 \x03(\x0e\x32\x0e.mace.DataType\x12\x12\n\x06mem_id\x18\n \x01(\x05:\x02-1\x12\x0f\n\x07node_id\x18\x64 \x01(\r\x12\r\n\x05op_id\x18\x65 \x01(\r\x12\x0f\n\x07padding\x18\x66 \x01(\r\x12#\n\nnode_input\x18g \x03(\x0b\x32\x0f.mace.NodeInput\x12\x19\n\x11out_max_byte_size\x18h \x03(\x05\"3\n\x0bMemoryBlock\x12\x0e\n\x06mem_id\x18\x01 \x01(\x05\x12\t\n\x01x\x18\x02 \x01(\r\x12\t\n\x01y\x18\x03 \x01(\r\"3\n\x0bMemoryArena\x12$\n\tmem_block\x18\x01 \x03(\x0b\x32\x11.mace.MemoryBlock\"|\n\tInputInfo\x12\x0c\n\x04name\x18\x01 \x01(\t\x12\x0f\n\x07node_id\x18\x02 \x01(\x05\x12\x0c\n\x04\x64ims\x18\x03 \x03(\x05\x12\x15\n\rmax_byte_size\x18\x04 \x01(\x05\x12+\n\tdata_type\x18\x05 \x01(\x0e\x32\x0e.mace.DataType:\x08\x44T_FLOAT\"}\n\nOutputInfo\x12\x0c\n\x04name\x18\x01 \x01(\t\x12\x0f\n\x07node_id\x18\x02 \x01(\x05\x12\x0c\n\x04\x64ims\x18\x03 \x03(\x05\x12\x15\n\rmax_byte_size\x18\x04 \x01(\x05\x12+\n\tdata_type\x18\x05 \x01(\x0e\x32\x0e.mace.DataType:\x08\x44T_FLOAT\"\xf9\x01\n\x06NetDef\x12\x0c\n\x04name\x18\x01 \x01(\t\x12\x1d\n\x02op\x18\x02 \x03(\x0b\x32\x11.mace.OperatorDef\x12\x0f\n\x07version\x18\x03 \x01(\t\x12\x1b\n\x03\x61rg\x18\x04 \x03(\x0b\x32\x0e.mace.Argument\x12\"\n\x07tensors\x18\x05 \x03(\x0b\x32\x11.mace.TensorProto\x12$\n\tmem_arena\x18\n \x01(\x0b\x32\x11.mace.MemoryArena\x12#\n\ninput_info\x18\x64 \x03(\x0b\x32\x0f.mace.InputInfo\x12%\n\x0boutput_info\x18\x65 \x03(\x0b\x32\x10.mace.OutputInfo*\x1f\n\x07NetMode\x12\x08\n\x04INIT\x10\x00\x12\n\n\x06NORMAL\x10\x01*+\n\nDeviceType\x12\x07\n\x03\x43PU\x10\x00\x12\x08\n\x04NEON\x10\x01\x12\n\n\x06OPENCL\x10\x02*\xc3\x01\n\x08\x44\x61taType\x12\x0e\n\nDT_INVALID\x10\x00\x12\x0c\n\x08\x44T_FLOAT\x10\x01\x12\r\n\tDT_DOUBLE\x10\x02\x12\x0c\n\x08\x44T_INT32\x10\x03\x12\x0c\n\x08\x44T_UINT8\x10\x04\x12\x0c\n\x08\x44T_INT16\x10\x05\x12\x0b\n\x07\x44T_INT8\x10\x06\x12\r\n\tDT_STRING\x10\x07\x12\x0c\n\x08\x44T_INT64\x10\x08\x12\r\n\tDT_UINT16\x10\t\x12\x0b\n\x07\x44T_BOOL\x10\n\x12\x0b\n\x07\x44T_HALF\x10\x13\x12\r\n\tDT_UINT32\x10\x16') +) + +_NETMODE = _descriptor.EnumDescriptor( + name='NetMode', + full_name='mace.NetMode', + filename=None, + file=DESCRIPTOR, + values=[ + _descriptor.EnumValueDescriptor( + name='INIT', index=0, number=0, + options=None, + type=None), + _descriptor.EnumValueDescriptor( + name='NORMAL', index=1, number=1, + options=None, + type=None), + ], + containing_type=None, + options=None, + serialized_start=1386, + serialized_end=1417, +) +_sym_db.RegisterEnumDescriptor(_NETMODE) + +NetMode = enum_type_wrapper.EnumTypeWrapper(_NETMODE) +_DEVICETYPE = _descriptor.EnumDescriptor( + name='DeviceType', + full_name='mace.DeviceType', + filename=None, + file=DESCRIPTOR, + values=[ + _descriptor.EnumValueDescriptor( + name='CPU', index=0, number=0, + options=None, + type=None), + _descriptor.EnumValueDescriptor( + name='NEON', index=1, number=1, + options=None, + type=None), + _descriptor.EnumValueDescriptor( + name='OPENCL', index=2, number=2, + options=None, + type=None), + ], + containing_type=None, + options=None, + serialized_start=1419, + serialized_end=1462, +) +_sym_db.RegisterEnumDescriptor(_DEVICETYPE) + +DeviceType = enum_type_wrapper.EnumTypeWrapper(_DEVICETYPE) +_DATATYPE = _descriptor.EnumDescriptor( + name='DataType', + full_name='mace.DataType', + filename=None, + file=DESCRIPTOR, + values=[ + _descriptor.EnumValueDescriptor( + name='DT_INVALID', index=0, number=0, + options=None, + type=None), + _descriptor.EnumValueDescriptor( + name='DT_FLOAT', index=1, number=1, + options=None, + type=None), + _descriptor.EnumValueDescriptor( + name='DT_DOUBLE', index=2, number=2, + options=None, + type=None), + _descriptor.EnumValueDescriptor( + name='DT_INT32', index=3, number=3, + options=None, + type=None), + _descriptor.EnumValueDescriptor( + name='DT_UINT8', index=4, number=4, + options=None, + type=None), + _descriptor.EnumValueDescriptor( + name='DT_INT16', index=5, number=5, + options=None, + type=None), + _descriptor.EnumValueDescriptor( + name='DT_INT8', index=6, number=6, + options=None, + type=None), + _descriptor.EnumValueDescriptor( + name='DT_STRING', index=7, number=7, + options=None, + type=None), + _descriptor.EnumValueDescriptor( + name='DT_INT64', index=8, number=8, + options=None, + type=None), + _descriptor.EnumValueDescriptor( + name='DT_UINT16', index=9, number=9, + options=None, + type=None), + _descriptor.EnumValueDescriptor( + name='DT_BOOL', index=10, number=10, + options=None, + type=None), + _descriptor.EnumValueDescriptor( + name='DT_HALF', index=11, number=19, + options=None, + type=None), + _descriptor.EnumValueDescriptor( + name='DT_UINT32', index=12, number=22, + options=None, + type=None), + ], + containing_type=None, + options=None, + serialized_start=1465, + serialized_end=1660, +) +_sym_db.RegisterEnumDescriptor(_DATATYPE) + +DataType = enum_type_wrapper.EnumTypeWrapper(_DATATYPE) +INIT = 0 +NORMAL = 1 +CPU = 0 +NEON = 1 +OPENCL = 2 +DT_INVALID = 0 +DT_FLOAT = 1 +DT_DOUBLE = 2 +DT_INT32 = 3 +DT_UINT8 = 4 +DT_INT16 = 5 +DT_INT8 = 6 +DT_STRING = 7 +DT_INT64 = 8 +DT_UINT16 = 9 +DT_BOOL = 10 +DT_HALF = 19 +DT_UINT32 = 22 + + + +_TENSORPROTO = _descriptor.Descriptor( + name='TensorProto', + full_name='mace.TensorProto', + filename=None, + file=DESCRIPTOR, + containing_type=None, + fields=[ + _descriptor.FieldDescriptor( + name='dims', full_name='mace.TensorProto.dims', index=0, + number=1, type=3, cpp_type=2, label=3, + has_default_value=False, default_value=[], + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None), + _descriptor.FieldDescriptor( + name='data_type', full_name='mace.TensorProto.data_type', index=1, + number=2, type=14, cpp_type=8, label=1, + has_default_value=True, default_value=1, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None), + _descriptor.FieldDescriptor( + name='float_data', full_name='mace.TensorProto.float_data', index=2, + number=3, type=2, cpp_type=6, label=3, + has_default_value=False, default_value=[], + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=_descriptor._ParseOptions(descriptor_pb2.FieldOptions(), _b('\020\001'))), + _descriptor.FieldDescriptor( + name='int32_data', full_name='mace.TensorProto.int32_data', index=3, + number=4, type=5, cpp_type=1, label=3, + has_default_value=False, default_value=[], + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=_descriptor._ParseOptions(descriptor_pb2.FieldOptions(), _b('\020\001'))), + _descriptor.FieldDescriptor( + name='byte_data', full_name='mace.TensorProto.byte_data', index=4, + number=5, type=12, cpp_type=9, label=1, + has_default_value=False, default_value=_b(""), + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None), + _descriptor.FieldDescriptor( + name='string_data', full_name='mace.TensorProto.string_data', index=5, + number=6, type=12, cpp_type=9, label=3, + has_default_value=False, default_value=[], + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None), + _descriptor.FieldDescriptor( + name='double_data', full_name='mace.TensorProto.double_data', index=6, + number=9, type=1, cpp_type=5, label=3, + has_default_value=False, default_value=[], + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=_descriptor._ParseOptions(descriptor_pb2.FieldOptions(), _b('\020\001'))), + _descriptor.FieldDescriptor( + name='int64_data', full_name='mace.TensorProto.int64_data', index=7, + number=10, type=3, cpp_type=2, label=3, + has_default_value=False, default_value=[], + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=_descriptor._ParseOptions(descriptor_pb2.FieldOptions(), _b('\020\001'))), + _descriptor.FieldDescriptor( + name='name', full_name='mace.TensorProto.name', index=8, + number=7, type=9, cpp_type=9, label=1, + has_default_value=False, default_value=_b("").decode('utf-8'), + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None), + _descriptor.FieldDescriptor( + name='node_id', full_name='mace.TensorProto.node_id', index=9, + number=100, type=13, cpp_type=3, label=1, + has_default_value=False, default_value=0, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None), + ], + extensions=[ + ], + nested_types=[], + enum_types=[ + ], + options=None, + is_extendable=False, + syntax='proto2', + extension_ranges=[], + oneofs=[ + ], + serialized_start=32, + serialized_end=272, +) + + +_ARGUMENT = _descriptor.Descriptor( + name='Argument', + full_name='mace.Argument', + filename=None, + file=DESCRIPTOR, + containing_type=None, + fields=[ + _descriptor.FieldDescriptor( + name='name', full_name='mace.Argument.name', index=0, + number=1, type=9, cpp_type=9, label=1, + has_default_value=False, default_value=_b("").decode('utf-8'), + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None), + _descriptor.FieldDescriptor( + name='f', full_name='mace.Argument.f', index=1, + number=2, type=2, cpp_type=6, label=1, + has_default_value=False, default_value=float(0), + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None), + _descriptor.FieldDescriptor( + name='i', full_name='mace.Argument.i', index=2, + number=3, type=3, cpp_type=2, label=1, + has_default_value=False, default_value=0, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None), + _descriptor.FieldDescriptor( + name='s', full_name='mace.Argument.s', index=3, + number=4, type=12, cpp_type=9, label=1, + has_default_value=False, default_value=_b(""), + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None), + _descriptor.FieldDescriptor( + name='floats', full_name='mace.Argument.floats', index=4, + number=5, type=2, cpp_type=6, label=3, + has_default_value=False, default_value=[], + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None), + _descriptor.FieldDescriptor( + name='ints', full_name='mace.Argument.ints', index=5, + number=6, type=3, cpp_type=2, label=3, + has_default_value=False, default_value=[], + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None), + _descriptor.FieldDescriptor( + name='strings', full_name='mace.Argument.strings', index=6, + number=7, type=12, cpp_type=9, label=3, + has_default_value=False, default_value=[], + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None), + ], + extensions=[ + ], + nested_types=[], + enum_types=[ + ], + options=None, + is_extendable=False, + syntax='proto2', + extension_ranges=[], + oneofs=[ + ], + serialized_start=274, + serialized_end=378, +) + + +_NODEINPUT = _descriptor.Descriptor( + name='NodeInput', + full_name='mace.NodeInput', + filename=None, + file=DESCRIPTOR, + containing_type=None, + fields=[ + _descriptor.FieldDescriptor( + name='node_id', full_name='mace.NodeInput.node_id', index=0, + number=1, type=5, cpp_type=1, label=1, + has_default_value=False, default_value=0, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None), + _descriptor.FieldDescriptor( + name='output_port', full_name='mace.NodeInput.output_port', index=1, + number=2, type=5, cpp_type=1, label=1, + has_default_value=False, default_value=0, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None), + ], + extensions=[ + ], + nested_types=[], + enum_types=[ + ], + options=None, + is_extendable=False, + syntax='proto2', + extension_ranges=[], + oneofs=[ + ], + serialized_start=380, + serialized_end=429, +) + + +_OUTPUTSHAPE = _descriptor.Descriptor( + name='OutputShape', + full_name='mace.OutputShape', + filename=None, + file=DESCRIPTOR, + containing_type=None, + fields=[ + _descriptor.FieldDescriptor( + name='dims', full_name='mace.OutputShape.dims', index=0, + number=1, type=3, cpp_type=2, label=3, + has_default_value=False, default_value=[], + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None), + ], + extensions=[ + ], + nested_types=[], + enum_types=[ + ], + options=None, + is_extendable=False, + syntax='proto2', + extension_ranges=[], + oneofs=[ + ], + serialized_start=431, + serialized_end=458, +) + + +_OPERATORDEF = _descriptor.Descriptor( + name='OperatorDef', + full_name='mace.OperatorDef', + filename=None, + file=DESCRIPTOR, + containing_type=None, + fields=[ + _descriptor.FieldDescriptor( + name='input', full_name='mace.OperatorDef.input', index=0, + number=1, type=9, cpp_type=9, label=3, + has_default_value=False, default_value=[], + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None), + _descriptor.FieldDescriptor( + name='output', full_name='mace.OperatorDef.output', index=1, + number=2, type=9, cpp_type=9, label=3, + has_default_value=False, default_value=[], + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None), + _descriptor.FieldDescriptor( + name='name', full_name='mace.OperatorDef.name', index=2, + number=3, type=9, cpp_type=9, label=1, + has_default_value=False, default_value=_b("").decode('utf-8'), + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None), + _descriptor.FieldDescriptor( + name='type', full_name='mace.OperatorDef.type', index=3, + number=4, type=9, cpp_type=9, label=1, + has_default_value=False, default_value=_b("").decode('utf-8'), + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None), + _descriptor.FieldDescriptor( + name='arg', full_name='mace.OperatorDef.arg', index=4, + number=5, type=11, cpp_type=10, label=3, + has_default_value=False, default_value=[], + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None), + _descriptor.FieldDescriptor( + name='output_shape', full_name='mace.OperatorDef.output_shape', index=5, + number=6, type=11, cpp_type=10, label=3, + has_default_value=False, default_value=[], + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None), + _descriptor.FieldDescriptor( + name='output_type', full_name='mace.OperatorDef.output_type', index=6, + number=7, type=14, cpp_type=8, label=3, + has_default_value=False, default_value=[], + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None), + _descriptor.FieldDescriptor( + name='mem_id', full_name='mace.OperatorDef.mem_id', index=7, + number=10, type=5, cpp_type=1, label=1, + has_default_value=True, default_value=-1, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None), + _descriptor.FieldDescriptor( + name='node_id', full_name='mace.OperatorDef.node_id', index=8, + number=100, type=13, cpp_type=3, label=1, + has_default_value=False, default_value=0, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None), + _descriptor.FieldDescriptor( + name='op_id', full_name='mace.OperatorDef.op_id', index=9, + number=101, type=13, cpp_type=3, label=1, + has_default_value=False, default_value=0, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None), + _descriptor.FieldDescriptor( + name='padding', full_name='mace.OperatorDef.padding', index=10, + number=102, type=13, cpp_type=3, label=1, + has_default_value=False, default_value=0, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None), + _descriptor.FieldDescriptor( + name='node_input', full_name='mace.OperatorDef.node_input', index=11, + number=103, type=11, cpp_type=10, label=3, + has_default_value=False, default_value=[], + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None), + _descriptor.FieldDescriptor( + name='out_max_byte_size', full_name='mace.OperatorDef.out_max_byte_size', index=12, + number=104, type=5, cpp_type=1, label=3, + has_default_value=False, default_value=[], + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None), + ], + extensions=[ + ], + nested_types=[], + enum_types=[ + ], + options=None, + is_extendable=False, + syntax='proto2', + extension_ranges=[], + oneofs=[ + ], + serialized_start=461, + serialized_end=773, +) + + +_MEMORYBLOCK = _descriptor.Descriptor( + name='MemoryBlock', + full_name='mace.MemoryBlock', + filename=None, + file=DESCRIPTOR, + containing_type=None, + fields=[ + _descriptor.FieldDescriptor( + name='mem_id', full_name='mace.MemoryBlock.mem_id', index=0, + number=1, type=5, cpp_type=1, label=1, + has_default_value=False, default_value=0, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None), + _descriptor.FieldDescriptor( + name='x', full_name='mace.MemoryBlock.x', index=1, + number=2, type=13, cpp_type=3, label=1, + has_default_value=False, default_value=0, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None), + _descriptor.FieldDescriptor( + name='y', full_name='mace.MemoryBlock.y', index=2, + number=3, type=13, cpp_type=3, label=1, + has_default_value=False, default_value=0, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None), + ], + extensions=[ + ], + nested_types=[], + enum_types=[ + ], + options=None, + is_extendable=False, + syntax='proto2', + extension_ranges=[], + oneofs=[ + ], + serialized_start=775, + serialized_end=826, +) + + +_MEMORYARENA = _descriptor.Descriptor( + name='MemoryArena', + full_name='mace.MemoryArena', + filename=None, + file=DESCRIPTOR, + containing_type=None, + fields=[ + _descriptor.FieldDescriptor( + name='mem_block', full_name='mace.MemoryArena.mem_block', index=0, + number=1, type=11, cpp_type=10, label=3, + has_default_value=False, default_value=[], + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None), + ], + extensions=[ + ], + nested_types=[], + enum_types=[ + ], + options=None, + is_extendable=False, + syntax='proto2', + extension_ranges=[], + oneofs=[ + ], + serialized_start=828, + serialized_end=879, +) + + +_INPUTINFO = _descriptor.Descriptor( + name='InputInfo', + full_name='mace.InputInfo', + filename=None, + file=DESCRIPTOR, + containing_type=None, + fields=[ + _descriptor.FieldDescriptor( + name='name', full_name='mace.InputInfo.name', index=0, + number=1, type=9, cpp_type=9, label=1, + has_default_value=False, default_value=_b("").decode('utf-8'), + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None), + _descriptor.FieldDescriptor( + name='node_id', full_name='mace.InputInfo.node_id', index=1, + number=2, type=5, cpp_type=1, label=1, + has_default_value=False, default_value=0, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None), + _descriptor.FieldDescriptor( + name='dims', full_name='mace.InputInfo.dims', index=2, + number=3, type=5, cpp_type=1, label=3, + has_default_value=False, default_value=[], + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None), + _descriptor.FieldDescriptor( + name='max_byte_size', full_name='mace.InputInfo.max_byte_size', index=3, + number=4, type=5, cpp_type=1, label=1, + has_default_value=False, default_value=0, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None), + _descriptor.FieldDescriptor( + name='data_type', full_name='mace.InputInfo.data_type', index=4, + number=5, type=14, cpp_type=8, label=1, + has_default_value=True, default_value=1, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None), + ], + extensions=[ + ], + nested_types=[], + enum_types=[ + ], + options=None, + is_extendable=False, + syntax='proto2', + extension_ranges=[], + oneofs=[ + ], + serialized_start=881, + serialized_end=1005, +) + + +_OUTPUTINFO = _descriptor.Descriptor( + name='OutputInfo', + full_name='mace.OutputInfo', + filename=None, + file=DESCRIPTOR, + containing_type=None, + fields=[ + _descriptor.FieldDescriptor( + name='name', full_name='mace.OutputInfo.name', index=0, + number=1, type=9, cpp_type=9, label=1, + has_default_value=False, default_value=_b("").decode('utf-8'), + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None), + _descriptor.FieldDescriptor( + name='node_id', full_name='mace.OutputInfo.node_id', index=1, + number=2, type=5, cpp_type=1, label=1, + has_default_value=False, default_value=0, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None), + _descriptor.FieldDescriptor( + name='dims', full_name='mace.OutputInfo.dims', index=2, + number=3, type=5, cpp_type=1, label=3, + has_default_value=False, default_value=[], + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None), + _descriptor.FieldDescriptor( + name='max_byte_size', full_name='mace.OutputInfo.max_byte_size', index=3, + number=4, type=5, cpp_type=1, label=1, + has_default_value=False, default_value=0, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None), + _descriptor.FieldDescriptor( + name='data_type', full_name='mace.OutputInfo.data_type', index=4, + number=5, type=14, cpp_type=8, label=1, + has_default_value=True, default_value=1, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None), + ], + extensions=[ + ], + nested_types=[], + enum_types=[ + ], + options=None, + is_extendable=False, + syntax='proto2', + extension_ranges=[], + oneofs=[ + ], + serialized_start=1007, + serialized_end=1132, +) + + +_NETDEF = _descriptor.Descriptor( + name='NetDef', + full_name='mace.NetDef', + filename=None, + file=DESCRIPTOR, + containing_type=None, + fields=[ + _descriptor.FieldDescriptor( + name='name', full_name='mace.NetDef.name', index=0, + number=1, type=9, cpp_type=9, label=1, + has_default_value=False, default_value=_b("").decode('utf-8'), + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None), + _descriptor.FieldDescriptor( + name='op', full_name='mace.NetDef.op', index=1, + number=2, type=11, cpp_type=10, label=3, + has_default_value=False, default_value=[], + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None), + _descriptor.FieldDescriptor( + name='version', full_name='mace.NetDef.version', index=2, + number=3, type=9, cpp_type=9, label=1, + has_default_value=False, default_value=_b("").decode('utf-8'), + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None), + _descriptor.FieldDescriptor( + name='arg', full_name='mace.NetDef.arg', index=3, + number=4, type=11, cpp_type=10, label=3, + has_default_value=False, default_value=[], + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None), + _descriptor.FieldDescriptor( + name='tensors', full_name='mace.NetDef.tensors', index=4, + number=5, type=11, cpp_type=10, label=3, + has_default_value=False, default_value=[], + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None), + _descriptor.FieldDescriptor( + name='mem_arena', full_name='mace.NetDef.mem_arena', index=5, + number=10, type=11, cpp_type=10, label=1, + has_default_value=False, default_value=None, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None), + _descriptor.FieldDescriptor( + name='input_info', full_name='mace.NetDef.input_info', index=6, + number=100, type=11, cpp_type=10, label=3, + has_default_value=False, default_value=[], + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None), + _descriptor.FieldDescriptor( + name='output_info', full_name='mace.NetDef.output_info', index=7, + number=101, type=11, cpp_type=10, label=3, + has_default_value=False, default_value=[], + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None), + ], + extensions=[ + ], + nested_types=[], + enum_types=[ + ], + options=None, + is_extendable=False, + syntax='proto2', + extension_ranges=[], + oneofs=[ + ], + serialized_start=1135, + serialized_end=1384, +) + +_TENSORPROTO.fields_by_name['data_type'].enum_type = _DATATYPE +_OPERATORDEF.fields_by_name['arg'].message_type = _ARGUMENT +_OPERATORDEF.fields_by_name['output_shape'].message_type = _OUTPUTSHAPE +_OPERATORDEF.fields_by_name['output_type'].enum_type = _DATATYPE +_OPERATORDEF.fields_by_name['node_input'].message_type = _NODEINPUT +_MEMORYARENA.fields_by_name['mem_block'].message_type = _MEMORYBLOCK +_INPUTINFO.fields_by_name['data_type'].enum_type = _DATATYPE +_OUTPUTINFO.fields_by_name['data_type'].enum_type = _DATATYPE +_NETDEF.fields_by_name['op'].message_type = _OPERATORDEF +_NETDEF.fields_by_name['arg'].message_type = _ARGUMENT +_NETDEF.fields_by_name['tensors'].message_type = _TENSORPROTO +_NETDEF.fields_by_name['mem_arena'].message_type = _MEMORYARENA +_NETDEF.fields_by_name['input_info'].message_type = _INPUTINFO +_NETDEF.fields_by_name['output_info'].message_type = _OUTPUTINFO +DESCRIPTOR.message_types_by_name['TensorProto'] = _TENSORPROTO +DESCRIPTOR.message_types_by_name['Argument'] = _ARGUMENT +DESCRIPTOR.message_types_by_name['NodeInput'] = _NODEINPUT +DESCRIPTOR.message_types_by_name['OutputShape'] = _OUTPUTSHAPE +DESCRIPTOR.message_types_by_name['OperatorDef'] = _OPERATORDEF +DESCRIPTOR.message_types_by_name['MemoryBlock'] = _MEMORYBLOCK +DESCRIPTOR.message_types_by_name['MemoryArena'] = _MEMORYARENA +DESCRIPTOR.message_types_by_name['InputInfo'] = _INPUTINFO +DESCRIPTOR.message_types_by_name['OutputInfo'] = _OUTPUTINFO +DESCRIPTOR.message_types_by_name['NetDef'] = _NETDEF +DESCRIPTOR.enum_types_by_name['NetMode'] = _NETMODE +DESCRIPTOR.enum_types_by_name['DeviceType'] = _DEVICETYPE +DESCRIPTOR.enum_types_by_name['DataType'] = _DATATYPE +_sym_db.RegisterFileDescriptor(DESCRIPTOR) + +TensorProto = _reflection.GeneratedProtocolMessageType('TensorProto', (_message.Message,), dict( + DESCRIPTOR = _TENSORPROTO, + __module__ = 'mace.proto.mace_pb2' + # @@protoc_insertion_point(class_scope:mace.TensorProto) + )) +_sym_db.RegisterMessage(TensorProto) + +Argument = _reflection.GeneratedProtocolMessageType('Argument', (_message.Message,), dict( + DESCRIPTOR = _ARGUMENT, + __module__ = 'mace.proto.mace_pb2' + # @@protoc_insertion_point(class_scope:mace.Argument) + )) +_sym_db.RegisterMessage(Argument) + +NodeInput = _reflection.GeneratedProtocolMessageType('NodeInput', (_message.Message,), dict( + DESCRIPTOR = _NODEINPUT, + __module__ = 'mace.proto.mace_pb2' + # @@protoc_insertion_point(class_scope:mace.NodeInput) + )) +_sym_db.RegisterMessage(NodeInput) + +OutputShape = _reflection.GeneratedProtocolMessageType('OutputShape', (_message.Message,), dict( + DESCRIPTOR = _OUTPUTSHAPE, + __module__ = 'mace.proto.mace_pb2' + # @@protoc_insertion_point(class_scope:mace.OutputShape) + )) +_sym_db.RegisterMessage(OutputShape) + +OperatorDef = _reflection.GeneratedProtocolMessageType('OperatorDef', (_message.Message,), dict( + DESCRIPTOR = _OPERATORDEF, + __module__ = 'mace.proto.mace_pb2' + # @@protoc_insertion_point(class_scope:mace.OperatorDef) + )) +_sym_db.RegisterMessage(OperatorDef) + +MemoryBlock = _reflection.GeneratedProtocolMessageType('MemoryBlock', (_message.Message,), dict( + DESCRIPTOR = _MEMORYBLOCK, + __module__ = 'mace.proto.mace_pb2' + # @@protoc_insertion_point(class_scope:mace.MemoryBlock) + )) +_sym_db.RegisterMessage(MemoryBlock) + +MemoryArena = _reflection.GeneratedProtocolMessageType('MemoryArena', (_message.Message,), dict( + DESCRIPTOR = _MEMORYARENA, + __module__ = 'mace.proto.mace_pb2' + # @@protoc_insertion_point(class_scope:mace.MemoryArena) + )) +_sym_db.RegisterMessage(MemoryArena) + +InputInfo = _reflection.GeneratedProtocolMessageType('InputInfo', (_message.Message,), dict( + DESCRIPTOR = _INPUTINFO, + __module__ = 'mace.proto.mace_pb2' + # @@protoc_insertion_point(class_scope:mace.InputInfo) + )) +_sym_db.RegisterMessage(InputInfo) + +OutputInfo = _reflection.GeneratedProtocolMessageType('OutputInfo', (_message.Message,), dict( + DESCRIPTOR = _OUTPUTINFO, + __module__ = 'mace.proto.mace_pb2' + # @@protoc_insertion_point(class_scope:mace.OutputInfo) + )) +_sym_db.RegisterMessage(OutputInfo) + +NetDef = _reflection.GeneratedProtocolMessageType('NetDef', (_message.Message,), dict( + DESCRIPTOR = _NETDEF, + __module__ = 'mace.proto.mace_pb2' + # @@protoc_insertion_point(class_scope:mace.NetDef) + )) +_sym_db.RegisterMessage(NetDef) + + +_TENSORPROTO.fields_by_name['float_data'].has_options = True +_TENSORPROTO.fields_by_name['float_data']._options = _descriptor._ParseOptions(descriptor_pb2.FieldOptions(), _b('\020\001')) +_TENSORPROTO.fields_by_name['int32_data'].has_options = True +_TENSORPROTO.fields_by_name['int32_data']._options = _descriptor._ParseOptions(descriptor_pb2.FieldOptions(), _b('\020\001')) +_TENSORPROTO.fields_by_name['double_data'].has_options = True +_TENSORPROTO.fields_by_name['double_data']._options = _descriptor._ParseOptions(descriptor_pb2.FieldOptions(), _b('\020\001')) +_TENSORPROTO.fields_by_name['int64_data'].has_options = True +_TENSORPROTO.fields_by_name['int64_data']._options = _descriptor._ParseOptions(descriptor_pb2.FieldOptions(), _b('\020\001')) +# @@protoc_insertion_point(module_scope) diff --git a/mace/python/tools/model.template b/mace/python/tools/model.template index 5989b86fcf5960200fa50449a06d923ade1bb093..b4db900d925d997f0fa3f060daa66e9627ec7f8d 100644 --- a/mace/python/tools/model.template +++ b/mace/python/tools/model.template @@ -9,7 +9,7 @@ namespace {{tag}}{ -alignas(4) unsigned char {{ tensor_info.name }}[] = { +{% if tensor_info.data_type != 'DT_UINT8' %} alignas(4) {% endif %} unsigned char {{ tensor_info.name }}[] = { {% for d in tensor_info.data %}{{"0x%02X, " % d }}{%endfor%} }; @@ -32,12 +32,14 @@ void UpdateOp(mace::OperatorDef &op, const std::string &type, const std::vector &inputs, const std::vector &outputs, - const std::vector &output_types) { + const std::vector &output_types, + uint32_t node_id) { op.set_name(name); op.set_type(type); op.set_input(inputs); op.set_output(outputs); op.set_output_type(output_types); + op.set_node_id(node_id); } } @@ -78,13 +80,40 @@ void CreateOperator{{i}}(mace::OperatorDef &op) { {% endif %} {% for shape in net.op[i].output_shape %} + {% if shape.dims | length > 0 %} op.add_output_shape(mace::OutputShape({ {{ shape.dims|join(', ') }} })); + {% endif %} {% endfor %} + std::vector output_types_int({ {{ net.op[i].output_type | join(', ') }} }); + std::vector output_types({{ net.op[i].output_type | length }}); + for (int k = 0; k < {{ net.op[i].output_type | length }}; ++k) { + output_types[k] = static_cast(output_types_int[k]); + } UpdateOp(op, {{ net.op[i].name|tojson }}, {{ net.op[i].type|tojson}}, { {{ net.op[i].input|stringfy }} }, { {{ net.op[i].output|stringfy }} }, - { {{ net.op[i].output_type|join(', ') }} }); + output_types, + {{ net.op[i].node_id }}); + + {% if runtime == 'dsp' %} + op.set_padding({{ net.op[i].padding }}); + {% if net.op[i].node_input | length > 0 %} + std::vector input_node_ids({ {{ net.op[i].node_input | map(attribute='node_id') | join(', ') }} }); + std::vector input_output_ports({ {{ net.op[i].node_input | map(attribute='output_port') | join(', ')}} }); + + for (size_t i = 0; i < {{ net.op[i].node_input | length }}; ++i) { + mace::NodeInput input(input_node_ids[i], input_output_ports[i]); + op.add_node_input(input); + } + {% endif %} + {% if net.op[i].out_max_byte_size | length > 0 %} + std::vector out_max_byte_sizes {{ net.op[i].out_max_byte_size | replace('[', '{') | replace(']', '}') }}; + for (size_t i = 0; i < {{ net.op[i].out_max_byte_size | length }}; ++i) { + op.add_out_max_byte_size(out_max_byte_sizes[i]); + } + {% endif %} + {% endif %} } @@ -145,10 +174,25 @@ static void CreateNetArg(mace::NetDef &net_def) { {% endif %} {% endfor %} - } {% endif %} +{% if net.output_info | length > 0 %} +static void CreateOutputInfo(mace::NetDef &net_def) { + std::vector> dims { {{net.output_info | map(attribute='dims') | join(', ') | replace('[', '{') | replace(']', '}') }} }; + + std::vector data_types_int { {{ net.output_info | map(attribute='data_type') | join(', ') }} }; + std::vector data_types({{ net.output_info | length }}); + for (int k = 0; k < {{ net.output_info | length }}; ++k) { + data_types[k] = static_cast(data_types_int[k]); + } + net_def.mutable_output_info().resize({{ net.output_info | length }}); + for (int i = 0; i < {{ net.output_info | length }}; ++i) { + net_def.mutable_output_info()[i].set_data_type(data_types[i]); + net_def.mutable_output_info()[i].set_dims(dims[i]); + } +} +{% endif %} static void CreateOperators(std::vector &ops) { ops.resize({{ net.op|length }}); @@ -205,6 +249,10 @@ NetDef {{'Create' + tag}}() { CreateMemoryArena(net_def.mutable_mem_arena()); {% endif %} + {% if net.output_info | length > 0 %} + CreateOutputInfo(net_def); + {% endif %} + return net_def; } diff --git a/mace/python/tools/source_converter_lib.py b/mace/python/tools/source_converter_lib.py index ace7b3e1d5fd0e19ae49b33ad11f62c6bfe7154b..ce343f3a3cc3f34bccef611b1a72a68042dd45b3 100644 --- a/mace/python/tools/source_converter_lib.py +++ b/mace/python/tools/source_converter_lib.py @@ -1,6 +1,7 @@ import struct import os import uuid +import numpy as np from tensorflow import gfile from mace.proto import mace_pb2 @@ -74,15 +75,18 @@ def rename_tensor(net_def): class TensorInfo: def __init__(self, t): self.name = t.name + self.data_type = mace_pb2.DataType.Name(t.data_type) if t.data_type == mace_pb2.DT_FLOAT: self.data = bytearray(struct.pack('%sf' % len(t.float_data), *t.float_data)) elif t.data_type == mace_pb2.DT_INT32: self.data = bytearray(struct.pack('%si' % len(t.int32_data), *t.int32_data)) + elif t.data_type == mace_pb2.DT_UINT8: + self.data = bytearray(np.array(t.int32_data).astype(np.uint8).tolist()) def stringfy(value): return ', '.join('"{0}"'.format(w) for w in value) -def convert_to_source(net_def, template, confuse, model_tag, output): +def convert_to_source(net_def, template, confuse, model_tag, output, runtime): if confuse: confuse_name(net_def) else: @@ -106,6 +110,7 @@ def convert_to_source(net_def, template, confuse, model_tag, output): tensor = t, tag = model_tag, mode = 0, + runtime = runtime, ) with gfile.GFile(output_dir + 'tensor' + str(counter) + '.cc', "wb") as f: f.write(source) @@ -120,7 +125,8 @@ def convert_to_source(net_def, template, confuse, model_tag, output): end = min(start+10, op_size), net = net_def, tag = model_tag, - mode = 1 + mode = 1, + runtime = runtime, ) with gfile.GFile(output_dir + 'op' + str(counter) + '.cc', "wb") as f: f.write(source) @@ -132,7 +138,8 @@ def convert_to_source(net_def, template, confuse, model_tag, output): tensors = tensors, net = net_def, tag = model_tag, - mode = 2 + mode = 2, + runtime = runtime, ) with gfile.GFile(output, "wb") as f: f.write(source) diff --git a/mace/python/tools/tf_converter.py b/mace/python/tools/tf_converter.py index d258f7bb7be5f39426075976c9987dfb17674b1c..2b182fe67eb2a836a2b09752804b8fe27c20160a 100644 --- a/mace/python/tools/tf_converter.py +++ b/mace/python/tools/tf_converter.py @@ -30,7 +30,7 @@ def main(unused_args): if FLAGS.output_type == 'source': source_converter_lib.convert_to_source(output_graph_def, FLAGS.template, FLAGS.confuse, - FLAGS.model_tag, FLAGS.output) + FLAGS.model_tag, FLAGS.output, FLAGS.runtime) else: with gfile.GFile(FLAGS.output, "wb") as f: f.write(output_graph_def.SerializeToString()) @@ -72,8 +72,8 @@ def parse_args(): parser.add_argument( "--prequantize", type=bool, - default=False, - help="e.g., False") + default=True, + help="e.g., True") parser.add_argument( "--data_type", type=str, diff --git a/mace/python/tools/tf_dsp_converter_lib.py b/mace/python/tools/tf_dsp_converter_lib.py index e9eae6361362447b2297c4a1b99a6e0c6b46166b..62cdfde87855175a82f423c0c3f77dc08b759db6 100644 --- a/mace/python/tools/tf_dsp_converter_lib.py +++ b/mace/python/tools/tf_dsp_converter_lib.py @@ -391,6 +391,7 @@ def convert_to_mace_pb(input_graph_def, input_node, output_node, prequantize=Fal # optimized_net_def = reverse_batch_to_space_and_biasadd(net_def) if prequantize: + print('Prequantize ...') net_def = strip_input_quantize_and_output_dequantize(net_def, input_node, output_node) sorted_net_def = graph_util.sort_mace_graph(net_def, '__output__') diff --git a/tools/validate_gcn.sh b/tools/validate_gcn.sh index 35973abf42d8813713c14395640e21957b8d5a1f..5fc0cfd7c9900ec8fbcb54fed9ffd430b26bcd7e 100644 --- a/tools/validate_gcn.sh +++ b/tools/validate_gcn.sh @@ -67,9 +67,6 @@ build_and_run() MACE_RUN_PARAMETER_PATH=${PHONE_DATA_DIR}/mace_run.config \ MACE_KERNEL_PATH=$KERNEL_DIR \ ${PHONE_DATA_DIR}/mace_run \ - --model=${PHONE_DATA_DIR}/${MACE_MODEL_NAME} \ - --input=mace_input_node \ - --output=mace_output_node \ --input_shape="1,${IMAGE_SIZE},${IMAGE_SIZE},3"\ --output_shape="1,${IMAGE_SIZE},${IMAGE_SIZE},2"\ --input_file=${PHONE_DATA_DIR}/${INPUT_FILE_NAME} \ @@ -97,7 +94,7 @@ bazel-bin/mace/python/tools/tf_converter --input=${TF_MODEL_FILE_PATH} \ --output_type=source \ --template=${MACE_SOURCE_DIR}/mace/python/tools/model.template \ --model_tag=${MODEL_TAG} \ - --confuse=True + --confuse=False echo "Step 3: Generate version source" rm -rf ${VERSION_SOURCE_PATH} diff --git a/tools/validate_gcn_dsp.sh b/tools/validate_gcn_dsp.sh new file mode 100644 index 0000000000000000000000000000000000000000..9e3176f5717765640b8f17248653f6729fe8dd47 --- /dev/null +++ b/tools/validate_gcn_dsp.sh @@ -0,0 +1,95 @@ +#!/bin/bash +# Must run at root dir of mace project. +set +x +Usage() { + echo 'Usage: bash tools/validate_gcn.sh tools/gcn.config tf_model_path image_size [tuning]' +} + +if [ $# -lt 2 ];then + Usage + exit -1 +fi + +source $1 + +VLOG_LEVEL=0 +TF_MODEL_FILE_PATH=$2 +MODEL_DIR=$(dirname ${TF_MODEL_FILE_PATH}) +MACE_SOURCE_DIR=`/bin/pwd` +MACE_MODEL_NAME='mace_model.pb' +INPUT_FILE_NAME='model_input' +OUTPUT_FILE_NAME='gcn.out' +OUTPUT_LIST_FILE='gcn.list' +PHONE_DATA_DIR="/data/local/tmp/${MACE_MODEL_NAME}" +KERNEL_DIR="${PHONE_DATA_DIR}/cl/" +IMAGE_SIZE=$3 +MODEL_TAG=GCN${IMAGE_SIZE} +CODEGEN_DIR=${MACE_SOURCE_DIR}/mace/codegen +MODEL_CODEGEN_DIR=${CODEGEN_DIR}/models/gcn-$IMAGE_SIZE +VERSION_SOURCE_PATH=${CODEGEN_DIR}/version + +build_and_run() +{ + bazel build -c opt --strip always mace/examples:mace_run \ + --crosstool_top=//external:android/crosstool \ + --host_crosstool_top=@bazel_tools//tools/cpp:toolchain \ + --cpu=armeabi-v7a \ + --copt=-DMACE_MODEL_FUNCTION=Create${MODEL_TAG} + + adb shell "mkdir -p ${PHONE_DATA_DIR}" + adb push ${MODEL_DIR}/${INPUT_FILE_NAME} ${PHONE_DATA_DIR} + adb push bazel-bin/mace/examples/mace_run ${PHONE_DATA_DIR} + + adb