Browse Source

!396 fix fossbot: delete op schema

Merge pull request !396 from wangzhengjun/delete_schema
pull/401/head
i-robot Gitee 4 years ago
parent
commit
8d6a83d420
13 changed files with 27 additions and 1166 deletions
  1. +0
    -2
      parser/common/CMakeLists.txt
  2. +0
    -2
      parser/common/module.mk
  3. +0
    -712
      parser/common/op_def/defs.cc
  4. +0
    -10
      parser/common/op_def/ir_pb_converter.cc
  5. +0
    -1
      parser/common/op_def/ir_pb_converter.h
  6. +0
    -226
      parser/common/op_def/op_schema.cc
  7. +0
    -175
      parser/common/op_def/op_schema.h
  8. +4
    -18
      parser/common/op_def/operator.cc
  9. +21
    -16
      parser/common/op_def/operator.h
  10. +0
    -2
      tests/st/CMakeLists.txt
  11. +1
    -0
      tests/st/testcase/test_tensorflow_parser.cc
  12. +0
    -2
      tests/ut/parser/CMakeLists.txt
  13. +1
    -0
      tests/ut/parser/testcase/tensorflow_parser_testcase/tensorflow_parser_unittest.cc

+ 0
- 2
parser/common/CMakeLists.txt View File

@@ -17,8 +17,6 @@ set(SRC_LIST
"convert/pb2json.cc"
"convert/message2operator.cc"
"op_def/ir_pb_converter.cc"
"op_def/defs.cc"
"op_def/op_schema.cc"
"op_def/operator.cc"
"op_map.cc"
"parser_types.cc"


+ 0
- 2
parser/common/module.mk View File

@@ -28,8 +28,6 @@ COMMON_LOCAL_SRC_FILES := \
../tensorflow/tensorflow_util.cc \
convert/pb2json.cc \
op_def/ir_pb_converter.cc \
op_def/defs.cc \
op_def/op_schema.cc \
op_def/operator.cc \
op_map.cc \
parser_types.cc \


+ 0
- 712
parser/common/op_def/defs.cc View File

@@ -1,712 +0,0 @@
/**
* Copyright 2020 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 "common/op_def/op_schema.h"

namespace ge {
DOMI_OP_SCHEMA(Data).Output("y");

DOMI_OP_SCHEMA(Const).Output("y");

DOMI_OP_SCHEMA(ConvolutionDepthwise)
.Input("x")
.Input("w")
.Input("b", OpSchema::Optional)
.Output("y")
.Attr("group", AttributeType::INT, static_cast<int64_t>(1))
.Attr("num_output", AttributeType::INT, static_cast<int64_t>(1))
.Attr("pad_mode", AttributeType::INT, static_cast<int64_t>(0))
.Attr("mode", AttributeType::INT, static_cast<int64_t>(1))
.Attr("pad", AttributeType::INTLIST, IntTuple{0, 0, 0, 0})
.Attr("stride", AttributeType::INTLIST, IntTuple{1, 1})
.Attr("dilation", AttributeType::INTLIST, IntTuple{1, 1})
.Attr("kernel", AttributeType::INTLIST, IntTuple{0, 0})
.Attr("before_pad", AttributeType::INTLIST, IntTuple{0, 0, 0, 0});

DOMI_OP_SCHEMA(Region)
.Input("x")
.Output("y")
.Attr("casses", AttributeType::INT, static_cast<int64_t>(20))
.Attr("coords", AttributeType::INT, static_cast<int64_t>(4))
.Attr("boxes", AttributeType::INT, static_cast<int64_t>(1))
.Attr("background", AttributeType::BOOL, static_cast<bool>(false))
.Attr("softmax", AttributeType::BOOL, static_cast<bool>(false))
.Attr("softmax_tree", AttributeType::BOOL, static_cast<bool>(false))
.Attr("yolo_version", AttributeType::INT, static_cast<int64_t>(0));

DOMI_OP_SCHEMA(Gather)
.Input("params")
.Input("indices")
.Input("axis", OpSchema::Optional)
.Output("y")
.Attr("params_type", AttributeType::INT, static_cast<int64_t>(1))
.Attr("indices_type", AttributeType::INT, static_cast<int64_t>(3))
.Attr("validate_indices", AttributeType::BOOL, static_cast<bool>(true));

DOMI_OP_SCHEMA(ArgMax)
.Input("input")
.Output("output")
.Attr("axis", AttributeType::INT, static_cast<int64_t>(0))
.Attr("keep_dims", AttributeType::BOOL, static_cast<bool>(true))
.Attr("axis_type", AttributeType::INT, static_cast<int64_t>(3))
.Attr("outmaxval", AttributeType::BOOL, static_cast<bool>(false))
.Attr("topk", AttributeType::UINT, static_cast<uint32_t>(1));

DOMI_OP_SCHEMA(Split)
.Input("x")
.Input("axis", OpSchema::Optional)
.Output("y")
.Attr("T", AttributeType::INT, static_cast<int64_t>(1))
.Attr("num_split", AttributeType::INT, static_cast<int64_t>(1));

DOMI_OP_SCHEMA(SplitV)
.Input("x")
.Input("axis", OpSchema::Optional)
.Output("y")
.Attr("T", AttributeType::INT, static_cast<int64_t>(1))
.Attr("Tlen", AttributeType::INT, static_cast<int64_t>(1))
.Attr("num_split", AttributeType::INT, static_cast<int64_t>(1));

DOMI_OP_SCHEMA(Fill).Input("x").Input("value").Output("y").Attr("T", AttributeType::INT, static_cast<int64_t>(1));
DOMI_OP_SCHEMA(Rsqrt).Input("x").Output("y");
DOMI_OP_SCHEMA(BiasAdd)
.Input("x")
.Input("bias")
.Output("y")
.Attr("format", AttributeType::INT, static_cast<int64_t>(1));
DOMI_OP_SCHEMA(Reverse)
.Input("x")
.Input("axis")
.Output("y")
.Attr("T", AttributeType::INT, static_cast<int64_t>(1))
.Attr("Tidx", AttributeType::INT, static_cast<int64_t>(1));
DOMI_OP_SCHEMA(Unpack)
.Input("x")
.Output("y")
.Attr("T", AttributeType::INT, static_cast<int64_t>(1))
.Attr("axis", AttributeType::INT, static_cast<int64_t>(0))
.Attr("num", AttributeType::INT, static_cast<int64_t>(1));
DOMI_OP_SCHEMA(Yolo2Reorg)
.Input("x")
.Output("y")
.Attr("reverse", AttributeType::BOOL, static_cast<bool>(1))
.Attr("stride", AttributeType::INT, static_cast<int64_t>(1));

DOMI_OP_SCHEMA(ReduceSum)
.Input("x")
.Output("y")
.Attr("Tidx", AttributeType::INT, static_cast<int64_t>(1))
.Attr("keep_dims", AttributeType::BOOL, static_cast<bool>(1));

DOMI_OP_SCHEMA(Concat)
.Input("x")
.Output("y")
.Attr("Tidx", AttributeType::INT, static_cast<int64_t>(1))
.Attr("N", AttributeType::INT, static_cast<int64_t>(1));

DOMI_OP_SCHEMA(ResizeBilinear)
.Input("x")
.Input("sizes")
.Output("y")
.Attr("output_dim_mode", AttributeType::INT, static_cast<int64_t>(1))
.Attr("align_corners", AttributeType::BOOL, static_cast<bool>(1))
.Attr("zoom_factor", AttributeType::INT, static_cast<int64_t>(1))
.Attr("shrink_factor", AttributeType::INT, static_cast<int64_t>(1))
.Attr("height", AttributeType::INT, static_cast<int64_t>(1))
.Attr("width", AttributeType::INT, static_cast<int64_t>(1))
.Attr("pad_begin", AttributeType::INT, static_cast<int64_t>(1))
.Attr("pad_end", AttributeType::INT, static_cast<int64_t>(1));

DOMI_OP_SCHEMA(LRN)
.Input("x")
.Output("y")
.Attr("lrn_normregion", AttributeType::UINT, static_cast<uint32_t>(0))
.Attr("lrn_k", AttributeType::FLOAT, static_cast<float>(1))
.Attr("lrn_localsize", AttributeType::UINT, static_cast<uint32_t>(5))
.Attr("lrn_alpha", AttributeType::FLOAT, static_cast<float>(1))
.Attr("lrn_beta", AttributeType::FLOAT, static_cast<float>(0.75));

DOMI_OP_SCHEMA(Maximum).Input("x").Input("w").Output("y");

DOMI_OP_SCHEMA(Slice)
.Input("x")
.Output("y")
.Attr("axis", AttributeType::INT, static_cast<int64_t>(2))
.AttrRequired("offsets", AttributeType::INTLIST);

DOMI_OP_SCHEMA(Pad)
.Input("x")
.Input("paddings")
.Input("constant_values", OpSchema::Optional)
.Output("y")
.Attr("T", AttributeType::INT, static_cast<int64_t>(1))
.Attr("t_paddings", AttributeType::INT, static_cast<int64_t>(1))
.Attr("mode", AttributeType::INT, static_cast<int64_t>(0));

DOMI_OP_SCHEMA(PadV2)
.Input("input")
.Output("output")
.Attr("constant_values", AttributeType::INT, static_cast<int64_t>(0))
.AttrRequired("paddings", AttributeType::INTLIST);

DOMI_OP_SCHEMA(MirrorPad)
.Input("input")
.Output("output")
.AttrRequired("paddings", AttributeType::INTLIST)
.Attr("mode", AttributeType::INT, static_cast<int64_t>(2));

DOMI_OP_SCHEMA(Upsample)
.Input("input")
.Input("scales")
.Output("output")
.Attr("mode", AttributeType::INT, static_cast<int64_t>(0));

DOMI_OP_SCHEMA(Cast)
.Input("x")
.Output("y")
.Attr("DstT", AttributeType::INT, static_cast<int64_t>(1))
.Attr("SrcT", AttributeType::INT, static_cast<int64_t>(1));
DOMI_OP_SCHEMA(LogicalNot).Input("x").Output("y");
DOMI_OP_SCHEMA(LogicalAnd).Input("x1").Input("x2").Output("y");
DOMI_OP_SCHEMA(LogicalOr).Input("x1").Input("x2").Output("y");
DOMI_OP_SCHEMA(Equal).Input("x1").Input("x2").Output("y").Attr("T", AttributeType::INT, static_cast<int64_t>(1));

DOMI_OP_SCHEMA(MatMul)
.Input("a")
.Input("b")
.Output("product")
.Attr("transposeX", AttributeType::BOOL, static_cast<bool>(false))
.Attr("transposeW", AttributeType::BOOL, static_cast<bool>(false));

DOMI_OP_SCHEMA(RNN)
.Input("x")
.Input("cont")
.Input("xstatic", OpSchema::Optional)
.Input("w") // filter
.Input("b") // bias
.Input("seqlen") // T
.Input("hx") // Hx
.Input("cx") // cx
.Output("y")
.Output("cyfw")
.Output("hyfw")
.Output("cybw")
.Output("hybw")
.Attr("hidden_size", AttributeType::INT, static_cast<int64_t>(0))
.Attr("num_layers", AttributeType::INT, static_cast<int64_t>(1))
.Attr("support_cont", AttributeType::BOOL, static_cast<bool>(false))
.Attr("support_xstatic", AttributeType::BOOL, static_cast<bool>(false))
.Attr("input_mode", AttributeType::INT, static_cast<int64_t>(0))
.Attr("direction_mode", AttributeType::INT, static_cast<int64_t>(0))
.Attr("mode", AttributeType::INT, static_cast<int64_t>(0))
.Attr("input_data_layout", AttributeType::INT, static_cast<int64_t>(0))
.Attr("output_data_layout", AttributeType::INT, static_cast<int64_t>(0));

DOMI_OP_SCHEMA(FrameworkOp).Attr("framework_type", AttributeType::INT, static_cast<int64_t>(3));
DOMI_OP_SCHEMA(Multinomial)
.Input("logits")
.Output("output")
.Attr("num_samples", AttributeType::INT, static_cast<int64_t>(0))
.AttrRequired("seed", AttributeType::INT)
.AttrRequired("seed2", AttributeType::INT);
DOMI_OP_SCHEMA(ReverseSequence)
.Input("input")
.Input("seq_lengths")
.Output("output")
.AttrRequired("seq_dim", AttributeType::INT)
.AttrRequired("batch_dim", AttributeType::INT);

DOMI_OP_SCHEMA(Interp)
.Input("x")
.Output("y")
.Attr("output_dim_mode", AttributeType::INT, static_cast<int64_t>(2))
.Attr("zoom_factor", AttributeType::INT, static_cast<int64_t>(1))
.Attr("shrink_factor", AttributeType::INT, static_cast<int64_t>(1))
.Attr("height", AttributeType::INT, static_cast<int64_t>(0))
.Attr("width", AttributeType::INT, static_cast<int64_t>(0))
.Attr("pad_begin", AttributeType::INT, static_cast<int64_t>(0))
.Attr("pad_end", AttributeType::INT, static_cast<int64_t>(0));

DOMI_OP_SCHEMA(ShuffleChannel).Input("x").Output("y").Attr("group", AttributeType::UINT, static_cast<uint32_t>(1));

DOMI_OP_SCHEMA(Conv2DBackpropFilter)
.Input("x")
.Input("w")
.Input("b", OpSchema::Optional)
.Output("y")
.Attr("padding", AttributeType::INT, static_cast<int64_t>(1))
.Attr("pads", AttributeType::UINTLIST, UintTuple{0, 0, 0, 0})
.Attr("strides", AttributeType::UINTLIST, UintTuple{1, 1})
.Attr("dilations", AttributeType::UINTLIST, UintTuple{1, 1});

DOMI_OP_SCHEMA(Conv2DBackpropInput)
.Input("input_sizes")
.Input("filter")
.Input("out_backprop")
.Output("output")
.Attr("data_format", AttributeType::STRING, static_cast<std::string>("NHWC"))
.Attr("group", AttributeType::UINT, static_cast<uint32_t>(1))
.Attr("padding", AttributeType::INT, static_cast<int64_t>(0))
.Attr("dilations", AttributeType::UINTLIST, UintTuple{1, 1})
.Attr("strides", AttributeType::UINTLIST, UintTuple{1, 1})
.Attr("pad", AttributeType::UINTLIST, UintTuple{0, 0, 0, 0});
DOMI_OP_SCHEMA(BiasAddGrad).Input("dy").Output("db").Attr("format", AttributeType::INT, static_cast<int64_t>(1));
DOMI_OP_SCHEMA(ReluGrad).Input("dy").Input("x").Output("dx");

DOMI_OP_SCHEMA(MeanGrad).Input("dy").Output("dx");

DOMI_OP_SCHEMA(NonMaxSuppression)
.Input("boxes")
.Input("scores")
.Output("selected_indices")
.Attr("max_output_size", AttributeType::INT, static_cast<int64_t>(-1))
.Attr("iou_threshold", AttributeType::FLOAT, static_cast<float>(0.5))
.Attr("score_threshold", AttributeType::FLOAT, static_cast<float>(-1));

DOMI_OP_SCHEMA(CropAndResize)
.Input("image")
.Input("boxes")
.Input("box_ind")
.Output("crops")
.Attr("method", AttributeType::INT, static_cast<int64_t>(0))
.Attr("extrapolation_value", AttributeType::FLOAT, static_cast<float>(0))
.Attr("crop_size_h", AttributeType::INT, static_cast<int64_t>(0))
.Attr("crop_size_w", AttributeType::INT, static_cast<int64_t>(0));

DOMI_OP_SCHEMA(TopKV2)
.Input("input")
.Input("k")
.Output("value")
.Output("indices")
.AttrRequired("sorted", AttributeType::BOOL);

DOMI_OP_SCHEMA(InvertPermutation).Input("x").Output("y");

DOMI_OP_SCHEMA(GatherV2)
.Input("params")
.Input("indices")
.Input("axis", OpSchema::Optional)
.Output("y")
.Attr("Tparams", AttributeType::INT, static_cast<int64_t>(0)) // default: DT_FLOAT
.Attr("Tindices", AttributeType::INT, static_cast<int64_t>(3)) // default: DT_INT32
.Attr("Taxis", AttributeType::INT, static_cast<int64_t>(3)); // default: DT_INT32

DOMI_OP_SCHEMA(HighWay)
.Input("x")
.Input("tw") // filter
.Input("tb") // bias
.Input("uw") // filter
.Input("ub") // bias
.Output("y");

DOMI_OP_SCHEMA(Reciprocal).Input("x").Output("y");

DOMI_OP_SCHEMA(Asinh).Input("input").Output("output");

DOMI_OP_SCHEMA(Acosh).Input("input").Output("output");

DOMI_OP_SCHEMA(Minimum).Input("x").Input("y").Output("output");

DOMI_OP_SCHEMA(Clip).Input("input").Input("min").Input("max").Output("output");

DOMI_OP_SCHEMA(FusedBatchNorm)
.Input("x")
.Input("scale")
.Input("offset")
.Input("mean")
.Input("variance")
.Output("y")
.Output("batch_mean")
.Output("batch_variance")
.Output("reserve_space_1")
.Output("reserve_space_2")
.Attr("data_format", AttributeType::STRING, static_cast<std::string>("NHWC"))
.Attr("epsilon", AttributeType::FLOAT, static_cast<float>(0.0001))
.Attr("is_training", AttributeType::BOOL, static_cast<bool>(false));

DOMI_OP_SCHEMA(FusedBatchNormGrad)
.Input("dy")
.Input("x")
.Input("bnscale")
.Input("save_mean")
.Input("save_variance")
.Output("dx")
.Output("result_bn_scale_diff")
.Output("result_bn_bias_diff")
.Attr("data_format", AttributeType::STRING, static_cast<std::string>("NHWC"))
.Attr("epsilon", AttributeType::FLOAT, static_cast<float>(0.0))
.Attr("is_training", AttributeType::BOOL, static_cast<bool>(true));

DOMI_OP_SCHEMA(MaxPoolWithArgmax)
.Input("x")
.Output("y")
.Output("argmax")
.AttrRequired("window", AttributeType::INTLIST)
.AttrRequired("stride", AttributeType::INTLIST)
.AttrRequired("pad_mode", AttributeType::INT)
.AttrRequired("ceil_mode", AttributeType::BOOL)
.AttrRequired("data_mode", AttributeType::INT);

DOMI_OP_SCHEMA(MaxPoolGradWithArgmax)
.Input("input")
.Input("grad")
.Output("output")
.AttrRequired("window", AttributeType::INTLIST)
.AttrRequired("stride", AttributeType::INTLIST)
.AttrRequired("pad_mode", AttributeType::INT)
.AttrRequired("ceil_mode", AttributeType::BOOL)
.AttrRequired("data_mode", AttributeType::INT);

DOMI_OP_SCHEMA(HcomBroadcast)
.AttrRequired("root_rank", AttributeType::INT)
.AttrRequired("group", AttributeType::STRING);

DOMI_OP_SCHEMA(HcomAllReduce)
.Input("x")
.Output("y")
.AttrRequired("reduction", AttributeType::STRING)
.AttrRequired("group", AttributeType::STRING);

DOMI_OP_SCHEMA(HcomAllGather)
.Input("x")
.Output("y")
.AttrRequired("rank_size", AttributeType::INT)
.AttrRequired("group", AttributeType::STRING);

DOMI_OP_SCHEMA(SparseSoftmaxCrossEntropyWithLogits)
.Input("features")
.Input("labels")
.Output("loss")
.Output("backprop")
.AttrRequired("T", AttributeType::INT)
.Attr("Tlabels", AttributeType::INT, static_cast<int64_t>(9));

DOMI_OP_SCHEMA(Snapshot).Input("input").Output("output").AttrRequired("T", AttributeType::INT);

DOMI_OP_SCHEMA(ReduceProd)
.Input("bottom")
.Output("top")
.AttrRequired("axes", AttributeType::INTLIST)
.Attr("keep_dims", AttributeType::BOOL, static_cast<bool>(false));

DOMI_OP_SCHEMA(ReduceAll)
.Input("x")
.Output("y")
.AttrRequired("axes", AttributeType::INTLIST)
.Attr("keep_dims", AttributeType::BOOL, static_cast<bool>(false));

DOMI_OP_SCHEMA(ReduceMax)
.Input("x")
.Output("y")
.AttrRequired("axis", AttributeType::INTLIST)
.Attr("keep_dims", AttributeType::BOOL, static_cast<bool>(false));

DOMI_OP_SCHEMA(AddN).Input("x").Output("y");

DOMI_OP_SCHEMA(ShapeN)
.Input("x")
.Output("y")
.AttrRequired("N", AttributeType::INT)
.AttrRequired("in_type", AttributeType::INT)
.AttrRequired("dtype", AttributeType::INT);

DOMI_OP_SCHEMA(ReduceMin)
.Input("x")
.Output("y")
.AttrRequired("axis", AttributeType::INTLIST)
.Attr("keep_dims", AttributeType::BOOL, static_cast<bool>(false));

DOMI_OP_SCHEMA(Sqrt).Input("x").Output("y");

DOMI_OP_SCHEMA(L2Loss).Input("x").Output("y");

DOMI_OP_SCHEMA(Multiply).Input("x").Input("y").Output("z");

DOMI_OP_SCHEMA(Add).Input("x").Output("y");

DOMI_OP_SCHEMA(Constant).Output("y");

DOMI_OP_SCHEMA(ApplyMomentum)
.Input("variable")
.Input("accumulation")
.Input("learningRate")
.Input("gradient")
.Input("momuntum")
.Input("fp16variable")
.Attr("algo", AttributeType::INT, static_cast<int64_t>(0));

DOMI_OP_SCHEMA(AvgPoolGrad)
.Input("shape")
.Input("grad")
.Output("output")
.Attr("padding", AttributeType::INT, static_cast<int64_t>(0))
.Attr("data_format", AttributeType::STRING, static_cast<std::string>("NHWC"))
.Attr("strides", AttributeType::UINTLIST, UintTuple{0, 0, 0, 0})
.Attr("ksize", AttributeType::UINTLIST, UintTuple{0, 0, 0, 0});

DOMI_OP_SCHEMA(Lars)
.Input("w")
.Input("g")
.Input("weight_decay")
.Output("y")
.Attr("hyperpara", AttributeType::FLOAT, static_cast<float>(0.001))
.Attr("epsilon", AttributeType::FLOAT, static_cast<float>(0.00001));

DOMI_OP_SCHEMA(AssignSub)
.Input("variable")
.Input("input")
.Input("output")
.Attr("mode", AttributeType::INT, static_cast<int64_t>(0));

DOMI_OP_SCHEMA(AssignAdd)
.Input("variable")
.Input("input")
.Output("output")
.Attr("mode", AttributeType::INT, static_cast<int64_t>(0));

DOMI_OP_SCHEMA(SpaceToBatchND).Input("input").Input("block_shape").Input("paddings").Output("output");

DOMI_OP_SCHEMA(Variable)
.Output("variable")
.Attr("container", AttributeType::STRING, static_cast<std::string>(""))
.Attr("shared_name", AttributeType::STRING, static_cast<std::string>(""))
.AttrRequired("dtype", AttributeType::INT);

DOMI_OP_SCHEMA(Assign).Input("variable").Input("value").Output("variable");

DOMI_OP_SCHEMA(VarIsInitializedOp).Input("variable").Output("value");

DOMI_OP_SCHEMA(NoOp).Attr("algo", AttributeType::INT, static_cast<int64_t>(0));

DOMI_OP_SCHEMA(LogTimeStamp)
.Attr("logid", AttributeType::STRING, static_cast<std::string>(""))
.Attr("notify", AttributeType::BOOL, static_cast<bool>(false));

DOMI_OP_SCHEMA(ResizeNearestNeighbor)
.Input("images")
.Output("resized_images")
.Attr("align_corners", AttributeType::BOOL, static_cast<bool>(false))
.AttrRequired("height", AttributeType::INT)
.AttrRequired("width", AttributeType::INT);

DOMI_OP_SCHEMA(BatchToSpaceND).Input("input").Input("block_shape").Input("crops").Output("output");

DOMI_OP_SCHEMA(Assert).Input("x").Input("w").Output("y");

DOMI_OP_SCHEMA(Pow).Input("x").Input("y").Output("z");

DOMI_OP_SCHEMA(GreaterEqual).Input("x1").Input("x2").Output("y");

DOMI_OP_SCHEMA(SpaceToDepth)
.Input("input")
.Output("output")
.Attr("block_size", AttributeType::INT, static_cast<int64_t>(0))
.AttrRequired("T", AttributeType::INT)
.Attr("data_format", AttributeType::STRING, static_cast<std::string>("NHWC"));

DOMI_OP_SCHEMA(DepthToSpace)
.Input("input")
.Output("output")
.Attr("block_size", AttributeType::INT, static_cast<int64_t>(0))
.AttrRequired("T", AttributeType::INT)
.Attr("data_format", AttributeType::STRING, static_cast<std::string>("NHWC"));

DOMI_OP_SCHEMA(Rint).Input("input").Output("output").AttrRequired("T", AttributeType::INT);

DOMI_OP_SCHEMA(ExtractImagePatches)
.Input("images")
.Output("y")
.AttrRequired("ksizes", AttributeType::INTLIST)
.AttrRequired("strides", AttributeType::INTLIST)
.AttrRequired("rates", AttributeType::INTLIST)
.AttrRequired("padding", AttributeType::STRING);

DOMI_OP_SCHEMA(Atan).Input("x").Output("output");

DOMI_OP_SCHEMA(Atanh).Input("x").Output("output");

DOMI_OP_SCHEMA(Acos).Input("x").Output("y");

DOMI_OP_SCHEMA(Asin).Input("x").Output("y");

DOMI_OP_SCHEMA(Log)
.Input("x")
.Output("output")
.AttrRequired("scale", AttributeType::INT)
.AttrRequired("shift", AttributeType::INT)
.AttrRequired("base", AttributeType::INT);

DOMI_OP_SCHEMA(Neg).Input("input").Output("output");

DOMI_OP_SCHEMA(Tan).Input("x").Output("output");

DOMI_OP_SCHEMA(Round).Input("x").Output("output");

DOMI_OP_SCHEMA(Exp)
.Input("x")
.Output("y")
.Attr("scale", AttributeType::FLOAT, static_cast<float>(1))
.Attr("shift", AttributeType::FLOAT, static_cast<float>(0))
.Attr("base", AttributeType::FLOAT, static_cast<float>(-1));

DOMI_OP_SCHEMA(Less).Input("x").Input("y").Output("output");

DOMI_OP_SCHEMA(LessEqual).Input("x").Input("y").Output("output");

DOMI_OP_SCHEMA(OneHot).Input("indices").Input("depth").Input("on_value").Input("off_value").Output("output");

DOMI_OP_SCHEMA(ZerosLike).Input("x").Output("y");

DOMI_OP_SCHEMA(Where).Input("x").Output("y");

DOMI_OP_SCHEMA(RefSwitch).Input("x").Output("y");

DOMI_OP_SCHEMA(FakeQuantWithMinMaxVars)
.Input("x")
.Input("min")
.Input("max")
.Output("y")
.Attr("narrow_range", AttributeType::BOOL, static_cast<bool>(false))
.Attr("num_bits", AttributeType::INT, static_cast<int64_t>(8));

DOMI_OP_SCHEMA(Sinh).Input("x").Output("y");

DOMI_OP_SCHEMA(Cosh).Input("x").Output("y");

DOMI_OP_SCHEMA(Floor).Input("x").Output("output");

DOMI_OP_SCHEMA(RandomUniform).Input("input").Output("output");

DOMI_OP_SCHEMA(BatchMatMul).Input("x").Input("y").Output("output");

DOMI_OP_SCHEMA(FloorMod).Input("x").Input("y").Output("output");

DOMI_OP_SCHEMA(SquaredDifference).Input("x").Input("y").Output("output");

DOMI_OP_SCHEMA(LayerNorm).Input("x").Output("output").AttrRequired("Epsilon", AttributeType::FLOAT);

DOMI_OP_SCHEMA(SSDPostProcessor)
.Input("trueImgShape")
.Input("boxEncoding")
.Input("anchors")
.Input("clsPred")
.Output("detectBoxes")
.Output("detectScores")
.Output("detectNum")
.Output("detectClasses")
.AttrRequired("numClasses", AttributeType::INT)
.AttrRequired("scoreThreshold", AttributeType::FLOAT)
.AttrRequired("iouThreshold", AttributeType::FLOAT)
.AttrRequired("maxDetectionsPerClass", AttributeType::INT)
.AttrRequired("maxTotalDetections", AttributeType::INT)
.AttrRequired("boxTypeNum", AttributeType::UINT)
.AttrRequired("scaleFactors_0", AttributeType::UINT)
.AttrRequired("scaleFactors_1", AttributeType::UINT)
.AttrRequired("scaleFactors_2", AttributeType::UINT)
.AttrRequired("scaleFactors_3", AttributeType::UINT)
.AttrRequired("imgH", AttributeType::INT)
.AttrRequired("imgW", AttributeType::INT)
.AttrRequired("useStaticShape", AttributeType::BOOL)
.AttrRequired("convertScoresMode", AttributeType::INT);

DOMI_OP_SCHEMA(RetinaPostProcessor)
.Input("anchors")
.Input("regression")
.Input("classification")
.Output("detectBoxes")
.Output("detectScores")
.Output("detectLabels")
.Output("detectNum")
.AttrRequired("numClasses", AttributeType::INT)
.AttrRequired("maxDetections", AttributeType::INT)
.AttrRequired("nmsThreshold", AttributeType::FLOAT)
.AttrRequired("scoreThreshold", AttributeType::FLOAT)
.AttrRequired("imgH", AttributeType::INT)
.AttrRequired("imgW", AttributeType::INT)
.AttrRequired("boxTypeNum", AttributeType::UINT)
.AttrRequired("means", AttributeType::FLOATLIST)
.AttrRequired("stds", AttributeType::FLOATLIST);

DOMI_OP_SCHEMA(ROIInterPooling)
.Input("input")
.Input("input_1")
.Output("maxPool")
.AttrRequired("hStride", AttributeType::INT)
.AttrRequired("wStride", AttributeType::INT)
.AttrRequired("hKernel", AttributeType::INT)
.AttrRequired("wKernel", AttributeType::INT)
.AttrRequired("hResize", AttributeType::INT)
.AttrRequired("wResize", AttributeType::INT)
.AttrRequired("hFeatureMap", AttributeType::INT)
.AttrRequired("wFeatureMap", AttributeType::INT);

DOMI_OP_SCHEMA(FirstStageProcessor)
.Input("anchors")
.Input("boxEncoding")
.Input("clsPred")
.Input("trueImgShape")
.Output("detectBoxes")
.Output("detectScores")
.Output("detectLables")
.Output("detectNum")
.AttrRequired("scaleFactorsNum", AttributeType::INT)
.AttrRequired("iouThreshold", AttributeType::FLOAT)
.AttrRequired("scoreThreshold", AttributeType::FLOAT)
.AttrRequired("maxSizePerClass", AttributeType::INT)
.AttrRequired("maxTotalSize", AttributeType::INT)
.AttrRequired("imgH", AttributeType::INT)
.AttrRequired("imgW", AttributeType::INT)
.AttrRequired("boxTypeNum", AttributeType::UINT)
.AttrRequired("scaleFactors_0", AttributeType::UINT)
.AttrRequired("scaleFactors_1", AttributeType::UINT)
.AttrRequired("scaleFactors_2", AttributeType::UINT)
.AttrRequired("scaleFactors_3", AttributeType::UINT);

DOMI_OP_SCHEMA(SecondStageProcessor)
.Input("anchors")
.Input("boxEncoding")
.Input("clsPred")
.Input("validBoxNum")
.Input("trueImgShape")
.Output("detectBoxes")
.Output("detectScores")
.Output("detectLables")
.Output("detectNum")
.AttrRequired("scaleFactorsNum", AttributeType::INT)
.AttrRequired("iouThreshold", AttributeType::FLOAT)
.AttrRequired("scoreThreshold", AttributeType::FLOAT)
.AttrRequired("maxSizePerClass", AttributeType::INT)
.AttrRequired("maxTotalSize", AttributeType::INT)
.AttrRequired("numClasses", AttributeType::INT)
.AttrRequired("scaleFactors_0", AttributeType::UINT)
.AttrRequired("scaleFactors_1", AttributeType::UINT)
.AttrRequired("scaleFactors_2", AttributeType::UINT)
.AttrRequired("scaleFactors_3", AttributeType::UINT);

DOMI_OP_SCHEMA(StreamSwitch)
.Input("loopIndex")
.Input("itersPerLoop")
.AttrRequired("switch_condition", AttributeType::UINT)
.AttrRequired("true_branch_stream", AttributeType::INT);

DOMI_OP_SCHEMA(StreamActive).AttrRequired("active_stream_list", AttributeType::INTLIST);

DOMI_OP_SCHEMA(MemcpyAsync).Input("in").Output("out");

DOMI_OP_SCHEMA(CleanAddr)
.AttrRequired("automic_add_addr_start", AttributeType::INT)
.AttrRequired("automic_add_mem_size", AttributeType::INT);
} // namespace ge

+ 0
- 10
parser/common/op_def/ir_pb_converter.cc View File

@@ -99,11 +99,6 @@ FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY domi::Status ConvertToOpDesc(co
GELOGE(ge::FAILED, "[Check][Param] param op_def is nullptr, check invalid.");
return ge::FAILED;
}
if (op.GetSchema() == nullptr) {
REPORT_INNER_ERROR("E19999", "Op schema is nullptr, op type: %s", op.GetType().c_str());
GELOGE(domi::PARAM_INVALID, "[Get][Schema] Op schema is nullptr, op type: %s", op.GetType().c_str());
return domi::PARAM_INVALID;
}
op_def->SetName(op.GetName());
op_def->SetType(op.GetType());
GE_IF_BOOL_EXEC(op.GetType() == ge::parser::YOLO, op_def->SetType(ge::parser::REGION));
@@ -139,11 +134,6 @@ FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY domi::Status ConvertToOpDesc(co
}
}
}
if (!op.GetSchema()->Verify(op_def)) {
REPORT_CALL_ERROR("E19999", "Op schema verify failed, op name: %s", op.GetName().c_str());
GELOGE(domi::PARAM_INVALID, "[Invoke][Verify] Op schema verify failed, op name: %s", op.GetName().c_str());
return domi::PARAM_INVALID;
}
return domi::SUCCESS;
}



+ 0
- 1
parser/common/op_def/ir_pb_converter.h View File

@@ -18,7 +18,6 @@
#define DOMI_COMMON_OP_DEF_IR_PB_CONVERTER_H

#include "framework/common/fmk_error_codes.h"
#include "common/op_def/op_schema.h"
#include "parser/common/op_def/operator.h"
#include "graph/ge_attr_value.h"
#include "graph/ge_tensor.h"


+ 0
- 226
parser/common/op_def/op_schema.cc View File

@@ -1,226 +0,0 @@
/**
* Copyright 2020 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 "common/op_def/op_schema.h"
#include <iostream>
#include <utility>
#include "framework/common/debug/ge_log.h"

namespace ge {
OpSchema::FormalParameter::FormalParameter(const std::string &name, FormalParameterOption param_option)
: name_(name), param_option_(param_option) {}

OpSchema::FormalParameter::~FormalParameter() {}

const std::string &OpSchema::FormalParameter::Name() const { return name_; }

OpSchema::FormalParameterOption OpSchema::FormalParameter::Option() const { return param_option_; }

OpSchema::OpSchema(const std::string &name) : name_(name) {}

OpSchema::~OpSchema() {}

OpSchema &OpSchema::Input(const std::string &name, FormalParameterOption param_option) {
inputs_.emplace_back(FormalParameter(name, param_option));
return *this;
}

OpSchema &OpSchema::Output(const std::string &name, FormalParameterOption param_option) {
outputs_.emplace_back(FormalParameter(name, param_option));
return *this;
}

OpSchema &OpSchema::Attr(const Attribute &attr) {
(void)attributes_.insert(std::make_pair(attr.name_, attr));
return *this;
}

#if defined(CFG_BUILD_DEBUG)
#define ATTR_SETTER_WITH_SINGLE_VALUE(Type, field, attrtype) \
OpSchema &OpSchema::Attr(const std::string &name, AttributeType attr_type, const Type &default_value) { \
if (attrtype != attr_type) { \
REPORT_INNER_ERROR("E19999", "Attribute specification param_type mismatch, input attr type %u, " \
"required attr type %u.", (uint32_t)attr_type, (uint32_t)attrtype); \
GELOGE(FAILED, "[Check][Param]Attribute specification param_type mismatch, " \
"input attr type %u, required attr type %u.", (uint32_t)attr_type, (uint32_t)attrtype); \
return *this; \
} \
\
domi::AttrDef a; \
a.set_##field(default_value); \
Attr(Attribute(name, attr_type, a)); \
return *this; \
}
#else
#define ATTR_SETTER_WITH_SINGLE_VALUE(Type, field, attrtype) \
OpSchema &OpSchema::Attr(const std::string &name, AttributeType attr_type, const Type &default_value) { \
if (attrtype != attr_type) { \
return *this; \
} \
domi::AttrDef a; \
a.set_##field(default_value); \
Attr(Attribute(name, attr_type, a)); \
return *this; \
}

#endif

#if defined(CFG_BUILD_DEBUG)
#define ATTR_SETTER_WITH_LIST_VALUE(Type, field, attrtype) \
OpSchema &OpSchema::Attr(const std::string &name, AttributeType attr_type, const std::vector<Type> &default_value) { \
if (attrtype != attr_type) { \
REPORT_INNER_ERROR("E19999", "Attribute specification vector param_type mismatch, " \
"input attr type %u, required attr type %u.", (uint32_t)attr_type, (uint32_t)attrtype); \
GELOGE(FAILED, "[Check][Param]Attribute specification vector param_type mismatch, " \
"input attr type %u, required attr type %u.", (uint32_t)attr_type, (uint32_t)attrtype); \
return *this; \
} \
domi::AttrDef vec_a; \
for (const auto &v : default_value) { \
vec_a.mutable_list()->add_##field(v); \
} \
Attr(Attribute(name, attr_type, vec_a)); \
return *this; \
} \
OpSchema &OpSchema::Attr(const std::string &name, AttributeType attr_type, const Tuple<Type> &default_value) { \
if (attrtype != attr_type) { \
REPORT_INNER_ERROR("E19999", "Attribute specification vector param_type mismatch, " \
"input attr type %u, required attr type %u.", (uint32_t)attr_type, (uint32_t)attrtype); \
GELOGE(FAILED, "[Check][Param]Attribute specification vector param_type mismatch, " \
"input attr type %u, required attr type %u.", (uint32_t)attr_type, (uint32_t)attrtype); \
return *this; \
} \
domi::AttrDef tuple_a; \
for (const auto &v : default_value) { \
tuple_a.mutable_list()->add_##field(v); \
} \
Attr(Attribute(name, attr_type, tuple_a)); \
return *this; \
}
#else
#define ATTR_SETTER_WITH_LIST_VALUE(Type, field, attrtype) \
OpSchema &OpSchema::Attr(const std::string &name, AttributeType attr_type, const std::vector<Type> &default_value) { \
if (attrtype != attr_type) { \
return *this; \
} \
domi::AttrDef vec_a; \
for (const auto &v : default_value) { \
vec_a.mutable_list()->add_##field(v); \
} \
Attr(Attribute(name, attr_type, vec_a)); \
return *this; \
} \
OpSchema &OpSchema::Attr(const std::string &name, AttributeType attr_type, const Tuple<Type> &default_value) { \
if (attrtype != attr_type) { \
return *this; \
} \
domi::AttrDef tuple_a; \
for (const auto &v : default_value) { \
tuple_a.mutable_list()->add_##field(v); \
} \
Attr(Attribute(name, attr_type, tuple_a)); \
return *this; \
}

#endif
ATTR_SETTER_WITH_SINGLE_VALUE(uint32_t, u, AttributeType::UINT)
ATTR_SETTER_WITH_SINGLE_VALUE(int64_t, i, AttributeType::INT)
ATTR_SETTER_WITH_SINGLE_VALUE(bool, b, AttributeType::BOOL)
ATTR_SETTER_WITH_SINGLE_VALUE(float, f, AttributeType::FLOAT)
ATTR_SETTER_WITH_SINGLE_VALUE(std::string, s, AttributeType::STRING)

ATTR_SETTER_WITH_LIST_VALUE(uint32_t, u, AttributeType::UINTLIST)
ATTR_SETTER_WITH_LIST_VALUE(int64_t, i, AttributeType::INTLIST)
ATTR_SETTER_WITH_LIST_VALUE(bool, b, AttributeType::BOOLLIST)
ATTR_SETTER_WITH_LIST_VALUE(float, f, AttributeType::FLOATLIST)
ATTR_SETTER_WITH_LIST_VALUE(std::string, s, AttributeType::STRINGLIST)

OpSchema &OpSchema::AttrRequired(const std::string &name, AttributeType attr_type) {
Attr(Attribute(name, attr_type, true));
return *this;
}

bool OpSchema::HasDefaultAttr(const std::string &name) const {
auto it = attributes_.find(name);
if (it == attributes_.end()) {
return false;
}

// required does not need a default value
return !it->second.required_;
}

const domi::AttrDef &OpSchema::GetDefaultAttr(const std::string &name) const {
auto it = attributes_.find(name);
if (it == attributes_.end()) {
const static domi::AttrDef attr_def;
return attr_def;
}
return it->second.default_value_;
}

bool OpSchema::Verify(const ge::OpDescPtr op_def) const {
if (op_def->GetType() != name_) {
REPORT_INNER_ERROR("E19999", "Name not math, op schema name: %s, opdef type: %s.",
name_.c_str(), op_def->GetType().c_str());
GELOGE(FAILED, "[Check][Param]Name not math, op schema name: %s, opdef type: %s.",
name_.c_str(), op_def->GetType().c_str());
return false;
}

// Required field verification
for (const auto &pair : attributes_) {
const auto &attr = pair.second;
if (!attr.required_) {
continue;
}
if (!op_def->HasAttr(attr.name_)) {
REPORT_INNER_ERROR("E19999", "Required attribute: %s of op: %s is missing.",
attr.name_.c_str(), op_def->GetName().c_str());
GELOGE(FAILED, "[Invoke][HasAttr]Required attribute: %s of op: %s is missing.",
attr.name_.c_str(), op_def->GetName().c_str());
return false;
}
}

return true;
}

OpSchemaFactory &OpSchemaFactory::Instance() {
static OpSchemaFactory instance;
return instance;
}

const OpSchema *OpSchemaFactory::Get(const std::string &op) const {
auto it = op_schema_map_.find(op);
if (it == op_schema_map_.end()) {
return nullptr;
}
return &it->second;
}

OpSchemaRegistry::OpSchemaRegistry(OpSchema &op_schema) {
OpSchemaFactory &op_factory = OpSchemaFactory::Instance();

// save op_schema to the map
if (op_factory.op_schema_map_.count(op_schema.name_)) {
GELOGD("Failed to register op schema: %s., reason: already exist!", op_schema.name_.c_str());
return;
}

(void)op_factory.op_schema_map_.emplace(std::make_pair(op_schema.name_, op_schema));
}
} // namespace ge

+ 0
- 175
parser/common/op_def/op_schema.h View File

@@ -1,175 +0,0 @@
/**
* Copyright 2020 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 DOMI_COMMON_OP_SCHEMA_H
#define DOMI_COMMON_OP_SCHEMA_H

#include <string>
#include <unordered_map>
#include <vector>
#include "common/tuple.h"
#include "graph/op_desc.h"
#include "proto/om.pb.h"
#include "framework/common/fmk_types.h"

namespace ge {
enum class AttributeType {
UNDEFINED,
INT,
UINT,
BOOL,
FLOAT,
STRING,
BYTES,

INTLIST,
UINTLIST,
BOOLLIST,
FLOATLIST,
STRINGLIST
};

class OpSchema;

class OpSchemaRegistry;

class FMK_FUNC_HOST_VISIBILITY OpSchema {
public:
// Formal parameter options.
enum FormalParameterOption {
// The input formal parameter is single and not optional.
// Number of this input is 1.
Single = 0,
// The input formal parameter is single and optional.
// Number of this input is 0 or 1.
Optional = 1,
// The input formal parameter is variadic.
// Number of this input is [1, n].
Variadic = 2,
};

// Formal parameter represenation, including input/output name, typeStr,
// description, and type constraints.
class FormalParameter {
public:
// Constructor.
FormalParameter() = default;

explicit FormalParameter(const std::string &name, FormalParameterOption param_option = Single);

~FormalParameter();

// Get formal parameter name.
const std::string &Name() const;

// Get the parameter option, it could be Single, Optional or Variadic.
FormalParameterOption Option() const;

private:
friend class OpSchema;

// Formal parameter name.
std::string name_;

// Formal parameter option.
FormalParameterOption param_option_;
};

explicit OpSchema(const std::string &name);

~OpSchema();

OpSchema &Input(const std::string &name, FormalParameterOption param_option = Single);

OpSchema &Output(const std::string &name, FormalParameterOption param_option = Single);

struct Attribute {
Attribute(const std::string &name, AttributeType type, bool required)
: name_(name), type_(type), required_(required) {}

Attribute(const std::string &name, AttributeType type, domi::AttrDef default_value)
: name_(name), type_(type), required_(false), default_value_(default_value) {}

const std::string name_;
AttributeType type_;
bool required_;
domi::AttrDef default_value_;
};

OpSchema &Attr(const Attribute &attr);

// Register "optional" attribute with default value.
#define ATTR_SETTER_WITH_DEFAULT_VALUE(TypeName) \
OpSchema &Attr(const std::string &name, AttributeType type, const TypeName &default_value); \
OpSchema &Attr(const std::string &name, AttributeType type, const std::vector<TypeName> &default_value); \
OpSchema &Attr(const std::string &name, AttributeType type, const Tuple<TypeName> &default_value);

ATTR_SETTER_WITH_DEFAULT_VALUE(uint32_t)
ATTR_SETTER_WITH_DEFAULT_VALUE(int64_t)
ATTR_SETTER_WITH_DEFAULT_VALUE(bool)
ATTR_SETTER_WITH_DEFAULT_VALUE(float)
ATTR_SETTER_WITH_DEFAULT_VALUE(std::string)

// Register "required" attribute without default value.
OpSchema &AttrRequired(const std::string &name, AttributeType type);

bool HasDefaultAttr(const std::string &name) const;

const domi::AttrDef &GetDefaultAttr(const std::string &name) const;

// verify op_def
bool Verify(const ge::OpDescPtr op_def) const;

private:
friend class OpSchemaRegistry;

std::string name_;

std::vector<FormalParameter> inputs_;

std::vector<FormalParameter> outputs_;

std::unordered_map<std::string, Attribute> attributes_;
};

class OpSchemaFactory {
public:
// this is a singleton object
static OpSchemaFactory &Instance();

const OpSchema *Get(const std::string &op) const;

private:
OpSchemaFactory() = default;
~OpSchemaFactory() = default;

friend class OpSchemaRegistry;
// the op schema map
std::unordered_map<std::string, OpSchema> op_schema_map_;
};

class FMK_FUNC_HOST_VISIBILITY OpSchemaRegistry {
public:
OpSchemaRegistry(OpSchema &op_schema);
~OpSchemaRegistry() = default;
};

#define DOMI_OP_SCHEMA(name) DOMI_OP_SCHEMA_UNIQ_HELPER(__COUNTER__, name)
#define DOMI_OP_SCHEMA_UNIQ_HELPER(ctr, name) DOMI_OP_SCHEMA_UNIQ(ctr, name)
#define DOMI_OP_SCHEMA_UNIQ(ctr, name) \
static OpSchemaRegistry op_schema_registry##ctr __attribute__((unused)) = OpSchema(#name)
} // namespace ge
#endif // DOMI_COMMON_OP_SCHEMA_H

+ 4
- 18
parser/common/op_def/operator.cc View File

@@ -27,13 +27,7 @@ using ge::StringTuple;
using ge::UintTuple;

namespace ge {
ParserOperator::ParserOperator(const std::string &type) {
type_ = type;
op_schema_ = ge::OpSchemaFactory::Instance().Get(type);
if (op_schema_ == nullptr) {
GELOGW("Cannot find op schema of op type: %s", type.c_str());
}
}
ParserOperator::ParserOperator(const std::string &type) : type_(type) {}

ParserOperator &ParserOperator::Input(const ParserOperator &in_op, uint32_t index) {
if (index == 0) {
@@ -61,14 +55,14 @@ FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY ParserOperator &ParserOperator:
}

FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY ParserOperator &ParserOperator::OutputTensorDesc(
const ge::GeTensorDesc &output_tensordesc) {
const ge::GeTensorDesc &output_tensordesc) {
output_descs_.push_back(output_tensordesc);
return *this;
}

FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY ParserOperator &ParserOperator::AttrVector(
std::string key,
std::vector<int32_t> &value) {
std::string key,
std::vector<int32_t> &value) {
domi::AttrDef out;
auto it = op_attrs_.find(key);
if (it != op_attrs_.end()) {
@@ -159,10 +153,6 @@ ATTR_SETTER_WITH_LIST_VALUE(uint32_t, i)
auto it = op_attrs_.find(name); \
if (it != op_attrs_.end()) { \
single_val = it->second.value_; \
} else { \
if (op_schema_ && op_schema_->HasDefaultAttr(name)) { \
single_val = op_schema_->GetDefaultAttr(name); \
} \
} \
return single_val.field(); \
}
@@ -178,10 +168,6 @@ ATTR_GET_SINGLE_VALUE(std::string, s, String)
auto it = op_attrs_.find(name); \
if (it != op_attrs_.end()) { \
value = it->second.value_; \
} else { \
if (op_schema_ && op_schema_->HasDefaultAttr(name)) { \
value = op_schema_->GetDefaultAttr(name); \
} \
} \
const auto attr_def = value.list(); \
std::size_t n = attr_def.field##_size(); \


+ 21
- 16
parser/common/op_def/operator.h View File

@@ -21,7 +21,6 @@
#include <unordered_map>
#include <vector>
#include "framework/common/fmk_types.h"
#include "common/op_def/op_schema.h"
#include "common/tuple.h"
#include "graph/ge_tensor.h"
#include "proto/om.pb.h"
@@ -35,9 +34,9 @@ struct OpAttribute {
class FMK_FUNC_HOST_VISIBILITY ParserOperator {
public:
explicit ParserOperator(const std::string &type);
ParserOperator() { op_schema_ = nullptr; }
ParserOperator() {}

virtual ~ParserOperator() { op_schema_ = nullptr; }
virtual ~ParserOperator() = default;

ParserOperator &Input(const ParserOperator &in_op, uint32_t index = 0);

@@ -56,17 +55,26 @@ class FMK_FUNC_HOST_VISIBILITY ParserOperator {

ParserOperator &Attr_bt(const std::string &name, const std::string &value);

// Register "optional" attribute with default value.
#define ATTR_SETTER_WITH_VALUE(TypeName) \
ParserOperator &Attr(const std::string &name, const TypeName &value); \
ParserOperator &Attr(const std::string &name, const std::vector<TypeName> &value); \
ParserOperator &Attr(const std::string &name, const ge::Tuple<TypeName> &value)
// Register "optional" attribute with default value.
ParserOperator &Attr(const std::string &name, const uint32_t &value);
ParserOperator &Attr(const std::string &name, const std::vector<uint32_t> &value);
ParserOperator &Attr(const std::string &name, const ge::Tuple<uint32_t> &value);

ATTR_SETTER_WITH_VALUE(uint32_t);
ATTR_SETTER_WITH_VALUE(int64_t);
ATTR_SETTER_WITH_VALUE(bool);
ATTR_SETTER_WITH_VALUE(float);
ATTR_SETTER_WITH_VALUE(std::string);
ParserOperator &Attr(const std::string &name, const int64_t &value);
ParserOperator &Attr(const std::string &name, const std::vector<int64_t> &value);
ParserOperator &Attr(const std::string &name, const ge::Tuple<int64_t> &value);

ParserOperator &Attr(const std::string &name, const bool &value);
ParserOperator &Attr(const std::string &name, const std::vector<bool> &value);
ParserOperator &Attr(const std::string &name, const ge::Tuple<bool> &value);

ParserOperator &Attr(const std::string &name, const float &value);
ParserOperator &Attr(const std::string &name, const std::vector<float> &value);
ParserOperator &Attr(const std::string &name, const ge::Tuple<float> &value);

ParserOperator &Attr(const std::string &name, const std::string &value);
ParserOperator &Attr(const std::string &name, const std::vector<std::string> &value);
ParserOperator &Attr(const std::string &name, const ge::Tuple<std::string> &value);

const std::string &GetName() const { return name_; }

@@ -82,8 +90,6 @@ class FMK_FUNC_HOST_VISIBILITY ParserOperator {

bool HasAttr(const std::string &name) const { return op_attrs_.find(name) != op_attrs_.end(); }

const ge::OpSchema *GetSchema() const { return op_schema_; }

int64_t GetIntAttr(const std::string &name) const;

uint32_t GetUintAttr(const std::string &name) const;
@@ -105,7 +111,6 @@ class FMK_FUNC_HOST_VISIBILITY ParserOperator {
ge::StringTuple GetStringTupleAttr(const std::string &name) const;

private:
const ge::OpSchema *op_schema_;
std::string name_;
std::string type_;
std::vector<std::string> inputs_;


+ 0
- 2
tests/st/CMakeLists.txt View File

@@ -246,13 +246,11 @@ set(PARSER_SRC_FILES
"${PARSER_DIR}/parser/common/model_saver.cc"
"${PARSER_DIR}/parser/common/op_def/arg_op.cc"
"${PARSER_DIR}/parser/common/op_def/constant_op.cc"
"${PARSER_DIR}/parser/common/op_def/defs.cc"
"${PARSER_DIR}/parser/common/op_def/fill_op.cc"
"${PARSER_DIR}/parser/common/op_def/frameworkop_op.cc"
"${PARSER_DIR}/parser/common/op_def/ir_pb_converter.cc"
"${PARSER_DIR}/parser/common/op_def/no_op_op.cc"
"${PARSER_DIR}/parser/common/op_def/operator.cc"
"${PARSER_DIR}/parser/common/op_def/op_schema.cc"
"${PARSER_DIR}/parser/common/op_def/ref_switch_op.cc"
"${PARSER_DIR}/parser/common/op_def/shape_n_op.cc"
"${PARSER_DIR}/parser/common/op_def/variable_op.cc"


+ 1
- 0
tests/st/testcase/test_tensorflow_parser.cc View File

@@ -78,6 +78,7 @@ TEST_F(STestTensorflowParser, tensorflow_parser_success) {
RegisterCustomOp();

std::string case_dir = __FILE__;
ParserOperator unused("Add");
case_dir = case_dir.substr(0, case_dir.find_last_of("/"));
std::string model_file = case_dir + "/origin_models/tf_add.pb";
std::map<ge::AscendString, ge::AscendString> parser_params;


+ 0
- 2
tests/ut/parser/CMakeLists.txt View File

@@ -247,13 +247,11 @@ set(PARSER_SRC_FILES
"${PARSER_DIR}/parser/common/model_saver.cc"
"${PARSER_DIR}/parser/common/op_def/arg_op.cc"
"${PARSER_DIR}/parser/common/op_def/constant_op.cc"
"${PARSER_DIR}/parser/common/op_def/defs.cc"
"${PARSER_DIR}/parser/common/op_def/fill_op.cc"
"${PARSER_DIR}/parser/common/op_def/frameworkop_op.cc"
"${PARSER_DIR}/parser/common/op_def/ir_pb_converter.cc"
"${PARSER_DIR}/parser/common/op_def/no_op_op.cc"
"${PARSER_DIR}/parser/common/op_def/operator.cc"
"${PARSER_DIR}/parser/common/op_def/op_schema.cc"
"${PARSER_DIR}/parser/common/op_def/ref_switch_op.cc"
"${PARSER_DIR}/parser/common/op_def/shape_n_op.cc"
"${PARSER_DIR}/parser/common/op_def/variable_op.cc"


+ 1
- 0
tests/ut/parser/testcase/tensorflow_parser_testcase/tensorflow_parser_unittest.cc View File

@@ -86,6 +86,7 @@ TEST_F(UtestTensorflowParser, tensorflow_parser_success) {
RegisterCustomOp();

std::string case_dir = __FILE__;
ParserOperator unused("Add");
case_dir = case_dir.substr(0, case_dir.find_last_of("/"));
std::string model_file = case_dir + "/tensorflow_model/add.pb";
std::map<ge::AscendString, ge::AscendString> parser_params;


Loading…
Cancel
Save