From 70001a71ea736abcb92158567e4b9007da15ee86 Mon Sep 17 00:00:00 2001 From: cjh9368 Date: Fri, 21 Aug 2020 16:39:34 +0800 Subject: [PATCH] fix dts bug --- mindspore/lite/src/ir/tensor.cc | 1 + mindspore/lite/src/runtime/thread_pool.cc | 16 +++++++ .../converter/parser/caffe/CMakeLists.txt | 1 + .../parser/caffe/caffe_relu6_parser.cc | 43 +++++++++++++++++++ .../parser/caffe/caffe_relu6_parser.h | 35 +++++++++++++++ .../converter/parser/onnx/onnx_pool_parser.cc | 4 ++ 6 files changed, 100 insertions(+) create mode 100644 mindspore/lite/tools/converter/parser/caffe/caffe_relu6_parser.cc create mode 100644 mindspore/lite/tools/converter/parser/caffe/caffe_relu6_parser.h diff --git a/mindspore/lite/src/ir/tensor.cc b/mindspore/lite/src/ir/tensor.cc index 48dd8cdfdb5..373223a0f3d 100644 --- a/mindspore/lite/src/ir/tensor.cc +++ b/mindspore/lite/src/ir/tensor.cc @@ -75,6 +75,7 @@ Tensor::~Tensor() { } else { free(this->data_); } + this->data_ = nullptr; } } diff --git a/mindspore/lite/src/runtime/thread_pool.cc b/mindspore/lite/src/runtime/thread_pool.cc index 0f6b40df30b..ecbad2772f3 100644 --- a/mindspore/lite/src/runtime/thread_pool.cc +++ b/mindspore/lite/src/runtime/thread_pool.cc @@ -27,6 +27,7 @@ namespace mindspore { namespace predict { constexpr int kDefaultBigCount = 2; constexpr int kDefaultMidCount = 2; +constexpr uint32_t kDefaultSpinCount = 300000; constexpr int kSmallCpuNum = 4; constexpr int kBigMidCpuNum = 4; constexpr int kDefaultThreadNum = 1; @@ -97,6 +98,11 @@ void LiteThreadBind::InitSortedCpuId() { #else numCores = static_cast(std::thread::hardware_concurrency()); #endif // MS_COMPILE_IOS + if (numCores < 0) { + MS_LOG(ERROR) << "get numCores return invalid value: " << numCores; + sortedCpuIds.clear(); + return; + } if (numCores < kBigMidCpuNum) { bigCore = 0; midCore = numCores; @@ -259,6 +265,7 @@ void ThreadPool::AddNewThread(int newNums) { auto queue = std::make_shared(); threadList.emplace_back([this, i, active, queue]() { ThreadPoolTask *task = nullptr; + uint32_t spin_count = 0; while (!exitRun) { while (*active) { if (queue->Dequeue(&task)) { @@ -267,6 +274,15 @@ void ThreadPool::AddNewThread(int newNums) { errorInfo.emplace_back(std::make_pair(i + 1, std::make_pair(false, ret))); } queue->taskSize--; + spin_count = 0; + } else { + ++spin_count; + } + if (spin_count == kDefaultSpinCount) { + *(activateList[i]) = false; + --curThreadRunNums; + spin_count = 0; + break; } std::this_thread::yield(); } diff --git a/mindspore/lite/tools/converter/parser/caffe/CMakeLists.txt b/mindspore/lite/tools/converter/parser/caffe/CMakeLists.txt index 37208577a2f..a0b8ee236ed 100644 --- a/mindspore/lite/tools/converter/parser/caffe/CMakeLists.txt +++ b/mindspore/lite/tools/converter/parser/caffe/CMakeLists.txt @@ -20,6 +20,7 @@ add_library(caffe_parser_mid OBJECT ${CMAKE_CURRENT_SOURCE_DIR}/caffe_power_parser.cc ${CMAKE_CURRENT_SOURCE_DIR}/caffe_prelu_parser.cc ${CMAKE_CURRENT_SOURCE_DIR}/caffe_relu_parser.cc + ${CMAKE_CURRENT_SOURCE_DIR}/caffe_relu6_parser.cc ${CMAKE_CURRENT_SOURCE_DIR}/caffe_reshape_parser.cc ${CMAKE_CURRENT_SOURCE_DIR}/caffe_scale_parser.cc ${CMAKE_CURRENT_SOURCE_DIR}/caffe_sigmoid_parser.cc diff --git a/mindspore/lite/tools/converter/parser/caffe/caffe_relu6_parser.cc b/mindspore/lite/tools/converter/parser/caffe/caffe_relu6_parser.cc new file mode 100644 index 00000000000..207f7ec963b --- /dev/null +++ b/mindspore/lite/tools/converter/parser/caffe/caffe_relu6_parser.cc @@ -0,0 +1,43 @@ +/** + * Copyright 2019 Huawei Technologies Co., Ltd + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include "mindspore/lite/tools/converter/parser/caffe/caffe_relu6_parser.h" + +namespace mindspore { +namespace lite { +STATUS CaffeRelu6Parser::Parse(const caffe::LayerParameter &proto, const caffe::LayerParameter &weight, + schema::CNodeT *op, std::vector *weightVec) { + std::unique_ptr attr(new schema::ActivationT()); + attr->type = schema::ActivationType_RELU6; + // relu: negative_slope = 0, no parameter; + // leakyrelu: negative_slope != 0; + if (proto.has_relu_param() && proto.relu_param().has_negative_slope()) { + float negative_slope = proto.relu_param().negative_slope(); + if (0 != negative_slope) { + attr->type = schema::ActivationType_LEAKY_RELU; + attr->alpha = negative_slope; + } + } + op->primitive = std::make_unique(); + op->primitive->value.value = attr.release(); + op->primitive->value.type = schema::PrimitiveType_Activation; + return RET_OK; +} + +CaffeNodeRegistrar g_caffeRelu6Parser("ReLU6", new CaffeRelu6Parser()); +} // namespace lite +} // namespace mindspore diff --git a/mindspore/lite/tools/converter/parser/caffe/caffe_relu6_parser.h b/mindspore/lite/tools/converter/parser/caffe/caffe_relu6_parser.h new file mode 100644 index 00000000000..3c347c232ed --- /dev/null +++ b/mindspore/lite/tools/converter/parser/caffe/caffe_relu6_parser.h @@ -0,0 +1,35 @@ +/** + * Copyright 2019 Huawei Technologies Co., Ltd + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#ifndef MINDSPORE_CCSRC_TOOLS_LITE_CONVERTER_PARSER_CAFFE_CAFFE_RELU6_PARSER_H_ +#define MINDSPORE_CCSRC_TOOLS_LITE_CONVERTER_PARSER_CAFFE_CAFFE_RELU6_PARSER_H_ + +#include +#include "mindspore/lite/tools/converter/parser/caffe/caffe_node_parser.h" +#include "mindspore/lite/tools/converter/parser/caffe/caffe_node_parser_registry.h" + +namespace mindspore { +namespace lite { +class CaffeRelu6Parser : public CaffeNodeParser { + public: + CaffeRelu6Parser() : CaffeNodeParser("relu6") {} + + STATUS Parse(const caffe::LayerParameter &proto, const caffe::LayerParameter &weight, schema::CNodeT *op, + std::vector *weightVec) override; +}; +} // namespace lite +} // namespace mindspore + +#endif // MINDSPORE_CCSRC_TOOLS_LITE_CONVERTER_PARSER_CAFFE_CAFFE_RELU_PARSER_H_ diff --git a/mindspore/lite/tools/converter/parser/onnx/onnx_pool_parser.cc b/mindspore/lite/tools/converter/parser/onnx/onnx_pool_parser.cc index b8113a16855..98c9565c0ba 100644 --- a/mindspore/lite/tools/converter/parser/onnx/onnx_pool_parser.cc +++ b/mindspore/lite/tools/converter/parser/onnx/onnx_pool_parser.cc @@ -53,6 +53,9 @@ STATUS OnnxPoolParser::Parse(const onnx::GraphProto &onnx_graph, } else if (pool_type == "GlobalAveragePool") { attr->poolingMode = schema::PoolMode_MEAN_POOLING; attr->global = true; + } else if (pool_type == "Int8AveragePool") { + attr->poolingMode = schema::PoolMode_MEAN_POOLING; + attr->global = false; } else { MS_LOG(ERROR) << "Pooling param`s PoolingMode is not MAX either AVE. MindSpore support MAX and AVE only."; return RET_ERROR; @@ -105,5 +108,6 @@ OnnxNodeRegistrar g_onnxMaxPoolParser("MaxPool", new OnnxPoolParser()); OnnxNodeRegistrar g_onnxAveragePoolParser("AveragePool", new OnnxPoolParser()); OnnxNodeRegistrar g_onnxGlobalAveragePoolParser("GlobalAveragePool", new OnnxPoolParser()); OnnxNodeRegistrar g_onnxGlobalMaxPoolParser("GlobalMaxPool", new OnnxPoolParser()); +OnnxNodeRegistrar g_onnxInt8AveragePoolParser("Int8AveragePool", new OnnxPoolParser()); } // namespace lite } // namespace mindspore