diff --git a/mace/core/runtime/hexagon/hexagon_control_wrapper.cc b/mace/core/runtime/hexagon/hexagon_control_wrapper.cc index 5443969510f2fc566d4763ba82ab95cd381fcd20..01be471dd0287be4154de95c1cbfe0836500e83a 100644 --- a/mace/core/runtime/hexagon/hexagon_control_wrapper.cc +++ b/mace/core/runtime/hexagon/hexagon_control_wrapper.cc @@ -58,9 +58,9 @@ bool HexagonControlWrapper::Config() { bool HexagonControlWrapper::Init() { LOG(INFO) << "Hexagon init"; - nn_id_ = hexagon_nn_init(); + MACE_CHECK(hexagon_nn_init(&nn_id_) == 0, "hexagon_nn_init failed"); ResetPerfInfo(); - return nn_id_ != 0; + return true; } bool HexagonControlWrapper::Finalize() { @@ -139,8 +139,19 @@ bool HexagonControlWrapper::SetupGraph(const NetDef &net_def, inputs[i].output_idx = op.node_input()[i].output_port(); } outputs.resize(op.out_max_byte_size().size()); - for (int i = 0; i < op.out_max_byte_size().size(); ++i) { - outputs[i].max_size = op.out_max_byte_size()[i]; + for (size_t i = 0; i < op.out_max_byte_size().size(); ++i) { + outputs[i].rank = op.output_shape()[i].dims().size(); + for (size_t j = 0; j < outputs[i].rank; ++j) { + outputs[i].max_sizes[j] = op.output_shape()[i].dims()[j]; + } + if (outputs[i].rank == 0) { + outputs[i].rank = 1; + outputs[i].max_sizes[0] = 1; + } + outputs[i].max_sizes[outputs[i].rank] = 0; + outputs[i].elementsize = GetEnumTypeSize(op.output_type()[i]); + outputs[i].zero_offset = 0; + outputs[i].stepsize = 0; } cached_inputs.push_back(inputs); cached_outputs.push_back(outputs); @@ -215,13 +226,13 @@ bool HexagonControlWrapper::SetupGraph(const NetDef &net_def, int64_t t1 = NowMicros(); - int res = hexagon_nn_prepare(nn_id_); + MACE_CHECK(hexagon_nn_prepare(nn_id_) == 0, "hexagon_nn_prepare failed"); int64_t t2 = NowMicros(); VLOG(1) << "Setup time: " << t1 - t0 << " " << t2 - t1; - return res == 0; + return true; } bool HexagonControlWrapper::TeardownGraph() { @@ -289,6 +300,7 @@ void HexagonControlWrapper::GetPerfInfo() { std::string node_type(node_type_buf); LOG(INFO) << "node id: " << perf_info[i].node_id << ", node type: " << node_type + << ", node type id: " << node_type_id << ", executions: " << perf_info[i].executions << ", duration: " << node_id_counters[node_id]; diff --git a/third_party/nnlib/hexagon_nn.h b/third_party/nnlib/hexagon_nn.h index 82308003e4f18fa187aed6aeec1898ad87e415ea..b8dbad353a059c2e55c10785b33c97880ca1dadb 100644 --- a/third_party/nnlib/hexagon_nn.h +++ b/third_party/nnlib/hexagon_nn.h @@ -77,8 +77,11 @@ struct hexagon_nn_input { }; typedef struct hexagon_nn_output hexagon_nn_output; struct hexagon_nn_output { - unsigned int max_size; - unsigned int unused; + unsigned int rank; + unsigned int max_sizes[8]; + unsigned int elementsize; + int zero_offset; + float stepsize; }; typedef struct hexagon_nn_perfinfo hexagon_nn_perfinfo; struct hexagon_nn_perfinfo { @@ -128,7 +131,7 @@ struct hexagon_nn_const_node { }; __QAIC_HEADER_EXPORT int __QAIC_HEADER(hexagon_nn_config)(void) __QAIC_HEADER_ATTRIBUTE; -__QAIC_HEADER_EXPORT int __QAIC_HEADER(hexagon_nn_init)(void) +__QAIC_HEADER_EXPORT int __QAIC_HEADER(hexagon_nn_init)(hexagon_nn_nn_id* g) __QAIC_HEADER_ATTRIBUTE; __QAIC_HEADER_EXPORT int __QAIC_HEADER(hexagon_nn_set_debug_level)( hexagon_nn_nn_id id, int level) __QAIC_HEADER_ATTRIBUTE; diff --git a/third_party/nnlib/libhexagon_controller.so b/third_party/nnlib/libhexagon_controller.so index 42dbfabb2cb90dfdcff463f4d46cac981de0dacf..ff8ab3b024b9aa01d89a8b6b0bbfb470c5cc50e8 100755 Binary files a/third_party/nnlib/libhexagon_controller.so and b/third_party/nnlib/libhexagon_controller.so differ diff --git a/third_party/nnlib/ops.h b/third_party/nnlib/ops.h index a01e71acab6cdae2fd96020d844767554307fe3d..34a6d20e876522b1fdfc93451d625bac4be46151 100644 --- a/third_party/nnlib/ops.h +++ b/third_party/nnlib/ops.h @@ -1,37 +1,3 @@ -/* - * Copyright (c) 2016-2017, The Linux Foundation. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted (subject to the limitations in the - * disclaimer below) provided that the following conditions are met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following - * disclaimer in the documentation and/or other materials provided - * with the distribution. - * - * * Neither the name of The Linux Foundation nor the names of its - * contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE - * GRANTED BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT - * HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR - * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE - * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER - * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR - * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN - * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ /* * You probably want to @@ -107,6 +73,7 @@ DEF_OP_WREF(QuantizedRelu_8) DEF_OP_WREF(QuantizedReluX_8) DEF_OP_WREF(QuantizedMaxPool_8) DEF_OP_WREF(QuantizedAvgPool_8) +DEF_OP_WREF(QuantizedL2Pool_8) DEF_OP_WREF(QuantizedConcat_8) DEF_OP_WREF(QuantizedBiasAdd_8p8to32) DEF_OP_WREF(Min_f) @@ -122,6 +89,7 @@ DEF_OP(MatMul_f) DEF_OP(Relu_f) DEF_OP(ReluX_f) DEF_OP(AvgPool_f) +DEF_OP(L2Pool_f) DEF_OP(MaxPool_f) DEF_OP(Concat_f) DEF_OP(BiasAdd_f) @@ -187,6 +155,7 @@ DEF_OP_WREF(QuantizedSigmoid_8) DEF_OP_WREF(QuantizedTanh_8) DEF_OP_WREF(QuantizedSoftmax_8) DEF_OP_WREF(QuantizedLRN_8) +DEF_OP_WREF(Quantizedpad2d_frame_8p) DEF_OP_WREF(QuantizedSub_8p8to32) DEF_OP_WREF(QuantizedMaximum_8) DEF_OP_WREF(QuantizedMinimum_8) @@ -194,23 +163,77 @@ 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(QuantizedResizeBilinear_8) +DEF_OP(Supernode_8x8p8to8_d32) +DEF_OP(Convert_to_d32) +DEF_OP(Convert_from_d32) +DEF_OP_WREF(QuantizedMaxPool_8_d32) +DEF_OP_WREF(QuantizedConcat_8_d32) +DEF_OP_WREF(QuantizedAvgPool_8_d32) + +DEF_OP(Sink) +DEF_OP_WREF(QuantizedPRelu_8_d32) DEF_OP_WREF(AutoQuantize) DEF_OP_WREF(QuantizedDepthwiseConv2d_8x8to32) DEF_OP(DepthwiseConv2d_f) -DEF_OP(QuantizedBiasAdd_8p8to8) +DEF_OP(DepthwiseSupernode_8x8p8to8) +DEF_OP(DepthwiseSupernode_8x8p8to8_d32) + +DEF_OP_WREF(QuantizedMul_8x8to8_d32) + +DEF_OP(FullyConnected_u8) +#if 0 + DEF_OP_WREF(QuantizedFC_8x8p8to8) +#endif + +DEF_OP_WREF(QuantizedAdd_8p8to8_d32) + +DEF_OP_WREF(QuantizedClamp_8) +DEF_OP(Clamp_f) +DEF_OP(QuantizeForTest_d32) +DEF_OP(Close_d32) +DEF_OP_WREF(QuantizedSub_8p8to8_d32) + +DEF_OP(InputSupernode_8x8p8to8_outd32) +DEF_OP(QuantizedLRN_8_d32) +DEF_OP_WREF(QuantizedBiasAdd_32p32to32) +DEF_OP_WREF(Quantize_int32) + +DEF_OP(Supernode_8x8p32to8) +DEF_OP(DepthwiseSupernode_8x8p32to8) +DEF_OP(Supernode_8x8p32to8_d32) +DEF_OP(DepthwiseSupernode_8x8p32to8_d32) +DEF_OP(InputSupernode_8x8p32to8_outd32) + +DEF_OP(PPrint_8_d32) +DEF_OP(PPrintWithPadding_8_d32) +DEF_OP_WREF(AutoQuantize_d32) + +DEF_OP_WREF(QuantizedTanh_8_d32) +DEF_OP_WREF(QuantizedSigmoid_8_d32) +DEF_OP_WREF(QuantizedSoftmax_8_d32) + + +DEF_OP_WREF(QuantizedL2Pool_8_d32) + +DEF_OP(Gather_f) +DEF_OP(Gather_int32) +DEF_OP(Gather_8) +DEF_OP(Table_f) +DEF_OP(Table_int32) +DEF_OP(Table_8) +DEF_OP(FillPadding_8_d32) +DEF_OP(QuantizedResizeBilinear_8_d32) #ifdef __SELF_DEF_OP_WREF #undef __SELF_DEF_OP_WREF #undef DEF_OP_WREF