| @@ -36,13 +36,11 @@ class KernelRegistry { | |||
| static KernelRegistry *GetInstance(); | |||
| int Init(); | |||
| void FreeCreatorArray(); | |||
| virtual kernel::KernelCreator GetCreator(const kernel::KernelKey &desc); | |||
| const kernel::KernelCreator *GetCreatorArrays(); | |||
| int GetCreatorFuncIndex(const kernel::KernelKey desc); | |||
| void RegKernel(const kernel::KernelKey desc, kernel::KernelCreator creator); | |||
| void RegKernel(const kernel::KERNEL_ARCH arch, const TypeId data_type, const schema::PrimitiveType type, | |||
| kernel::KernelCreator creator); | |||
| int GetCreatorFuncIndex(kernel::KernelKey desc); | |||
| void RegKernel(kernel::KernelKey desc, kernel::KernelCreator creator); | |||
| void RegKernel(kernel::KERNEL_ARCH arch, TypeId data_type, schema::PrimitiveType type, kernel::KernelCreator creator); | |||
| bool Merge(const std::unordered_map<kernel::KernelKey, kernel::KernelCreator> &newCreators); | |||
| kernel::LiteKernel *GetKernel(const std::vector<Tensor *> &in_tensors, const std::vector<Tensor *> &out_tensors, | |||
| const PrimitiveC *primitive, const InnerContext *ctx, const kernel::KernelKey &key); | |||
| @@ -61,6 +59,7 @@ class KernelRegistrar { | |||
| KernelRegistrar(const kernel::KernelKey &desc, kernel::KernelCreator creator) { | |||
| KernelRegistry::GetInstance()->RegKernel(desc, creator); | |||
| } | |||
| ~KernelRegistrar() = default; | |||
| KernelRegistrar(const kernel::KERNEL_ARCH arch, const TypeId data_type, const schema::PrimitiveType op_type, | |||
| kernel::KernelCreator creator) { | |||
| @@ -29,6 +29,7 @@ bool ConvertNodes(const schema::MetaGraph *meta_graph, Model *model) { | |||
| return false; | |||
| } | |||
| auto c_node = meta_graph->nodes()->GetAs<schema::CNode>(i); | |||
| MS_ASSERT(c_node != nullptr); | |||
| auto src_prim = c_node->primitive(); | |||
| MS_ASSERT(src_prim != nullptr); | |||
| #ifdef PRIMITIVE_WRITEABLE | |||
| @@ -63,6 +64,8 @@ bool ConvertNodes(const schema::MetaGraph *meta_graph, Model *model) { | |||
| } | |||
| bool ConvertTensors(const schema::MetaGraph *meta_graph, Model *model) { | |||
| MS_ASSERT(model != nullptr); | |||
| MS_ASSERT(meta_graph != nullptr); | |||
| MS_ASSERT(meta_graph->allTensors() != nullptr); | |||
| auto tensor_count = meta_graph->allTensors()->size(); | |||
| for (uint32_t i = 0; i < tensor_count; ++i) { | |||
| @@ -165,13 +168,13 @@ Model *ImportFromBuffer(const char *model_buf, size_t size, bool take_buf) { | |||
| } else { | |||
| if (size == 0) { | |||
| MS_LOG(ERROR) << "malloc size is equal to 0"; | |||
| delete (model); | |||
| delete model; | |||
| return nullptr; | |||
| } | |||
| model->buf = reinterpret_cast<char *>(malloc(size)); | |||
| if (model->buf == nullptr) { | |||
| MS_LOG(ERROR) << "new inner model buf fail!"; | |||
| delete (model); | |||
| delete model; | |||
| return nullptr; | |||
| } | |||
| memcpy(model->buf, model_buf, size); | |||
| @@ -180,7 +183,7 @@ Model *ImportFromBuffer(const char *model_buf, size_t size, bool take_buf) { | |||
| auto meta_graph = schema::GetMetaGraph(model->buf); | |||
| if (meta_graph == nullptr) { | |||
| MS_LOG(ERROR) << "meta_graph is nullptr!"; | |||
| delete (model); | |||
| delete model; | |||
| return nullptr; | |||
| } | |||
| @@ -209,6 +212,7 @@ Model *ImportFromBuffer(const char *model_buf, size_t size, bool take_buf) { | |||
| int ret = MetaGraphMappingSubGraph(meta_graph, model); | |||
| if (ret != RET_OK) { | |||
| MS_LOG(ERROR) << "converter old version model wrong."; | |||
| delete model; | |||
| return nullptr; | |||
| } | |||
| } else { | |||
| @@ -219,11 +223,13 @@ Model *ImportFromBuffer(const char *model_buf, size_t size, bool take_buf) { | |||
| int ret = ConvertSubGraph(sub_graph, model); | |||
| if (ret != RET_OK) { | |||
| MS_LOG(ERROR) << "converter subgraph wrong."; | |||
| delete model; | |||
| return nullptr; | |||
| } | |||
| } | |||
| } | |||
| if (model->sub_graphs_.empty()) { | |||
| delete model; | |||
| return nullptr; | |||
| } | |||
| return model; | |||
| @@ -27,7 +27,7 @@ namespace mindspore { | |||
| class ParamValueLite : public Value { | |||
| public: | |||
| ParamValueLite() : tensor_addr_(nullptr), tensor_size_(0) {} | |||
| virtual ~ParamValueLite() { | |||
| ~ParamValueLite() override { | |||
| if (tensor_addr_ != nullptr) { | |||
| auto tensor_mem = reinterpret_cast<char *>(tensor_addr_); | |||
| delete[](tensor_mem); | |||
| @@ -58,7 +58,7 @@ class DequantUtil { | |||
| } | |||
| } | |||
| } else if (input_tensor->GetQuantParams().size() != kPerTensor) { | |||
| size_t channels = static_cast<size_t>(input_tensor->Batch()); | |||
| auto channels = static_cast<size_t>(input_tensor->Batch()); | |||
| if (input_tensor->GetQuantParams().size() != channels) { | |||
| MS_LOG(ERROR) << "Quant param not equal channel num " << input_tensor->GetQuantParams().size() << channels; | |||
| free(dequant_datas); | |||
| @@ -136,6 +136,8 @@ class DequantUtil { | |||
| template <typename T1, typename T2> | |||
| static void UnPackUtil(const schema::Tensor *input_tensor, int origin_bit, void *unpack_int_data) { | |||
| MS_ASSERT(input_tensor != nullptr); | |||
| MS_ASSERT(input_tensor->data() != nullptr); | |||
| auto weight_data = input_tensor->data()->data(); | |||
| int pack_size = | |||
| input_tensor->dataType() == kNumberTypeInt8 ? input_tensor->data()->size() : input_tensor->data()->size() / 2; | |||
| @@ -848,6 +848,7 @@ ThreadPool *CreateThreadPool(int thread_num, int mode) { | |||
| if (thread_pool->thread_list == NULL) { | |||
| LOG_ERROR("create thread list failed"); | |||
| DestroyThreadPool(thread_pool); | |||
| thread_pool = NULL; | |||
| return NULL; | |||
| } | |||
| thread_pool->thread_list->head = NULL; | |||
| @@ -14,17 +14,14 @@ | |||
| * limitations under the License. | |||
| */ | |||
| #include <string> | |||
| #include <memory> | |||
| #include <vector> | |||
| #include <utility> | |||
| #include "tools/converter/legacy_optimizer/graph/trans_format_insert_pass.h" | |||
| #include "tools/common/node_util.h" | |||
| #include "src/common/log_adapter.h" | |||
| #include "src/common/utils.h" | |||
| namespace mindspore { | |||
| namespace lite { | |||
| namespace mindspore::lite { | |||
| bool TransOpInsertPass::CanFusion(schema::MetaGraphT *graph, const std::unique_ptr<CNodeT> &node) { | |||
| auto input_node_indexes = GetInputNodeIdx(*graph, *node); | |||
| pre_type_ = schema::PrimitiveType_NONE; | |||
| @@ -90,7 +87,6 @@ bool TransOpInsertPass::CanFusion(schema::MetaGraphT *graph, const std::unique_p | |||
| if (GetCNodeTType(*node) == schema::PrimitiveType_Activation) { | |||
| MS_ASSERT(node != nullptr); | |||
| MS_ASSERT(node->primitive != nullptr); | |||
| MS_ASSERT(node->primitive->value != nullptr); | |||
| MS_ASSERT(node->primitive->value.AsActivation() != nullptr); | |||
| if (node->primitive->value.AsActivation() != nullptr && | |||
| node->primitive->value.AsActivation()->type == schema::ActivationType_LEAKY_RELU) { | |||
| @@ -131,7 +127,6 @@ STATUS TransOpInsertPass::ChangeOpAxis(schema::MetaGraphT *graph, const std::uni | |||
| MS_LOG(ERROR) << "node or primitive null"; | |||
| return RET_NULL_PTR; | |||
| } | |||
| MS_ASSERT(node->primitive->value != nullptr); | |||
| auto type = node->primitive->value.type; | |||
| auto input1_ndim = graph->allTensors.at(node->inputIndex[0])->dims.size(); | |||
| if (input1_ndim != 4) { | |||
| @@ -147,14 +142,14 @@ STATUS TransOpInsertPass::ChangeOpAxis(schema::MetaGraphT *graph, const std::uni | |||
| } | |||
| } | |||
| if (type == PrimitiveType_Concat) { | |||
| MS_ASSERT(node->primitive->value.AsConcat() != nullptr); | |||
| auto origin_axis = node->primitive->value.AsConcat()->axis; | |||
| auto axis_map = GetNc2NhAxisMap(); | |||
| if (node->primitive->value.AsConcat() == nullptr) { | |||
| auto attr = node->primitive->value.AsConcat(); | |||
| if (attr == nullptr) { | |||
| MS_LOG(ERROR) << "node->primitive->value.AsConcat() is nullptr"; | |||
| return RET_NULL_PTR; | |||
| } | |||
| node->primitive->value.AsConcat()->axis = axis_map[origin_axis]; | |||
| auto origin_axis = attr->axis; | |||
| auto axis_map = GetNc2NhAxisMap(); | |||
| attr->axis = axis_map[origin_axis]; | |||
| } | |||
| if (type == PrimitiveType_StridedSlice) { | |||
| auto attr = node->primitive->value.AsStridedSlice(); | |||
| @@ -170,25 +165,25 @@ STATUS TransOpInsertPass::ChangeOpAxis(schema::MetaGraphT *graph, const std::uni | |||
| attr->stride = {origin_stride[NCHW_N], origin_stride[NCHW_H], origin_stride[NCHW_W], origin_stride[NCHW_C]}; | |||
| } | |||
| if (type == PrimitiveType_Split) { | |||
| MS_ASSERT(node->primitive->value.AsSplit() != nullptr); | |||
| auto origin_axis = node->primitive->value.AsSplit()->splitDim; | |||
| auto axis_map = GetNc2NhAxisMap(); | |||
| if (node->primitive->value.AsSplit() == nullptr) { | |||
| auto attr = node->primitive->value.AsSplit(); | |||
| if (attr == nullptr) { | |||
| MS_LOG(ERROR) << "node->primitive->value.AsSplit() is nullptr"; | |||
| return RET_NULL_PTR; | |||
| } | |||
| node->primitive->value.AsSplit()->splitDim = axis_map[origin_axis]; | |||
| auto origin_axis = attr->splitDim; | |||
| auto axis_map = GetNc2NhAxisMap(); | |||
| attr->splitDim = axis_map[origin_axis]; | |||
| } | |||
| if (type == PrimitiveType_Crop) { | |||
| MS_ASSERT(node->primitive->value.AsCrop() != nullptr); | |||
| auto origin_axis = node->primitive->value.AsCrop()->axis; | |||
| auto offsets = node->primitive->value.AsCrop()->offsets; | |||
| auto axis_map = GetNc2NhAxisMap(); | |||
| if (node->primitive->value.AsCrop() == nullptr) { | |||
| auto attr = node->primitive->value.AsCrop(); | |||
| if (attr == nullptr) { | |||
| MS_LOG(ERROR) << "node->primitive->value.AsCrop() is nullptr"; | |||
| return RET_NULL_PTR; | |||
| } | |||
| node->primitive->value.AsCrop()->axis = axis_map[origin_axis]; | |||
| auto origin_axis = attr->axis; | |||
| auto offsets = attr->offsets; | |||
| auto axis_map = GetNc2NhAxisMap(); | |||
| attr->axis = axis_map[origin_axis]; | |||
| // nchw->nhwc,offsets need pad 0; | |||
| if (axis_map[origin_axis] == 0) { | |||
| offsets = {offsets[0], offsets[2], offsets[3], offsets[1]}; | |||
| @@ -203,7 +198,7 @@ STATUS TransOpInsertPass::ChangeOpAxis(schema::MetaGraphT *graph, const std::uni | |||
| MS_LOG(ERROR) << "Crop error"; | |||
| return RET_ERROR; | |||
| } | |||
| node->primitive->value.AsCrop()->offsets = offsets; | |||
| attr->offsets = offsets; | |||
| } | |||
| if (type == PrimitiveType_Slice) { | |||
| auto attr = node->primitive->value.AsSlice(); | |||
| @@ -278,5 +273,4 @@ STATUS TransOpInsertPass::Run(schema::MetaGraphT *graph) { | |||
| } | |||
| return RET_OK; | |||
| } | |||
| } // namespace lite | |||
| } // namespace mindspore | |||
| } // namespace mindspore::lite | |||
| @@ -37,7 +37,7 @@ class TransOpInsertPass : public FormatTransPass { | |||
| STATUS FindOutTransType(); | |||
| STATUS ChangeOpAxis(schema::MetaGraphT *graph, const std::unique_ptr<CNodeT> &node); | |||
| static STATUS ChangeOpAxis(schema::MetaGraphT *graph, const std::unique_ptr<CNodeT> &node); | |||
| private: | |||
| FormatTransNodeType pre_insert_trans_type_ = kNHWC2NCHW; | |||
| @@ -19,8 +19,7 @@ | |||
| #include <memory> | |||
| #include <vector> | |||
| namespace mindspore { | |||
| namespace lite { | |||
| namespace mindspore::lite { | |||
| constexpr int32_t kSingleGroup = 1; | |||
| bool OnnxConvParser::ParseGroupConvolution(const std::unique_ptr<schema::Conv2DT> &attr, schema::CNodeT *op) { | |||
| MS_LOG(DEBUG) << "onnx DepthwiseConvParser"; | |||
| @@ -139,6 +138,7 @@ STATUS OnnxConvParser::Parse(const onnx::GraphProto &onnx_graph, const onnx::Nod | |||
| } | |||
| std::vector<int> weight_shape; | |||
| auto size = (*nodeIter).dims_size(); | |||
| weight_shape.reserve(size); | |||
| for (int i = 0; i < size; ++i) { | |||
| weight_shape.emplace_back((*nodeIter).dims(i)); | |||
| } | |||
| @@ -156,7 +156,6 @@ STATUS OnnxConvParser::Parse(const onnx::GraphProto &onnx_graph, const onnx::Nod | |||
| auto iter = std::find_if((*nodeIter).attribute().begin(), (*nodeIter).attribute().end(), | |||
| [](const onnx::AttributeProto &attr) { return attr.name() == "shape"; }); | |||
| if (iter != (*nodeIter).attribute().end()) { | |||
| MS_ASSERT(iter->ints() != nullptr); | |||
| MS_ASSERT(iter->ints().begin() != nullptr); | |||
| MS_ASSERT(iter->ints().end() != nullptr); | |||
| dims.insert(dims.begin(), iter->ints().begin(), iter->ints().end()); | |||
| @@ -188,5 +187,4 @@ OnnxNodeRegistrar g_onnxConvParser("Conv", new OnnxConvParser()); | |||
| OnnxNodeRegistrar g_onnxInt8ConvParser("Int8Conv", new OnnxConvParser()); | |||
| OnnxNodeRegistrar g_onnxConvReluParser("ConvRelu", new OnnxConvParser()); | |||
| OnnxNodeRegistrar g_onnxInt8ConvReluParser("Int8ConvRelu", new OnnxConvParser()); | |||
| } // namespace lite | |||
| } // namespace mindspore | |||
| } // namespace mindspore::lite | |||
| @@ -31,7 +31,7 @@ class OnnxConvParser : public OnnxNodeParser { | |||
| STATUS Parse(const onnx::GraphProto &onnx_graph, const onnx::NodeProto &onnx_node, schema::CNodeT *op) override; | |||
| private: | |||
| bool ParseGroupConvolution(const std::unique_ptr<schema::Conv2DT> &attr, schema::CNodeT *op); | |||
| static bool ParseGroupConvolution(const std::unique_ptr<schema::Conv2DT> &attr, schema::CNodeT *op); | |||
| }; | |||
| } // namespace lite | |||
| } // namespace mindspore | |||
| @@ -17,8 +17,7 @@ | |||
| #include "tools/converter/parser/onnx/onnx_lp_norm_parser.h" | |||
| #include <memory> | |||
| namespace mindspore { | |||
| namespace lite { | |||
| namespace mindspore::lite { | |||
| STATUS OnnxLpNormParser::Parse(const onnx::GraphProto &onnx_graph, const onnx::NodeProto &onnx_node, | |||
| schema::CNodeT *op) { | |||
| MS_LOG(DEBUG) << "onnx LpNormParser"; | |||
| @@ -38,13 +37,12 @@ STATUS OnnxLpNormParser::Parse(const onnx::GraphProto &onnx_graph, const onnx::N | |||
| return RET_NULL_PTR; | |||
| } | |||
| auto onnx_node_attr = onnx_node.attribute(); | |||
| for (int i = 0; i < onnx_node_attr.size(); ++i) { | |||
| MS_ASSERT(onnx_node_attr.at(i) != nullptr); | |||
| if (onnx_node_attr.at(i).name() == "axis") { | |||
| attr->axis = onnx_node_attr.at(i).i(); | |||
| } else if (onnx_node_attr.at(i).name() == "p") { | |||
| attr->p = onnx_node_attr.at(i).i(); | |||
| for (const auto &onnx_node_attr : onnx_node.attribute()) { | |||
| const auto &attribute_name = onnx_node_attr.name(); | |||
| if (attribute_name == "axis") { | |||
| attr->axis = onnx_node_attr.i(); | |||
| } else if (attribute_name == "p") { | |||
| attr->p = onnx_node_attr.i(); | |||
| } | |||
| } | |||
| @@ -54,5 +52,4 @@ STATUS OnnxLpNormParser::Parse(const onnx::GraphProto &onnx_graph, const onnx::N | |||
| } | |||
| OnnxNodeRegistrar g_onnxLpNormParser("LpNormalization", new OnnxLpNormParser()); | |||
| } // namespace lite | |||
| } // namespace mindspore | |||
| } // namespace mindspore::lite | |||
| @@ -17,8 +17,7 @@ | |||
| #include "tools/converter/parser/onnx/onnx_lrn_parser.h" | |||
| #include <memory> | |||
| namespace mindspore { | |||
| namespace lite { | |||
| namespace mindspore::lite { | |||
| STATUS OnnxLrnParser::Parse(const onnx::GraphProto &onnx_graph, const onnx::NodeProto &onnx_node, schema::CNodeT *op) { | |||
| MS_LOG(DEBUG) << "onnx LrnParser"; | |||
| if (op == nullptr) { | |||
| @@ -37,18 +36,17 @@ STATUS OnnxLrnParser::Parse(const onnx::GraphProto &onnx_graph, const onnx::Node | |||
| return RET_NULL_PTR; | |||
| } | |||
| auto onnx_node_attr = onnx_node.attribute(); | |||
| int32_t size = 0; | |||
| for (int i = 0; i < onnx_node_attr.size(); ++i) { | |||
| MS_ASSERT(onnx_node_attr.at(i) != nullptr); | |||
| if (onnx_node_attr.at(i).name() == "alpha") { | |||
| attr->alpha = onnx_node_attr.at(i).f(); | |||
| } else if (onnx_node_attr.at(i).name() == "beta") { | |||
| attr->beta = onnx_node_attr.at(i).f(); | |||
| } else if (onnx_node_attr.at(i).name() == "bias") { | |||
| attr->bias = onnx_node_attr.at(i).f(); | |||
| } else if (onnx_node_attr.at(i).name() == "size") { | |||
| size = static_cast<int32_t>(onnx_node_attr.at(i).i()); | |||
| for (const auto &onnx_node_attr : onnx_node.attribute()) { | |||
| const auto &attribute_name = onnx_node_attr.name(); | |||
| if (attribute_name == "alpha") { | |||
| attr->alpha = onnx_node_attr.f(); | |||
| } else if (attribute_name == "beta") { | |||
| attr->beta = onnx_node_attr.f(); | |||
| } else if (attribute_name == "bias") { | |||
| attr->bias = onnx_node_attr.f(); | |||
| } else if (attribute_name == "size") { | |||
| size = static_cast<int32_t>(onnx_node_attr.i()); | |||
| attr->depth_radius = size / 2; | |||
| } | |||
| } | |||
| @@ -66,5 +64,4 @@ STATUS OnnxLrnParser::Parse(const onnx::GraphProto &onnx_graph, const onnx::Node | |||
| OnnxNodeRegistrar g_onnxLrnxParser("Lrn", new OnnxLrnParser()); | |||
| OnnxNodeRegistrar g_onnxLRNxParser("LRN", new OnnxLrnParser()); | |||
| } // namespace lite | |||
| } // namespace mindspore | |||
| } // namespace mindspore::lite | |||
| @@ -192,22 +192,24 @@ class Calibrator { | |||
| STATUS AddQuantizedOp(const CNodePtr &node); | |||
| STATUS RecordMaxValue(const std::vector<float> &data, const std::unique_ptr<DivergInfo> &diverg_info); | |||
| static STATUS RecordMaxValue(const std::vector<float> &data, const std::unique_ptr<DivergInfo> &diverg_info); | |||
| STATUS UpdateDivergInverval(std::unordered_map<std::string, std::vector<std::unique_ptr<DivergInfo>>> *diverg_info); | |||
| static STATUS UpdateDivergInverval( | |||
| std::unordered_map<std::string, std::vector<std::unique_ptr<DivergInfo>>> *diverg_info); | |||
| STATUS UpdateDataFrequency(const std::vector<float> &data, const std::unique_ptr<DivergInfo> &diverg_info); | |||
| static STATUS UpdateDataFrequency(const std::vector<float> &data, const std::unique_ptr<DivergInfo> &diverg_info); | |||
| void Dump(); | |||
| STATUS ComputeThreshold(); | |||
| std::unordered_map<CNodePtr, float> GetScale( | |||
| static std::unordered_map<CNodePtr, float> GetScale( | |||
| std::unordered_map<std::string, std::unique_ptr<DivergInfo>> *diverg_info); | |||
| std::unordered_map<CNodePtr, int32_t> GetZeropoint( | |||
| static std::unordered_map<CNodePtr, int32_t> GetZeropoint( | |||
| std::unordered_map<std::string, std::unique_ptr<DivergInfo>> *diverg_info); | |||
| std::map<CNodePtr, MaxMin> GetMinMax(std::unordered_map<std::string, std::unique_ptr<DivergInfo>> *diverg_info); | |||
| static std::map<CNodePtr, MaxMin> GetMinMax( | |||
| std::unordered_map<std::string, std::unique_ptr<DivergInfo>> *diverg_info); | |||
| std::unordered_map<std::string, std::vector<std::unique_ptr<DivergInfo>>> *GetInputDivergInfo(); | |||
| @@ -106,8 +106,9 @@ ParameterPtr CreateNewParamter(const FuncGraphPtr &func_graph, Tensor *tensor) { | |||
| parameter->set_default_param(param_value); | |||
| return parameter; | |||
| } | |||
| kernel::LiteKernel *GetLiteKernel(std::vector<Tensor *> inputs, std::vector<Tensor *> outputs, OpParameter *parameter, | |||
| lite::InnerContext *context, mindspore::lite::PrimitiveC *primitive) { | |||
| kernel::LiteKernel *GetLiteKernel(std::vector<Tensor *> inputs, const std::vector<Tensor *> &outputs, | |||
| OpParameter *parameter, lite::InnerContext *context, | |||
| mindspore::lite::PrimitiveC *primitive) { | |||
| MS_ASSERT(nullptr != lite_primitive); | |||
| auto data_type = inputs.front()->data_type(); | |||
| kernel::KernelKey desc{kernel::KERNEL_ARCH::kCPU, data_type, (schema::PrimitiveType)primitive->Type()}; | |||
| @@ -159,15 +160,15 @@ lite::STATUS ReplaceCNode(const FuncGraphPtr &func_graph, const CNodePtr &any_no | |||
| } // namespace | |||
| void FreeTensors(std::vector<Tensor *> *input_tensor, std::vector<Tensor *> *output_tensor) { | |||
| if (input_tensor != nullptr) { | |||
| for (size_t i = 0; i < input_tensor->size(); i++) { | |||
| delete (*input_tensor)[i]; | |||
| (*input_tensor)[i] = nullptr; | |||
| for (auto &i : *input_tensor) { | |||
| delete i; | |||
| i = nullptr; | |||
| } | |||
| } | |||
| if (output_tensor != nullptr) { | |||
| for (size_t i = 0; i < output_tensor->size(); i++) { | |||
| delete (*output_tensor)[i]; | |||
| (*output_tensor)[i] = nullptr; | |||
| for (auto &i : *output_tensor) { | |||
| delete i; | |||
| i = nullptr; | |||
| } | |||
| } | |||
| } | |||
| @@ -227,9 +228,9 @@ const AnfNodePtr ConstFoldPass::Process(const FuncGraphPtr &func_graph, const An | |||
| // here, input_tensor's format need to be transposed nhwc according to fmkType, | |||
| // but for the time being, we only transpose the tensor with 0/1/2/3D. | |||
| // Others should be added in future. | |||
| for (size_t j = 0; j < input_tensors.size(); ++j) { | |||
| input_tensors[j]->SetFormat(schema::Format::Format_NHWC); | |||
| if (input_tensors[j]->shape().size() == 4) { | |||
| for (auto &input_tensor : input_tensors) { | |||
| input_tensor->SetFormat(schema::Format::Format_NHWC); | |||
| if (input_tensor->shape().size() == 4) { | |||
| MS_LOG(INFO) << "init input_tensor format to nhwc"; | |||
| } | |||
| } | |||
| @@ -234,13 +234,11 @@ const void ConvTransformFusion::CalNewWeightTensor(float *weight_data, int kerne | |||
| return; | |||
| } | |||
| if (tmp_weight_data != nullptr) { | |||
| delete[] tmp_weight_data; | |||
| } | |||
| delete[] tmp_weight_data; | |||
| } | |||
| const void ConvTransformFusion::CalNewBiasTensor(float *bias_data, int kernel_num, bool bias_flag, | |||
| const float *trans_scale, const float *trans_bias) const { | |||
| const float *trans_scale, const float *trans_bias) { | |||
| MS_ASSERT(bias_data != nullptr); | |||
| if (bias_flag) { | |||
| auto tmp_bias_data = new (std::nothrow) float[kernel_num]; | |||
| @@ -31,7 +31,7 @@ class ConvTransformFusion : public PatternProcessPass { | |||
| virtual const void InitTransParam(const CNodePtr &, int, float *, float *) const = 0; | |||
| const void GenNewConvTensor(const FuncGraphPtr &, const CNodePtr &, int, const float *, const float *) const; | |||
| const void CalNewWeightTensor(float *, int, int, const float *) const; | |||
| const void CalNewBiasTensor(float *, int, bool, const float *, const float *) const; | |||
| static const void CalNewBiasTensor(float *, int, bool, const float *, const float *); | |||
| }; | |||
| } // namespace mindspore::opt | |||
| #endif // MINDSPORE_LITE_SRC_PASS_FUSION_CONV_TRANSFORM_FUSION_H_ | |||