From 3ae2d41eb884bed639b00fea65b84e9472f046a8 Mon Sep 17 00:00:00 2001 From: jwx930962 Date: Mon, 22 Nov 2021 18:53:14 +0800 Subject: [PATCH] increase parser st --- tests/depends/ops_stub/ops_stub.h | 208 ++++ .../st/testcase/origin_models/avgpool3dgrad.pb.txt | Bin 0 -> 416 bytes tests/st/testcase/origin_models/conv2d.pb | Bin 0 -> 356 bytes .../origin_models/conv2d_depthwise_pb_gen.py | 26 + tests/st/testcase/origin_models/merge.pb | Bin 0 -> 234 bytes tests/st/testcase/origin_models/model.pb | Bin 0 -> 660 bytes tests/st/testcase/origin_models/tensor_array.pb | Bin 0 -> 529 bytes .../testcase/origin_models/tensor_array_pb_gen.py | 14 + tests/st/testcase/origin_models/test.json | 71 ++ .../origin_models/test_VarIsInitializedOp.pb | Bin 0 -> 563 bytes .../test_VarIsInitializedOp_pb_gen.py | 14 + tests/st/testcase/origin_models/test_VariableV2.pb | Bin 0 -> 223 bytes .../origin_models/test_avgpool3dgrad_pb_gen.py | 41 + .../origin_models/test_blocklstm_pb.gen.py | 34 + tests/st/testcase/origin_models/test_constant.pb | Bin 0 -> 416 bytes .../testcase/origin_models/test_constant_pb_gen.py | 21 + .../testcase/origin_models/test_conv2d_pb_gen.py | 26 + .../origin_models/test_depth_wise_conv2d.pb | Bin 0 -> 764 bytes tests/st/testcase/origin_models/test_enter.pb | Bin 0 -> 337 bytes .../st/testcase/origin_models/test_enter_pb_gen.py | 13 + tests/st/testcase/origin_models/test_fill.pb | Bin 0 -> 289 bytes .../st/testcase/origin_models/test_fill_pb_gen.py | 12 + tests/st/testcase/origin_models/test_identity.pb | Bin 0 -> 210 bytes .../testcase/origin_models/test_identity_pb_gen.py | 13 + .../st/testcase/origin_models/test_merge_pb_gen.py | 18 + tests/st/testcase/origin_models/test_no_op.pb | Bin 0 -> 179 bytes .../st/testcase/origin_models/test_no_op_pb_gen.py | 14 + tests/st/testcase/origin_models/test_reshape.pb | Bin 0 -> 206 bytes .../testcase/origin_models/test_reshape_pb_gen.py | 10 + tests/st/testcase/origin_models/test_sequeeze.pb | Bin 0 -> 234 bytes .../testcase/origin_models/test_sequeeze_pb_gen.py | 13 + tests/st/testcase/origin_models/test_shape_n.pb | Bin 0 -> 272 bytes .../testcase/origin_models/test_shape_n_pb_gen.py | 11 + tests/st/testcase/origin_models/test_switch.pb | Bin 0 -> 339 bytes .../testcase/origin_models/test_switch_pb_gen.py | 13 + .../origin_models/test_variableV2_pb_gen.py | 13 + tests/st/testcase/test_tensorflow_parser.cc | 1056 +++++++++++++++++++- 37 files changed, 1640 insertions(+), 1 deletion(-) create mode 100644 tests/st/testcase/origin_models/avgpool3dgrad.pb.txt create mode 100644 tests/st/testcase/origin_models/conv2d.pb create mode 100644 tests/st/testcase/origin_models/conv2d_depthwise_pb_gen.py create mode 100644 tests/st/testcase/origin_models/merge.pb create mode 100644 tests/st/testcase/origin_models/model.pb create mode 100644 tests/st/testcase/origin_models/tensor_array.pb create mode 100644 tests/st/testcase/origin_models/tensor_array_pb_gen.py create mode 100644 tests/st/testcase/origin_models/test.json create mode 100644 tests/st/testcase/origin_models/test_VarIsInitializedOp.pb create mode 100644 tests/st/testcase/origin_models/test_VarIsInitializedOp_pb_gen.py create mode 100644 tests/st/testcase/origin_models/test_VariableV2.pb create mode 100644 tests/st/testcase/origin_models/test_avgpool3dgrad_pb_gen.py create mode 100644 tests/st/testcase/origin_models/test_blocklstm_pb.gen.py create mode 100644 tests/st/testcase/origin_models/test_constant.pb create mode 100644 tests/st/testcase/origin_models/test_constant_pb_gen.py create mode 100644 tests/st/testcase/origin_models/test_conv2d_pb_gen.py create mode 100644 tests/st/testcase/origin_models/test_depth_wise_conv2d.pb create mode 100644 tests/st/testcase/origin_models/test_enter.pb create mode 100644 tests/st/testcase/origin_models/test_enter_pb_gen.py create mode 100644 tests/st/testcase/origin_models/test_fill.pb create mode 100644 tests/st/testcase/origin_models/test_fill_pb_gen.py create mode 100644 tests/st/testcase/origin_models/test_identity.pb create mode 100644 tests/st/testcase/origin_models/test_identity_pb_gen.py create mode 100644 tests/st/testcase/origin_models/test_merge_pb_gen.py create mode 100644 tests/st/testcase/origin_models/test_no_op.pb create mode 100644 tests/st/testcase/origin_models/test_no_op_pb_gen.py create mode 100644 tests/st/testcase/origin_models/test_reshape.pb create mode 100644 tests/st/testcase/origin_models/test_reshape_pb_gen.py create mode 100644 tests/st/testcase/origin_models/test_sequeeze.pb create mode 100644 tests/st/testcase/origin_models/test_sequeeze_pb_gen.py create mode 100644 tests/st/testcase/origin_models/test_shape_n.pb create mode 100644 tests/st/testcase/origin_models/test_shape_n_pb_gen.py create mode 100644 tests/st/testcase/origin_models/test_switch.pb create mode 100644 tests/st/testcase/origin_models/test_switch_pb_gen.py create mode 100644 tests/st/testcase/origin_models/test_variableV2_pb_gen.py diff --git a/tests/depends/ops_stub/ops_stub.h b/tests/depends/ops_stub/ops_stub.h index 0299df1..2a261a8 100644 --- a/tests/depends/ops_stub/ops_stub.h +++ b/tests/depends/ops_stub/ops_stub.h @@ -108,6 +108,183 @@ REG_OP(PartitionedCall) .ATTR(config_proto, String, "") .ATTR(executor_type, String, "") .OP_END_FACTORY_REG(PartitionedCall) +REG_OP(TensorArray) + .INPUT(size, TensorType({DT_INT32})) + .OUTPUT(handle, TensorType({DT_RESOURCE})) + .OUTPUT(flow, TensorType({DT_FLOAT})) + .REQUIRED_ATTR(dtype, Type) + .ATTR(element_shape, ListInt, ge::UNKNOWN_RANK) + .ATTR(dynamic_size, Bool, false) + .ATTR(clear_after_read, Bool, true) + .ATTR(identical_element_shapes, Bool, false) + .ATTR(tensor_array_name, String, "") + .OP_END_FACTORY_REG(TensorArray) + +REG_OP(TensorArrayWrite) + .INPUT(handle, TensorType({DT_RESOURCE})) + .INPUT(index, TensorType({DT_INT32})) + .INPUT(value, TensorType({DT_FLOAT, DT_FLOAT16, DT_DOUBLE, DT_INT8, + DT_INT16, DT_UINT16, DT_UINT8, DT_INT32, DT_INT64, DT_BOOL, + DT_STRING, DT_COMPLEX64, DT_COMPLEX128})) + .INPUT(flow_in, TensorType({DT_FLOAT})) + .OUTPUT(flow_out, TensorType({DT_FLOAT})) + .OP_END_FACTORY_REG(TensorArrayWrite) + +REG_OP(AvgPool3DGrad) + .INPUT(orig_input_shape, TensorType({DT_INT32})) + .INPUT(grads, TensorType({DT_FLOAT16, DT_FLOAT32, DT_DOUBLE})) + .OUTPUT(output, TensorType({DT_FLOAT16, DT_FLOAT32, DT_DOUBLE})) + .REQUIRED_ATTR(ksize, ListInt) + .REQUIRED_ATTR(strides, ListInt) + .REQUIRED_ATTR(pads, ListInt) + .ATTR(ceil_mode, Bool, false) + .ATTR(count_include_pad, Bool, true) + .ATTR(divisor_override, Int, 0) + .ATTR(data_format, String, "NDHWC") + .OP_END_FACTORY_REG(AvgPool3DGrad) + +REG_OP(Merge) + .DYNAMIC_INPUT(x, TensorType({DT_FLOAT16, DT_FLOAT, DT_DOUBLE, + DT_INT8, DT_INT16, DT_INT32, DT_INT64, DT_UINT8, DT_UINT16, DT_UINT32, + DT_UINT64, DT_BOOL})) + .OUTPUT(y, TensorType({DT_FLOAT16, DT_FLOAT, DT_DOUBLE, + DT_INT8, DT_INT16, DT_INT32, DT_INT64, DT_UINT8, DT_UINT16, DT_UINT32, + DT_UINT64, DT_BOOL})) + .OUTPUT(value_index, TensorType({DT_INT32})) + .OP_END_FACTORY_REG(Merge) + +REG_OP(NoOp) + .OP_END_FACTORY_REG(NoOp) + +REG_OP(VarIsInitializedOp) + .INPUT(x, TensorType({DT_FLOAT, DT_FLOAT16, DT_INT8, DT_INT16, DT_UINT16, DT_UINT8, + DT_INT32, DT_INT64, DT_UINT32, DT_UINT64, DT_BOOL, DT_DOUBLE})) + .OUTPUT(y, TensorType({DT_BOOL})) + .OP_END_FACTORY_REG(VarIsInitializedOp) + +REG_OP(AssignVariableOp) + .INPUT(resource, TensorType({DT_RESOURCE})) + .INPUT(value, TensorType({DT_FLOAT, DT_FLOAT16, DT_INT8, DT_INT16, \ + DT_UINT16, DT_UINT8, DT_INT32, DT_INT64, DT_BOOL, DT_DOUBLE})) + .REQUIRED_ATTR(dtype, Type) + .OP_END_FACTORY_REG(AssignVariableOp) + +REG_OP(ReadVariableOp) + .INPUT(x, TensorType({DT_FLOAT, DT_FLOAT16, DT_INT8, DT_INT16, DT_UINT16, DT_UINT8, + DT_INT32, DT_INT64, DT_UINT32, DT_UINT64, DT_BOOL, DT_DOUBLE})) + .OUTPUT(y, TensorType({DT_FLOAT, DT_FLOAT16, DT_INT8, DT_INT16, DT_UINT16, DT_UINT8, + DT_INT32, DT_INT64, DT_UINT32, DT_UINT64, DT_BOOL, DT_DOUBLE})) + .ATTR(dtype, Int, DT_INT32) + .OP_END_FACTORY_REG(ReadVariableOp) + +REG_OP(Reshape) + .INPUT(x, TensorType({DT_FLOAT, DT_FLOAT16, DT_INT8, DT_INT16, DT_UINT16, DT_UINT8, DT_INT32, + DT_INT64, DT_UINT32, DT_UINT64, DT_BOOL, DT_DOUBLE})) + .INPUT(shape, TensorType({DT_INT32, DT_INT64})) + .OUTPUT(y, TensorType({DT_FLOAT, DT_FLOAT16, DT_INT8, DT_INT16, DT_UINT16, DT_UINT8, DT_INT32, + DT_INT64, DT_UINT32, DT_UINT64, DT_BOOL, DT_DOUBLE})) + .ATTR(axis, Int, 0) + .ATTR(num_axes, Int, -1) + .OP_END_FACTORY_REG(Reshape) + +REG_OP(VarHandleOp) + .ATTR(container, String, "") + .ATTR(shared_name, String, "") + .REQUIRED_ATTR(dtype, Type) + .ATTR(shape, ListInt, ge::UNKNOWN_SHAPE) + .OUTPUT(y, TensorType({DT_RESOURCE})) + .OP_END_FACTORY_REG(VarHandleOp) + +REG_OP(Squeeze) + .INPUT(x, TensorType::ALL()) + .OUTPUT(y, TensorType::ALL()) + .ATTR(axis, ListInt, {}) + .OP_END_FACTORY_REG(Squeeze) + +REG_OP(Fill) + .INPUT(dims, TensorType::IndexNumberType()) + .INPUT(value, TensorType({DT_FLOAT, DT_DOUBLE, DT_INT32, DT_UINT8, DT_INT16, + DT_INT8, DT_COMPLEX64, DT_INT64, DT_BOOL, DT_QINT8, + DT_QUINT8, DT_QINT32, DT_QINT16, DT_QUINT16, DT_UINT16, + DT_COMPLEX128, DT_FLOAT16, DT_UINT32, DT_UINT64})) + .OUTPUT(y, TensorType({DT_FLOAT, DT_DOUBLE, DT_INT32, DT_UINT8, DT_INT16, + DT_INT8, DT_COMPLEX64, DT_INT64, DT_BOOL, DT_QINT8, + DT_QUINT8, DT_QINT32, DT_QINT16, DT_QUINT16, DT_UINT16, + DT_COMPLEX128, DT_FLOAT16, DT_UINT32, DT_UINT64})) + .OP_END_FACTORY_REG(Fill) + +REG_OP(ShapeN) + .DYNAMIC_INPUT(x, TensorType({DT_FLOAT, DT_FLOAT16, DT_INT8, DT_INT16, DT_UINT16, DT_UINT8, + DT_INT32, DT_INT64, DT_UINT32, DT_UINT64, DT_BOOL, DT_DOUBLE})) + .DYNAMIC_OUTPUT(y, TensorType({DT_INT32, DT_INT64})) + .ATTR(dtype, Int, DT_INT32) + .OP_END_FACTORY_REG(ShapeN) + +REG_OP(Switch) + .INPUT(data, TensorType({DT_FLOAT16, DT_FLOAT, DT_DOUBLE, + DT_INT8, DT_INT16, DT_INT32, DT_INT64, DT_UINT8, DT_UINT16, DT_UINT32, + DT_UINT64, DT_BOOL})) + .INPUT(pred, TensorType({DT_BOOL})) + .OUTPUT(output_false, TensorType({DT_FLOAT16, DT_FLOAT, DT_DOUBLE, + DT_INT8, DT_INT16, DT_INT32, DT_INT64, DT_UINT8, DT_UINT16, DT_UINT32, + DT_UINT64, DT_BOOL})) + .OUTPUT(output_true, TensorType({DT_FLOAT16, DT_FLOAT, DT_DOUBLE, + DT_INT8, DT_INT16, DT_INT32, DT_INT64, DT_UINT8, DT_UINT16, DT_UINT32, + DT_UINT64, DT_BOOL})) + .OP_END_FACTORY_REG(Switch) + +REG_OP(RefSwitch) + .INPUT(data, TensorType({DT_FLOAT16, DT_FLOAT, DT_DOUBLE, + DT_INT8, DT_INT16, DT_INT32, DT_INT64, DT_UINT8, DT_UINT16, DT_UINT32, + DT_UINT64, DT_BOOL})) + .INPUT(pred, TensorType({DT_BOOL})) + .OUTPUT(output_false, TensorType({DT_FLOAT16, DT_FLOAT, DT_DOUBLE, + DT_INT8, DT_INT16, DT_INT32, DT_INT64, DT_UINT8, DT_UINT16, DT_UINT32, + DT_UINT64, DT_BOOL})) + .OUTPUT(output_true, TensorType({DT_FLOAT16, DT_FLOAT, DT_DOUBLE, + DT_INT8, DT_INT16, DT_INT32, DT_INT64, DT_UINT8, DT_UINT16, DT_UINT32, + DT_UINT64, DT_BOOL})) + .OP_END_FACTORY_REG(RefSwitch) + +REG_OP(Enter) + .INPUT(x, TensorType({DT_FLOAT16, DT_FLOAT, DT_DOUBLE, + DT_INT8, DT_INT16, DT_INT32, DT_INT64, DT_UINT8, DT_UINT16, DT_UINT32, + DT_UINT64, DT_BOOL})) + .OUTPUT(y, TensorType({DT_FLOAT16, DT_FLOAT, DT_DOUBLE, + DT_INT8, DT_INT16, DT_INT32, DT_INT64, DT_UINT8, DT_UINT16, DT_UINT32, + DT_UINT64, DT_BOOL})) + .REQUIRED_ATTR(frame_name, String) + .REQUIRED_ATTR(is_constant, Bool) + .OP_END_FACTORY_REG(Enter) + +REG_OP(VariableV2) + .INPUT(x, TensorType({DT_FLOAT, DT_FLOAT16, DT_INT8, DT_INT16, DT_UINT16, \ + DT_UINT8, DT_INT32, DT_INT64, DT_UINT32, DT_UINT64, DT_BOOL, DT_DOUBLE})) + .OUTPUT(y, TensorType({DT_FLOAT, DT_FLOAT16, DT_INT8, DT_INT16, DT_UINT16, \ + DT_UINT8, DT_INT32, DT_INT64, DT_UINT32, DT_UINT64, DT_BOOL, DT_DOUBLE})) + .ATTR(index, Int, 0) + .ATTR(value, Tensor, Tensor()) + .ATTR(container, String, "") + .ATTR(shared_name, String, "") + .OP_END_FACTORY_REG(VariableV2) + +REG_OP(Constant) + .OUTPUT(y, TensorType({DT_FLOAT, DT_FLOAT16, DT_INT8, DT_INT16, DT_UINT16, + DT_UINT8, DT_INT32, DT_INT64, DT_UINT32, DT_UINT64, DT_BOOL, DT_DOUBLE})) + .ATTR(value, Tensor, Tensor()) + .OP_END_FACTORY_REG(Constant) + +REG_OP(Mul) + .INPUT(x1, TensorType({DT_FLOAT16, DT_FLOAT, DT_DOUBLE, DT_UINT8, DT_INT8, + DI_UINT16, DT_INT16, DT_INT32, DT_INT64, + DT_COMPLEX64, DT_COMPLEX128})) + .INPUT(x2, TensorType({DT_FLOAT16, DT_FLOAT, DT_DOUBLE, DT_UINT8, DT_INT8, + DI_UINT16, DT_INT16, DT_INT32, DT_INT64, + DT_COMPLEX64, DT_COMPLEX128})) + .OUTPUT(y, TensorType({DT_FLOAT16, DT_FLOAT, DT_DOUBLE, DT_UINT8, DT_INT8, + DI_UINT16, DT_INT16, DT_INT32, DT_INT64, + DT_COMPLEX64, DT_COMPLEX128})) + .OP_END_FACTORY_REG(Mul) // for plugin static Status ParseParamsStub(const google::protobuf::Message* op_src, ge::Operator& op_dest) { @@ -209,5 +386,36 @@ REGISTER_CUSTOM_OP("PartitionedCall") .OriginOpType({"ai.onnx::9::Clip"}) .ParseParamsFn(ParseParamsClipV9Stub) .ParseOpToGraphFn(ParseOpToGraphClipV9Stub); +REGISTER_CUSTOM_OP("TensorArray") + .FrameworkType(domi::TENSORFLOW) + .OriginOpType("TensorArrayV3") + .ParseParamsFn(ParseParamsStub); + +REGISTER_CUSTOM_OP("TensorArrayWrite") + .FrameworkType(domi::TENSORFLOW) + .OriginOpType("TensorArrayWriteV3") + .ParseParamsFn(ParseParamsStub); + +REGISTER_CUSTOM_OP("DynamicRNN") + .FrameworkType(domi::TENSORFLOW) + .OriginOpType("BlockLSTM") + .ParseParamsFn(ParseParamsStub); + +REGISTER_CUSTOM_OP("Merge") + .FrameworkType(domi::TENSORFLOW) + .OriginOpType("HistogramSummary") + .ParseParamsFn(ParseParamsStub); + +REGISTER_CUSTOM_OP("NoOp") + .FrameworkType(domi::TENSORFLOW) + .OriginOpType("NoOp") + .ParseParamsFn(ParseParamsStub); + +REGISTER_CUSTOM_OP("Fill") + .FrameworkType(domi::TENSORFLOW) + .OriginOpType("Fill") + .ParseParamsFn(ParseParamsStub); } // namespace ge + + #endif // MAIN_OPS_STUB_H diff --git a/tests/st/testcase/origin_models/avgpool3dgrad.pb.txt b/tests/st/testcase/origin_models/avgpool3dgrad.pb.txt new file mode 100644 index 0000000000000000000000000000000000000000..31f8a32f92558e2e63ed82ce256e4c3a68d20067 GIT binary patch literal 416 zcmV;R0bl+KND2#3Y+++%Xm4y}WpWY=P;6miWoU0~WMy(H3kn5fba`-P5&|$2Djy03 zb7*03WfB%T6cPdm0TKcT0TKcT0ullU0ullU0t!kB4Nz=hV`XS>Y-D9}UojF3P;6mi zWoU0~WMy(H3kn5fba`-P5&|$2Djy03b7*03WfB%T6cPdm0TKcT0TKcT0ullU0ullU z0tzn*13_eD5(7bGWEu-lY+++%Xm4y}WpWw~P;6miWoU0~WMy(+F)9ZN0aOwKFcS(! z3I#)NZgX@J1w(Icb95>T3I$|zd2nSC0x$zADGCL4VQh6}5+Fhz2m=xX5&{SXA`}4t z00031000930009300093000V!0SXO4c4ts;Z)`I}M{;3g5)DCiXHai%Y%@eha$#f| z1w(Icb95R5L1bhq2MPgH5&|$2Di#V0WMOn+UuJJ|ZDDj02NDHNLqtedDiR6>YjbIO zWfBPr2O0$d0RjR7DiR6@aA9O*X>Ml{2NDHVK}<Y-D9}UojF3P;6miWoU0~ zWMy(H3kn5fba`-P5&|#*DjNy~b7*03WfBrP5E23i0}=uV0}=uVKoSB7Knl(Q3JPOy zZgw(cUvg!05(YzWZgw(68VgWtVPj=zZ){{`avBX#Y+++%Xm4y}WpZCJDhCPyR1yL( z0V)*=3uIw*VP9r%a&2LB5(W|kPDocnDisO|WNB<+bZKvHa}o#&1{wqb0RaIjAqo*? zcyMfKV`+3>aA9O*X>Mn85)29o8VCRY0RaI4001f#3I}juWMpY>XA%k$2t`;>Oi4pY zR4Nk+2Xl0CX=G({5(o+g8Uz6W0Rbu&3J`U3WnW`;WNvO>Z*E^_aCH&_C;=h^2(bj6 CXH}K} literal 0 KcmV+b0RR6000031 diff --git a/tests/st/testcase/origin_models/conv2d_depthwise_pb_gen.py b/tests/st/testcase/origin_models/conv2d_depthwise_pb_gen.py new file mode 100644 index 0000000..7ac9c2d --- /dev/null +++ b/tests/st/testcase/origin_models/conv2d_depthwise_pb_gen.py @@ -0,0 +1,26 @@ +import tensorflow as tf +import os + +pb_file_path = os.getcwd() + +with tf.compat.v1.Session(graph=tf.Graph()) as sess: + # NHWC + fmap_shape = [17, 101, 101, 17] + filter_size = [5, 5, 17, 1] + dy_shape = [17, 49, 49, 17] + strideh, stridew = [2, 2] + padding = 'VALID' + tensor_x1 = tf.compat.v1.placeholder(dtype="float16", shape=fmap_shape) + tensor_x2 = tf.compat.v1.placeholder(dtype="float16", shape=fmap_shape) + tensor_x = tf.add(tensor_x1, tensor_x2) + tensor_dy1 = tf.compat.v1.placeholder(dtype="float16", shape=dy_shape) + tensor_dy2 = tf.compat.v1.placeholder(dtype="float16", shape=dy_shape) + tensor_dy = tf.add(tensor_dy1, tensor_dy2) + + op = tf.nn.depthwise_conv2d_backprop_filter(tensor_x, filter_size, tensor_dy, + strides=[1, strideh, stridew, 1], + padding=padding, + data_format='NHWC', + dilations=[1,1,1,1]) + + tf.io.write_graph(sess.graph, logdir="./", name="test_depth_wise_conv2d.pb", as_text=False) diff --git a/tests/st/testcase/origin_models/merge.pb b/tests/st/testcase/origin_models/merge.pb new file mode 100644 index 0000000000000000000000000000000000000000..0d2c0538af1e5285a810fce9af67f998259715e2 GIT binary patch literal 234 zcmVc42IFWfBQO2M7Za06GBy3VaFyViF5hVRA@eZe(m_ zPjD&}3I<&=$DisP3VQg$~cV%Q>WMy_~V`Xy^0tx^s4+;rm zZ*Fv9X>Mh55&{wcDhmn)WOR9OWfB4~11bv&1#@U&aAgt#IshsX3JY^+VRB_;Uv6P- zWfB7t0b&X}3L;`JNpneVX>@5}Y-xIBWG_}>a!GSZZfSIBVQgu7Wn@oq5)xKna!GSZ zZfSIBVQgu7Wn@oq8UbPoNeT#JFF|v2X=iQ{5J7WuX=iR$VRC6dS!AiX>MtBX<=+%c42IFWhx5_1!Q!2aAgt#FaruV3Ke26Qe|OeFH&V; zWL9BvX<=e)WlwMt4pL=dWL9BvX<=e)WlwM#0b(i(3I$|zd2nSC0x$y#843eUb!-v? zO?7M<0eBh#c`64A0aOwKFarua3L0;4UvzI@b98TVWiL`?VPsZea%o{=Y-LYy5)M*j zVPsZea%o{=Y-LYy8UbP|3kn5fba`-P5&|#-3Oou6Z*X69Z(nnCZ*pZ413_eD8Usyr uY#JJGa9?z9UvqSCa%C@4WnpAiVRC6Y-D9}UojF3P;6miWoU0~WMy(H3kn5fba`-P5&|#* zDiaC?b7*03WfBTH2oeGa0ullU0tz+?4Nz=hV`XS>Y-D9}UosL4P;6miWoU0~WMy(H z3kn5fba`-P5&|#-Dhmn)b7*03WfB59017q=4Nz=hV`XS>Y-D9}Uo#R5P;6miWoU0~ zWMy(H3kn5fba`-P5&|#*Dhmn)b7*03WfB5901C7L3Jp|cZgX#PL2`0oc~&zL4OC@r zb8m7%a&lpLRx=t4P;6miWoU0~WMy(H777q!Y-M3`Utwl+WpZC~Wnp9z0w@703kn5f zba`-P5&|#*DiR6|WO;63ZE0g)b7^{I5&|dyDisP1Wo%__Wo~p|b7*03WfBBB0vG`* z9ts#~WMyu2X=7n*UuA4%ZDnqBUvp?-aAk860w@3~7YY${Wo~nCa$jL`a$$L2ZeeX@ z5&{wc3T+A!RAp{+Z*oC$a$$K_a%psBRx=V3RAp{+Z*oC$a$$K_a%psBRx=t6RAp{+ zZ*oC$a$$K^Ga3z0Y+++%Xm4y}WpZCK8VyivVPj=zZ){{`a$hkT4Nz=hV`XS>Y-D9} TUo$EP3IS9S0x$t00|>DM0X3LI literal 0 KcmV+b0RR6000031 diff --git a/tests/st/testcase/origin_models/tensor_array_pb_gen.py b/tests/st/testcase/origin_models/tensor_array_pb_gen.py new file mode 100644 index 0000000..c035978 --- /dev/null +++ b/tests/st/testcase/origin_models/tensor_array_pb_gen.py @@ -0,0 +1,14 @@ +import tensorflow as tf +import os +from tensorflow.python.framework import graph_util +from tensorflow.python.ops import gen_data_flow_ops +import numpy as np + +with tf.compat.v1.Session(graph=tf.Graph()) as sess: + size = tf.compat.v1.placeholder(dtype="int32", shape=()) + value = tf.compat.v1.placeholder(dtype="float32", shape=(2,2)) + index = tf.compat.v1.placeholder(dtype="int32", shape=()) + flow = tf.compat.v1.placeholder(dtype="float32", shape=()) + handleTensor = gen_data_flow_ops.tensor_array_v3(size= size, dtype = np.float32) + output = gen_data_flow_ops.tensor_array_write_v3(handle = handleTensor[0], index=index, value=value, flow_in=flow) + tf.io.write_graph(sess.graph, logdir="./", name="tensor_array.pb", as_text=False) diff --git a/tests/st/testcase/origin_models/test.json b/tests/st/testcase/origin_models/test.json new file mode 100644 index 0000000..d1dbcc4 --- /dev/null +++ b/tests/st/testcase/origin_models/test.json @@ -0,0 +1,71 @@ +{ + "node": [ + { + "attr": [ + { + "key": "dtype", + "value": { + "type": "DT_HALF" + } + }, + { + "key": "shape", + "value": { + "shape": { + "dim": [ + { + "size": 1 + } + ] + } + } + } + ], + "name": "Placeholder", + "op": "Placeholder" + }, + { + "attr": [ + { + "key": "dtype", + "value": { + "type": "DT_HALF" + } + }, + { + "key": "shape", + "value": { + "shape": { + "dim": [ + { + "size": 1 + } + ] + } + } + } + ], + "name": "Placeholder_1", + "op": "Placeholder" + }, + { + "attr": [ + { + "key": "T", + "value": { + "type": "DT_HALF" + } + } + ], + "input": [ + "Placeholder", + "Placeholder_1" + ], + "name": "add_test_1", + "op": "Add" + } + ], + "versions": { + "producer": 134 + } +} \ No newline at end of file diff --git a/tests/st/testcase/origin_models/test_VarIsInitializedOp.pb b/tests/st/testcase/origin_models/test_VarIsInitializedOp.pb new file mode 100644 index 0000000000000000000000000000000000000000..ac9f9324a12d7aae39afcf2615722aec060387a6 GIT binary patch literal 563 zcmV-30?hpiGztq)Y+++%Xm4y}WpWY=P;6miWoU0~WMy(H3kn5fba`-P5&|#-Dhmn) zb7*03WfB59018_Q8+k8DZfSIBVQgu7WpXcRZfSIBVQgP^VQh6}5(PtVZgX@h6bc4k zV{Bn_a}o*)2oeTtZ(}+@c`6GE1!Q!2aAgt#Fas(Q3I%pyY;|Q42|@=50}=o_0Rswr z3ITZ%3szxrNMUYdY-LYyDijI^Ut?@xb8`|33J4MgY;R*aKzS+^3J+myY;SjEWM5=u zc4=c}a}ojy04fg(31e?=bYW?3WpWY%5&$X-3I$|zd2nSC0x$zA3kn5uXkl<=5&}8^ zDiR6{b7*05Wn^D&VQpm+0}=sw3OfoSc`r$GNp5L$X<=+>dSzrUR$+2Ub4hM#bZKF1 zX?kU3PjC_vR$+2Ub4hM#bZKF1X?kU3PjDImc?wAi2zf6-b8~5DZW0hdb8~5DZdPG( zX<=e)WlwM#0eKo5c`r$BX>@5}Y-xIBaxZCaX>@5}Y+rU^Y;|QS3kn5fba`-P5&|#- z3O5QBc`s6BVPr2-WnpAiVRC6Mh55&{wcDhmn) zWOR9OWfB4~11b*+1#@U&aAgt(Is_5|2m&e*3JY^+VRB_;Uv6P-WfB4s03rhju>>KG BocI6$ literal 0 KcmV+b0RR6000031 diff --git a/tests/st/testcase/origin_models/test_VarIsInitializedOp_pb_gen.py b/tests/st/testcase/origin_models/test_VarIsInitializedOp_pb_gen.py new file mode 100644 index 0000000..79d86b6 --- /dev/null +++ b/tests/st/testcase/origin_models/test_VarIsInitializedOp_pb_gen.py @@ -0,0 +1,14 @@ +import tensorflow as tf +import numpy as np + +def generate_VarIsInitializedOp_pb(): + with tf.compat.v1.Session(graph=tf.Graph()) as sess: + x = tf.compat.v1.placeholder(dtype="int32", shape=()) + y = tf.Variable(tf.compat.v1.random_normal(shape=[4,3],mean=0,stddev=1), dtype="float32", name='y') + init = tf.compat.v1.global_variables_initializer() + sess.run(init) + op = tf.compat.v1.raw_ops.VarIsInitializedOp(resource=y, name="VarIsInitializedOp") + tf.io.write_graph(sess.graph, logdir="./", name="test_VarIsInitializedOp.pb", as_text=False) + +if __name__=='__main__': + generate_VarIsInitializedOp_pb() \ No newline at end of file diff --git a/tests/st/testcase/origin_models/test_VariableV2.pb b/tests/st/testcase/origin_models/test_VariableV2.pb new file mode 100644 index 0000000000000000000000000000000000000000..1494ce5357b6b8a10a6a7972b4da30367bd5e15e GIT binary patch literal 223 zcmV<503iPgJPHd?Y+++%Xm4y}WpWY=P;6miWoU0~WMy(H3kn5fba`-P5&|#-DiaC? zb7*03WfBTH2oeGa0ullU0}5UW3RYoqX<=e)WmYm03RYoqX<=e)WmYmO4+;rmZ*Fv9 zX>Mh55&{wcDhmn)WOR9OWfB4~11b{=1#@U&aAgt-ItUU12m%rU2m>k+3JY^+VRB_; zUv6P-WfB4s016BW1Zi$*bP@zkZ%=RvED8fbWMmQpL1bha3s7ufV`XS>Y-D9}8VXin Za%o{=Y-Lt5DhCPyR1yL(10n+mu>=nCHI4uP literal 0 KcmV+b0RR6000031 diff --git a/tests/st/testcase/origin_models/test_avgpool3dgrad_pb_gen.py b/tests/st/testcase/origin_models/test_avgpool3dgrad_pb_gen.py new file mode 100644 index 0000000..a22f5ba --- /dev/null +++ b/tests/st/testcase/origin_models/test_avgpool3dgrad_pb_gen.py @@ -0,0 +1,41 @@ +import tensorflow as tf +import os +import numpy as np +from tensorflow.python.framework import graph_util + +pb_file_path = os.getcwd() + +def generate_case_1(): + with tf.compat.v1.Session(graph=tf.Graph()) as sess: + grads_1 = tf.compat.v1.placeholder(dtype="float16", shape=(1,2,2,2,1)) + grads_2 = tf.compat.v1.placeholder(dtype="float16", shape=(1,2,2,2,1)) + grads = tf.add(grads_1, grads_2) + orig_input_shape = tf.constant(np.array([1,3,3,3,1]).astype("int32")) + op = tf.raw_ops.AvgPool3DGrad(orig_input_shape=orig_input_shape, + grad=grads, + ksize=[1,2,2,2,1], + strides=[1,1,1,1,1], + padding="VALID", + data_format='NDHWC', + name='AvgPool3DGrad') + + tf.io.write_graph(sess.graph, logdir="./", name="avgpool3dgrad_case_1.pb", as_text=False) + +def generate_case_2(): + with tf.compat.v1.Session(graph=tf.Graph()) as sess: + grads_1 = tf.compat.v1.placeholder(dtype="float16", shape=(1,1,2,2,2)) + grads_2 = tf.compat.v1.placeholder(dtype="float16", shape=(1,1,2,2,2)) + grads = tf.add(grads_1, grads_2) + orig_input_shape = tf.constant(np.array([1,1,3,3,3]).astype("int32"), ) + op = tf.raw_ops.AvgPool3DGrad(orig_input_shape=orig_input_shape, + grad=grads, + ksize=[1,1,2,2,2], + strides=[1,1,1,1,1], + padding="VALID", + data_format='NCDHW', + name='AvgPool3DGrad') + + tf.io.write_graph(sess.graph, logdir="./", name="avgpool3dgrad.pb.txt", as_text=False) + +if __name__=='__main__': + generate_case_2() \ No newline at end of file diff --git a/tests/st/testcase/origin_models/test_blocklstm_pb.gen.py b/tests/st/testcase/origin_models/test_blocklstm_pb.gen.py new file mode 100644 index 0000000..b9d2908 --- /dev/null +++ b/tests/st/testcase/origin_models/test_blocklstm_pb.gen.py @@ -0,0 +1,34 @@ +import tensorflow as tf +import os + +pb_file_path = os.getcwd() + +def generate_case_0(): + with tf.compat.v1.Session(graph=tf.Graph()) as sess: + input_dtype = tf.float32 + input_shape0 = [1, ] + input_shape1 = [202, 1, 768] + input_shape2 = [1, 1] + input_shape3 = [1, 1] + input_shape4 = [769, 4] + input_shape5 = [1, ] + input_shape6 = [1, ] + input_shape7 = [1, ] + input_shape8 = [4, ] + + d0 = tf.compat.v1.placeholder(dtype=tf.int64, shape=input_shape0) + d1 = tf.compat.v1.placeholder(dtype=input_dtype, shape=input_shape1) + d2 = tf.compat.v1.placeholder(dtype=input_dtype, shape=input_shape2) + d3 = tf.compat.v1.placeholder(dtype=input_dtype, shape=input_shape3) + d4 = tf.compat.v1.placeholder(dtype=input_dtype, shape=input_shape4) + d5 = tf.compat.v1.placeholder(dtype=input_dtype, shape=input_shape5) + d6 = tf.compat.v1.placeholder(dtype=input_dtype, shape=input_shape6) + d7 = tf.compat.v1.placeholder(dtype=input_dtype, shape=input_shape7) + d8 = tf.compat.v1.placeholder(dtype=input_dtype, shape=input_shape8) + + i1, cs1, f1, o1, ci1, co1, h1 = tf.raw_ops.BlockLSTM(seq_len_max=d0, x=d1, cs_prev=d2, h_prev=d3, w=d4, wci=d5, wcf=d6, wco=d7, b=d8, + forget_bias=1, cell_clip=3, use_peephole=False, name="blockLSTM") + tf.io.write_graph(sess.graph, logdir="./", name="blocklstm_case.pb", as_text=False) + +if __name__=='__main__': + generate_case_0() diff --git a/tests/st/testcase/origin_models/test_constant.pb b/tests/st/testcase/origin_models/test_constant.pb new file mode 100644 index 0000000000000000000000000000000000000000..31f8a32f92558e2e63ed82ce256e4c3a68d20067 GIT binary patch literal 416 zcmV;R0bl+KND2#3Y+++%Xm4y}WpWY=P;6miWoU0~WMy(H3kn5fba`-P5&|$2Djy03 zb7*03WfB%T6cPdm0TKcT0TKcT0ullU0ullU0t!kB4Nz=hV`XS>Y-D9}UojF3P;6mi zWoU0~WMy(H3kn5fba`-P5&|$2Djy03b7*03WfB%T6cPdm0TKcT0TKcT0ullU0ullU z0tzn*13_eD5(7bGWEu-lY+++%Xm4y}WpWw~P;6miWoU0~WMy(+F)9ZN0aOwKFcS(! z3I#)NZgX@J1w(Icb95>T3I$|zd2nSC0x$zADGCL4VQh6}5+Fhz2m=xX5&{SXA`}4t z00031000930009300093000V!0SXO4c4ts;Z)`I}M{;3g5)DCiXHai%Y%@eha$#f| z1w(Icb95R5L1bhq2MPgH5&|$2Di#V0WMOn+UuJJ|ZDDj02NDHNLqtedDiR6>YjbIO zWfBPr2O0$d0RjR7DiR6@aA9O*X>Ml{2NDHVK}<Y-D9}UojF3P;6miWoU0~ zWMy(H3kn5fba`-P5&|$2DjNy~b7*03WfBrP5E23i5fTCjWfB4iWfB4i5ehE~13_eD z5(7bGWEu-lY+++%Xm4y}WpWw~P;6miWoU0~WMy(+F)9ZN0aOwKFcS(!3Jp+fVPj=z zZ){{`a$hnM3s7ufV`XS>Y-D9}Dhmn)WOR9OWfB4~6Dk`D1#@U&aAgt_IuH^92oVwj z2r&`@2r&`@2oVZK3Jp+fVPj=zZ){{`a$hqN3s7ufV`XS>Y-D9}Dhmn)WOR9OWfB4~ z6Dk`D1#@U&aAgt_IuH^92oVwj2r&`@2r&`@2oVZ13I#!AWM45713_eD8VyivVPj=z zZ){{`a$hnU4Nz=hV`XS>Y-D9}Uo$EP3IS9S0x%N_Z3-|%WpH$8cWHBFLvL<&GGtC+ zbZK^FLSbWTaB^>OMrmwxWpXcOX>4?5a$j?4dS!DG1w(Icb95>T3I$|zd2nSC0x$zA zB?<+0VQh6}5*$Jr2m=xX5&{SWA`k@t000F5000pH00031000Vs0tzEUWpH$8cWHBF zLvL<&GGtC+bZK^FLSbWTaB^>OMrmwxWpWZDL}hSvXm@FIWkYXnb~0p6VRUJBWkO+N zYjARJa7JltbY*fH13_eD8Zbm(;mZ*F!nWKLmpX?A5oVPk7>a&K@(X>4?5 zaxZ3SY; literal 0 KcmV+b0RR6000031 diff --git a/tests/st/testcase/origin_models/test_enter.pb b/tests/st/testcase/origin_models/test_enter.pb new file mode 100644 index 0000000000000000000000000000000000000000..a933678947ba674abb11b30dbe4c79b998e5cb32 GIT binary patch literal 337 zcmV-X0j~ZEGztq)Y+++%Xm4y}WpWY=P;6miWoU0~WMy(H3kn5fba`-P5&|#-Dhmn) zb7*03WfB59017q=4Nz=hV`XS>Y-D9}UojF3P;6miWoU0~WMy(H3kn5fba`-P5&|#- zDhmn)b7*03WfB59019gg1x0RjWpWY)MQ(IuavBRzY+++%Xm4y}WpXM93IS9S0x$zA z7YYhya$#*{Uv6P-WfBPz2XA$BaCLMsDiI0`X>(s=Z*FsRVQzF10w@3~8443{VRB(? zY-Ma;X>?_BVRUJ4ZgUa>7zzq+3I|1QbY*g1F%ktuZggdG8VyivVPj=zZ){{`a$hkj z2MPgH5&|#-Di;b0W^!R|WnXS#ZDkS(5(jT}bZ~WaF)9%X3u$v-V{dMAbYX6E5&|dy jDj5nBaA9&`Y;0w0Uukq@a$$67Z*FrE0vHM+0|>DMbP!$j literal 0 KcmV+b0RR6000031 diff --git a/tests/st/testcase/origin_models/test_enter_pb_gen.py b/tests/st/testcase/origin_models/test_enter_pb_gen.py new file mode 100644 index 0000000..291dfd8 --- /dev/null +++ b/tests/st/testcase/origin_models/test_enter_pb_gen.py @@ -0,0 +1,13 @@ +import tensorflow as tf +from tensorflow.python.ops import control_flow_ops + +def generate_enter_pb(): + with tf.compat.v1.Session(graph=tf.Graph()) as sess: + x = tf.compat.v1.placeholder(dtype="int32", shape=()) + y = tf.compat.v1.placeholder(dtype="int32", shape=()) + output1 = control_flow_ops.enter(x, frame_name = "output1") + output2 = control_flow_ops.enter(y, frame_name = "output2") + tf.io.write_graph(sess.graph, logdir="./", name="test_enter.pb", as_text=False) + +if __name__=='__main__': + generate_enter_pb() \ No newline at end of file diff --git a/tests/st/testcase/origin_models/test_fill.pb b/tests/st/testcase/origin_models/test_fill.pb new file mode 100644 index 0000000000000000000000000000000000000000..f351f147b08f9810214e13fda4e65216460930f5 GIT binary patch literal 289 zcmV++0p9)!JPHd?Y+++%Xm4y}WpWY=P;6miWoU0~WMy(H3kn5fba`-P5&|#-DiaC? zb7*03WfBTH2oeGa0ullU0t!9~2}WsbY%gSKZF3R@LvL<#bSeu91!Q!2aAgt#Fas(b z3I%pyY;|Q46haaR0}=!h0tf;k2mt^900IC2017k;3Px#cY%g|UY;|Q41w(Icb95>T z3I$|zd2nSC0x$zA5())&VQh6}5(z>F2m=xTIspX=J_-azX>4o~1V(9WY#IqhX>4pS zWNB@48VW{fY-}%fVQh6}DhCPyR1yL(11b;-3TbX+Wq4n7d2nSC0x$y#CJF;VWMmQp nL1bha3s7ufV`XS>Y-D9}8U#jZY-}nA3IS9S0x$z20|>DMg`z>w literal 0 KcmV+b0RR6000031 diff --git a/tests/st/testcase/origin_models/test_fill_pb_gen.py b/tests/st/testcase/origin_models/test_fill_pb_gen.py new file mode 100644 index 0000000..d7ed9f1 --- /dev/null +++ b/tests/st/testcase/origin_models/test_fill_pb_gen.py @@ -0,0 +1,12 @@ +import tensorflow as tf +import numpy as np + +def generate_fill_pb(): + with tf.compat.v1.Session(graph=tf.Graph()) as sess: + x = tf.compat.v1.placeholder(dtype="int32", shape=(2,2)) + y = tf.fill([1,2], value = 5) + z = tf.add(x,y) + tf.io.write_graph(sess.graph, logdir="./", name="test_fill.pb", as_text=False) + +if __name__ == "__main__": + generate_fill_pb() \ No newline at end of file diff --git a/tests/st/testcase/origin_models/test_identity.pb b/tests/st/testcase/origin_models/test_identity.pb new file mode 100644 index 0000000000000000000000000000000000000000..8d8184eb08373f21709bd64fde18baa6bd90b042 GIT binary patch literal 210 zcmV;@04@ItGztq)Y+++%Xm4y}WpWY=P;6miWoU0~WMy(H3kn5fba`-P5&|#-Dhmn) zb7*03WfB59017e+2zXy`Y;|)lc@hOfZ*FsRDhmn)WOR9OWfB4~11b^<1$JR zLI(%~5&${@0SYY&26$g^Y;|)I13_eD8VgWtVPj=zZ){{`avBJDUvO-7b1!)+2MPgH z5&|#-3Ni`@dS78=WMyO$2uWmRZggpMc^V5)Y+++%Xm4y}WpWw^UU*+{Y;|)g2MPgH M5&|#-A_EAq1fA$Ms{jB1 literal 0 KcmV+b0RR6000031 diff --git a/tests/st/testcase/origin_models/test_identity_pb_gen.py b/tests/st/testcase/origin_models/test_identity_pb_gen.py new file mode 100644 index 0000000..1ff3781 --- /dev/null +++ b/tests/st/testcase/origin_models/test_identity_pb_gen.py @@ -0,0 +1,13 @@ +import tensorflow as tf + +def generate_identity_pb(): + with tf.compat.v1.Session(graph=tf.Graph()) as sess: + x = tf.compat.v1.placeholder(dtype="int32", shape=()) + x_plus_1 = tf.add(x, 1, name='x_plus') + with tf.control_dependencies([x_plus_1]): + y = x + z = tf.identity(x,name='identity') + tf.io.write_graph(sess.graph, logdir="./", name="test_identity.pb", as_text=False) + +if __name__=='__main__': + generate_identity_pb() \ No newline at end of file diff --git a/tests/st/testcase/origin_models/test_merge_pb_gen.py b/tests/st/testcase/origin_models/test_merge_pb_gen.py new file mode 100644 index 0000000..709f81b --- /dev/null +++ b/tests/st/testcase/origin_models/test_merge_pb_gen.py @@ -0,0 +1,18 @@ +import tensorflow as tf +from tensorflow.python.framework import graph_util +import numpy as np + +def generate_merge_pb(): + with tf.compat.v1.Session(graph=tf.Graph()) as sess: + dist = tf.compat.v1.placeholder(tf.float32, [100]) + tf.compat.v1.summary.histogram(name="Merge", values=dist) + writer = tf.compat.v1.summary.FileWriter("./tf_summary_merge_pb") + op = tf.compat.v1.summary.merge_all() + for step in range(10): + mean_moving_normal = np.random.normal(loc=step, scale=1, size=[100]) + summ = sess.run(op, feed_dict = {dist : mean_moving_normal}) + writer.add_summary(summ, global_step=step) + tf.io.write_graph(sess.graph, logdir="./", name="merge.pb", as_text=False) + +if __name__=='__main__': + generate_merge_pb() diff --git a/tests/st/testcase/origin_models/test_no_op.pb b/tests/st/testcase/origin_models/test_no_op.pb new file mode 100644 index 0000000000000000000000000000000000000000..a56f4acf7f81223b276834eb1be7631520891229 GIT binary patch literal 179 zcmV;k08IZ1Gztq)Y+++%Xm4y}WpWY=P;6miWoU0~WMy(H3kn5fba`-P5&|#-Dhmn) zb7*03WfB59017q=4Nz=hV`XS>Y-D9}UojF3P;6miWoU0~WMy(H3kn5fba`-P5&|#- zDhmn)b7*03WfB59017V(13_eD5(7bGWEu-lY+++%Xm4y}WpWw~P;6miWoU0~WMy(+ hF)9ZN0aOwKFart=3I%j>VQFp>1Ws>Ha3TW;u>>OVFGm0X literal 0 KcmV+b0RR6000031 diff --git a/tests/st/testcase/origin_models/test_no_op_pb_gen.py b/tests/st/testcase/origin_models/test_no_op_pb_gen.py new file mode 100644 index 0000000..1e4ba29 --- /dev/null +++ b/tests/st/testcase/origin_models/test_no_op_pb_gen.py @@ -0,0 +1,14 @@ +import tensorflow as tf +import numpy as np + +def generate_no_op_pb(): + with tf.compat.v1.Session(graph=tf.Graph()) as sess: + x = tf.compat.v1.placeholder(dtype="int32", shape=()) + y = tf.compat.v1.placeholder(dtype="int32", shape=()) + add_op = tf.add(x, y) + y2 = tf.no_op(name="train") + z = tf.group([add_op, y2]) + tf.io.write_graph(sess.graph, logdir="./", name="test_no_op.pb", as_text=False) + +if __name__=='__main__': + generate_no_op_pb() \ No newline at end of file diff --git a/tests/st/testcase/origin_models/test_reshape.pb b/tests/st/testcase/origin_models/test_reshape.pb new file mode 100644 index 0000000000000000000000000000000000000000..1b772bae33b52d73e5e8fd2ecc662eb523a3f490 GIT binary patch literal 206 zcmV;<05SgxJPHd?Y+++%Xm4y}WpWY=P;6miWoU0~WMy(H3kn5fba`-P5&|#-DiaC? zb7*03WfBTH2oeGa0ullU0t!M34N_%uXkl<=FLP*NaAgt&LvL<#bSeu91!Q!2aAgt# zFas(b3I%pyY;|Q46haaR0}=!h0tf;k2m$~A00IC2018D42U2BoXkl<=5(iRcb7*03 zWf}`mY+++%Xm4y}WpWw~Qe|^!VQ^(Hb7*03Whw^>0aOwKFas(K3Ib!BCGWfBKdadl;7dSw~|L1bhq k2MPgH5&|#-DiR6|b8&TLWqM^_WNB@45&{YUA_EAq1a$Z^TL1t6 literal 0 KcmV+b0RR6000031 diff --git a/tests/st/testcase/origin_models/test_sequeeze_pb_gen.py b/tests/st/testcase/origin_models/test_sequeeze_pb_gen.py new file mode 100644 index 0000000..b9a4078 --- /dev/null +++ b/tests/st/testcase/origin_models/test_sequeeze_pb_gen.py @@ -0,0 +1,13 @@ +import tensorflow as tf +import numpy as np + +def generate_sequeeze_pb(): + with tf.compat.v1.Session(graph=tf.Graph()) as sess: + x = tf.compat.v1.placeholder(dtype="int32", shape=(2,2)) + y = tf.constant([[1,2],[2,3]]) + z = tf.add(x,y) + op = tf.squeeze(z,name = "squeeze") + tf.io.write_graph(sess.graph, logdir="./", name="test_sequeeze.pb", as_text=False) + +if __name__ == "__main__": + generate_sequeeze_pb() \ No newline at end of file diff --git a/tests/st/testcase/origin_models/test_shape_n.pb b/tests/st/testcase/origin_models/test_shape_n.pb new file mode 100644 index 0000000000000000000000000000000000000000..39ce087ec7a169f4c970091efece7170b3538fec GIT binary patch literal 272 zcmV+r0q_0_JPHd?Y+++%Xm4y}WpWY=P;6miWoU0~WMy(H3kn5fba`-P5&|#-DiaC? zb7*03WfBTH2oeGa0ullU0tz__4|8Z?aAjX^FKKRYb#z}a5(PtVZgX@h3kn5fba`-P z5&|#-DiR6>c42IFWfBQO2M7Za06GBy3ONc7b7*03WnXSDX>M?JbYC$N1w(Icb95>T z3I$|zd2nSC0x$zA5())&VQh6}5(z>F2m=xTIspO-RSE}lXkl<=Uv3fxQ)ppuWlkCo zb7*03WnXSDX>M?JbYCzU4|8Z?aAjX^FKKRYb#z}bDhCPyP7(qb0xAaz0aOwKFas(M W3J7m?bYFCNaAgt#Fash32(biiKSL}4 literal 0 KcmV+b0RR6000031 diff --git a/tests/st/testcase/origin_models/test_shape_n_pb_gen.py b/tests/st/testcase/origin_models/test_shape_n_pb_gen.py new file mode 100644 index 0000000..2f29597 --- /dev/null +++ b/tests/st/testcase/origin_models/test_shape_n_pb_gen.py @@ -0,0 +1,11 @@ +import tensorflow as tf +import numpy as np + +def generate_shape_n_pb(): + with tf.compat.v1.Session(graph=tf.Graph()) as sess: + x = tf.compat.v1.placeholder(dtype="int32", shape=(2,2)) + y = tf.shape_n([1,2], name= "shape_n") + tf.io.write_graph(sess.graph, logdir="./", name="test_shape_n.pb", as_text=False) + +if __name__ == "__main__": + generate_shape_n_pb() \ No newline at end of file diff --git a/tests/st/testcase/origin_models/test_switch.pb b/tests/st/testcase/origin_models/test_switch.pb new file mode 100644 index 0000000000000000000000000000000000000000..7379e783394b2dc2b3da760b645577a07ed7b571 GIT binary patch literal 339 zcmV-Z0j&NCGztq)Y+++%Xm4y}WpWY=P;6miWoU0~WMy(H3kn5fba`-P5&|#-Dhmn) zb7*03WfB59017q=4Nz=hV`XS>Y-D9}UojF3P;6miWoU0~WMy(H3kn5fba`-P5&|#- zDhmn)b7*03WfB59017n<3sZM#bYo~QaB^j25(PtVZgX@h3kn5fba`-P5&|#^DiR6> zc42IFWfBQO2M7uh09pY63Ns1@Q+H`}V`vfvQ+H`}V`v%+P;6miWoU0~WMy(13sZM# zbYo~QaB^j2DhCPyR1yL(0}3|^4O4e%bYo~=F)wg(Wn>ZsLvL<#bSeu91!Q!2aAgt# zFbXOX3I%pyY;|Q42|@=53K9TX0Raj*3J6noX>?;~UojE}Q+H`}V`v%;P;6miWoU0~ lWMy(+F&Yh1cWHEEXkRfeaB^j2DhCPyR1yL(10n+mu>`r=Sdah! literal 0 KcmV+b0RR6000031 diff --git a/tests/st/testcase/origin_models/test_switch_pb_gen.py b/tests/st/testcase/origin_models/test_switch_pb_gen.py new file mode 100644 index 0000000..5b2f87c --- /dev/null +++ b/tests/st/testcase/origin_models/test_switch_pb_gen.py @@ -0,0 +1,13 @@ +import tensorflow as tf +from tensorflow.python.ops import control_flow_ops + +def generate_switch_pb(): + with tf.compat.v1.Session(graph=tf.Graph()) as sess: + x = tf.compat.v1.placeholder(dtype="int32", shape=()) + y = tf.compat.v1.placeholder(dtype="int32", shape=()) + output1 = control_flow_ops.switch(x,False) + output2 = control_flow_ops.switch(y,True) + tf.io.write_graph(sess.graph, logdir="./", name="test_switch.pb", as_text=False) + +if __name__=='__main__': + generate_switch_pb() \ No newline at end of file diff --git a/tests/st/testcase/origin_models/test_variableV2_pb_gen.py b/tests/st/testcase/origin_models/test_variableV2_pb_gen.py new file mode 100644 index 0000000..fa1416c --- /dev/null +++ b/tests/st/testcase/origin_models/test_variableV2_pb_gen.py @@ -0,0 +1,13 @@ +import tensorflow as tf + +def generate_VariableV2_pb(): + with tf.compat.v1.Session(graph=tf.Graph()) as sess: + x = tf.compat.v1.placeholder(dtype="int32", shape=(2,3)) + op = tf.raw_ops.VariableV2(shape=[2,3], dtype="int32", name="VariableV2") + init = tf.compat.v1.global_variables_initializer() + op_add = tf.add(x,op) + sess.run(init) + tf.io.write_graph(sess.graph, logdir="./", name="test_VariableV2.pb", as_text=False) + +if __name__=='__main__': + generate_VariableV2_pb() \ No newline at end of file diff --git a/tests/st/testcase/test_tensorflow_parser.cc b/tests/st/testcase/test_tensorflow_parser.cc index 454ac91..3366c47 100644 --- a/tests/st/testcase/test_tensorflow_parser.cc +++ b/tests/st/testcase/test_tensorflow_parser.cc @@ -15,14 +15,38 @@ */ #include + +#define protected public +#define private public #include "parser/common/op_parser_factory.h" #include "parser/tensorflow/tensorflow_parser.h" #include "graph/operator_reg.h" #include "register/op_registry.h" +#include "external/register/register.h" #include "parser/common/register_tbe.h" -#include "external/parser/tensorflow_parser.h" #include "st/parser_st_utils.h" #include "tests/depends/ops_stub/ops_stub.h" +#include "parser/common/acl_graph_parser_util.h" +#include "metadef/third_party/graphengine/inc/external/ge/ge_api_types.h" +#include "omg/parser/parser_factory.h" +#include "common/pre_checker.h" +#include "common/util.h" +#include "external/parser/tensorflow_parser.h" +#include "parser/tensorflow/tensorflow_constant_parser.h" +#include "common/types.h" +#include "parser/common/op_def/variable_op.h" +#include "parser/tensorflow/tensorflow_ref_switch_parser.h" +#undef protected +#undef private + +using namespace std; +using namespace domi::tensorflow; +using namespace domi; +using namespace testing; +using namespace std; +using namespace google::protobuf; + +static const string GRAPH_DEFAULT_NAME = "default"; namespace ge { class STestTensorflowParser : public testing::Test { @@ -55,6 +79,378 @@ void STestTensorflowParser::RegisterCustomOp() { domi::OpRegistry::Instance()->registrationDatas.clear(); } +namespace { + NodeDef *initNodeDef() + { + NodeDef * nodeDef = new NodeDef(); + nodeDef->set_op("Const"); + ::google::protobuf::Map< ::std::string, ::tensorflow::AttrValue >* node_attr_map = nodeDef->mutable_attr(); + + //设置 T属性 + domi::tensorflow::AttrValue t_attr_value; + t_attr_value.set_type(domi::tensorflow::DT_INT32); + (*node_attr_map)[TENSORFLOW_ATTR_T] = t_attr_value; + + domi::tensorflow::AttrValue dtype_attr_value; + dtype_attr_value.set_type(domi::tensorflow::DT_INT32); + (*node_attr_map)[TENSORFLOW_ATTR_DTYPE] = dtype_attr_value; + + // out_put + domi::tensorflow::AttrValue outputs_attr_value; + ::tensorflow::AttrValue_ListValue* list = outputs_attr_value.mutable_list(); + list->add_s("MatMul"); + (*node_attr_map)[TENSORFLOW_ATTR_OUTPUT_OP] = outputs_attr_value; + + // 设置 tensor 属性 + domi::tensorflow::AttrValue value_attr_value; + ::tensorflow::TensorProto* tensor = value_attr_value.mutable_tensor(); + ::tensorflow::TensorShapeProto* tensor_shape = tensor->mutable_tensor_shape(); + tensor_shape->clear_dim(); + tensor_shape->add_dim()->set_size(4); + tensor_shape->add_dim()->set_size(6); + tensor->set_dtype(domi::tensorflow::DT_INT32); + + float *addr = new float[24]; + for (int32_t i = 0; i < 24; i++) + { + *(addr + i) = 1.0 + i; + } + tensor->set_tensor_content((void *)addr, 24 * sizeof(float)); + + (*node_attr_map)[TENSORFLOW_ATTR_VALUE] = value_attr_value; + delete[] addr; + return nodeDef; + } + + NodeDef *MallocNodeDef(const string &name, const string &type) { + NodeDef* node_def = new (std::nothrow) NodeDef(); + if (node_def != nullptr) { + node_def->set_name(name); + node_def->set_op(type); + } + return node_def; + } + + void GenOriginNodeDef(ge::TensorFlowModelParser *tensorflow_parser, vector &node_name_list) { + NodeDef* pre_node_a = MallocNodeDef("pre_node_a", "Const"); + EXPECT_NE(pre_node_a, nullptr); + { + ::google::protobuf::Map< ::std::string, ::tensorflow::AttrValue >* node_attr_map = pre_node_a->mutable_attr(); + tensorflow::AttrValue attr_dtype; + attr_dtype.set_type(tensorflow::DT_FLOAT); + (*node_attr_map)["dtype"] = attr_dtype; + tensorflow::AttrValue attr_value; + tensorflow::TensorProto* tensor = attr_value.mutable_tensor(); + tensor->add_bool_val(true); + tensor->set_dtype(tensorflow::DT_BOOL); + (*node_attr_map)["value"] = attr_value; + } + tensorflow_parser->nodedef_map_["pre_node_a"] = pre_node_a; + node_name_list.push_back("pre_node_a"); + + NodeDef* pre_node_ctrl_in = MallocNodeDef("pre_node_ctrl_in", "Const"); + EXPECT_NE(pre_node_ctrl_in, nullptr); + { + ::google::protobuf::Map< ::std::string, ::tensorflow::AttrValue >* node_attr_map = pre_node_ctrl_in->mutable_attr(); + tensorflow::AttrValue attr_dtype; + attr_dtype.set_type(tensorflow::DT_FLOAT); + (*node_attr_map)["dtype"] = attr_dtype; + tensorflow::AttrValue attr_value; + tensorflow::TensorProto* tensor = attr_value.mutable_tensor(); + tensor->add_bool_val(true); + tensor->set_dtype(tensorflow::DT_BOOL); + (*node_attr_map)["value"] = attr_value; + } + tensorflow_parser->nodedef_map_["pre_node_ctrl_in"] = pre_node_ctrl_in; + node_name_list.push_back("pre_node_ctrl_in"); + + NodeDef* post_node_b = MallocNodeDef("post_node_b", "Identity"); + EXPECT_NE(post_node_b, nullptr); + tensorflow_parser->nodedef_map_["post_node_b"] = post_node_b; + node_name_list.push_back("post_node_b"); + + NodeDef* post_node_c = MallocNodeDef("post_node_c", "Identity"); + EXPECT_NE(post_node_c, nullptr); + tensorflow_parser->nodedef_map_["post_node_c"] = post_node_c; + node_name_list.push_back("post_node_c"); + + NodeDef* post_node_d = MallocNodeDef("post_node_d", "Identity"); + EXPECT_NE(post_node_d, nullptr); + tensorflow_parser->nodedef_map_["post_node_d"] = post_node_d; + node_name_list.push_back("post_node_d"); + } + + void FreeNodeDefMap(ge::TensorFlowModelParser *tensorflow_parser, set &malloc_node_name_list) { + for (auto &item : tensorflow_parser->nodedef_map_) { + if (item.second != nullptr && malloc_node_name_list.count(item.first) > 0) { + delete (item.second); + item.second = nullptr; + } + } + } + void GenFusionScopesResult(shared_ptr &scope_graph, FusionScopesResult *fusion_rlt, + const string &fusion_op_name) { + if (fusion_rlt == nullptr) { + return; + } + fusion_rlt->InsertInputs("scope_node_1", {0}); // scope input 0 + fusion_rlt->InsertOutputs("scope_node_m", {0}); // scope output 0 + fusion_rlt->InsertOutputs("scope_node_n", {1}); // scope output 1 + + fusion_rlt->SetType(ge::kScopeToMultiNodes); + fusion_rlt->SetName(fusion_op_name); + fusion_rlt->SetDescription("Description for fusion node"); + + // Add inner nodes in sequence. + auto node1 = fusion_rlt->AddInnerNode("inner_node_1", "Unique"); // add inner node1 + CHECK_INNER_NODE_CONDITION(node1 != nullptr, fusion_rlt); + auto ret = node1 + ->InsertInput(ge::kInputFromFusionScope, 0) // Input from 0th of boundary (a) + .InsertOutput(ge::kOutputToFusionScope, 0) // Output to 0th of boundary (b) + .InsertOutput("inner_node_2", 0) // Output to input 0th of internal node 2 + .BuildInnerNode(); // Construct an internal Operator + CHECK_INNER_NODE_CONDITION(ret == ge::GRAPH_SUCCESS, fusion_rlt); + string str_val = "This is a string."; + node1->MutableOperator()->SetAttr("key1", 2); // Set integer attribute + node1->MutableOperator()->SetAttr("key2", str_val); // Set the string attribute + node1->MutableOperator()->SetAttr("key3", true); // Set boolean attribute + + auto node2 = fusion_rlt->AddInnerNode("inner_node_2", "Identity"); // add inner node2 + CHECK_INNER_NODE_CONDITION(node2 != nullptr, fusion_rlt); + ret = node2 + ->InsertInput("inner_node_1", 1) // The input comes from the 1st output of internal node 1 + .InsertOutput("inner_node_3", 0) // Output to input 0th of internal node 3 + .BuildInnerNode(); + CHECK_INNER_NODE_CONDITION(ret == ge::GRAPH_SUCCESS, fusion_rlt); + node2->SetInputFormat("x", "NHWC"); + node2->SetOutputFormat("y", "NHWC"); + + auto node3 = fusion_rlt->AddInnerNode("inner_node_3", "Identity"); // add inner node3 + CHECK_INNER_NODE_CONDITION(node3 != nullptr, fusion_rlt); + ret = node3 + ->InsertInput("inner_node_2", 0) // The input comes from the 0th output of internal node 2 + .InsertOutput(ge::kOutputToFusionScope, 1) // Output to 1st of boundary (c) + .BuildInnerNode(); + CHECK_INNER_NODE_CONDITION(ret == ge::GRAPH_SUCCESS, fusion_rlt); + + scope_graph->impl_->AddFusionScopesResult(fusion_rlt); + } + + void GenOriginContext(ge::TensorFlowModelParser *tensorflow_parser, const string &fusion_op_name) { + // op_node_context for fusion op + ge::OpNodeContext op_node_context; + op_node_context.input_map["pre_node_a"].push_back({0, 0}); + op_node_context.input_map["pre_node_ctrl_in"].push_back({-1, -1}); // ctrl edges + op_node_context.output_map["post_node_b"].push_back({0, 0}); + op_node_context.output_map["post_node_c"].push_back({1, 0}); + op_node_context.output_map["post_node_d"].push_back({-1, -1}); // ctrl edges + tensorflow_parser->op_node_context_map_[fusion_op_name] = op_node_context; + tensorflow_parser->SaveEdgesControlInfo(fusion_op_name, -1); + + // op_node_context for pre_node_a + ge::OpNodeContext op_node_context_a; + op_node_context_a.output_map[fusion_op_name].push_back({0, 0}); + tensorflow_parser->op_node_context_map_["pre_node_a"] = op_node_context_a; + + // op_node_context for pre_node_ctrl_in + ge::OpNodeContext op_node_context_ctrl_in; + op_node_context_ctrl_in.output_map[fusion_op_name].push_back({-1, -1}); // ctrl edges + tensorflow_parser->op_node_context_map_["pre_node_ctrl_in"] = op_node_context_ctrl_in; + + // op_node_context for post_node_b + ge::OpNodeContext op_node_context_b; + op_node_context_b.input_map[fusion_op_name].push_back({0, 0}); + tensorflow_parser->op_node_context_map_["post_node_b"] = op_node_context_b; + + // op_node_context for post_node_c + ge::OpNodeContext op_node_context_c; + op_node_context_c.input_map[fusion_op_name].push_back({1, 0}); + op_node_context_c.output_map["post_node_d"].push_back({0, 0}); + tensorflow_parser->op_node_context_map_["post_node_c"] = op_node_context_c; + + // op_node_context for post_node_d + ge::OpNodeContext op_node_context_d; + op_node_context_d.input_map["post_node_c"].push_back({0, 0}); + op_node_context_d.input_map[fusion_op_name].push_back({-1, -1}); // ctrl edges + tensorflow_parser->op_node_context_map_["post_node_d"] = op_node_context_d; + tensorflow_parser->SaveEdgesControlInfo("post_node_d", -1); + + string fusion_op_type = ge::kScopeToMultiNodes; + string description = "fusion op description"; + tensorflow_parser->fusion_op_type_map_[fusion_op_name].push_back(fusion_op_type); + tensorflow_parser->fusion_op_type_map_[fusion_op_name].push_back(description); + } + void register_tbe_op() + { + std::vector registrationDatas = OpRegistry::Instance()->registrationDatas; + for(OpRegistrationData reg_data : registrationDatas) + { + OpRegistrationTbe::Instance()->Finalize(reg_data); + OpRegistry::Instance()->Register(reg_data); + } + OpRegistry::Instance()->registrationDatas.clear(); + } +} + +namespace { +REG_OP(Data) + .INPUT(x, TensorType::ALL()) + .OUTPUT(y, TensorType::ALL()) + .ATTR(index, Int, 0) + .OP_END_FACTORY_REG(Data) + +REG_OP(Add) + .INPUT(x1, TensorType({DT_FLOAT, DT_INT32, DT_INT64, DT_FLOAT16, DT_INT16, + DT_INT8, DT_UINT8, DT_DOUBLE, DT_COMPLEX128, + DT_COMPLEX64, DT_STRING})) + .INPUT(x2, TensorType({DT_FLOAT, DT_INT32, DT_INT64, DT_FLOAT16, DT_INT16, + DT_INT8, DT_UINT8, DT_DOUBLE, DT_COMPLEX128, + DT_COMPLEX64, DT_STRING})) + .OUTPUT(y, TensorType({DT_FLOAT, DT_INT32, DT_INT64, DT_FLOAT16, DT_INT16, + DT_INT8, DT_UINT8, DT_DOUBLE, DT_COMPLEX128, + DT_COMPLEX64, DT_STRING})) + .OP_END_FACTORY_REG(Add) +} + +struct MemBuffer +{ + void* data; + uint32_t size; +}; + +static MemBuffer* MemBufferFromFile(const char *path) +{ + char path_temp[PATH_MAX + 1] = {0x00}; + if(strlen(path) > PATH_MAX || nullptr == realpath(path, path_temp)) { + return nullptr; + } + FILE *fp = fopen(path_temp, "r+"); + if (fp == nullptr) { + return nullptr; + } + + // get model file length + if (0 != fseek(fp, 0, SEEK_END)) { + fclose(fp); + return nullptr; + } + long file_length = ftell(fp); + if (fseek(fp, 0, SEEK_SET)) { + fclose(fp); + return nullptr; + } + if (file_length <= 0) { + fclose(fp); + return nullptr; + } + + // alloc model buffer + void *data = malloc((unsigned int)file_length); + if (!data) { + fclose(fp); + return nullptr; + } + + // read file into memory + uint32_t read_size = (uint32_t)fread(data, 1, (unsigned int)file_length, fp); + + // check if read success + if ((long)read_size != file_length) { + free(data); + data = nullptr; + fclose(fp); + return nullptr; + } + + // close model file + fclose(fp); + + // create an MemBuffer + MemBuffer* membuf = new MemBuffer(); + if (!membuf) { + free(data); + data = nullptr; + return nullptr; + } + membuf->data = malloc((unsigned int)read_size); + + // set size && data + membuf->size = (uint32_t)read_size; + memcpy((char*)membuf->data, (char*)data, read_size); + free(data); + return membuf; +} + + +/// placeholder0 placeholder1 +/// | /\ /\ | +/// | / \/ \ | +/// | / /\ \ | +/// | | / \ | | +/// | add0 mul0 | +/// | / /c | \ | +/// mul1 --- / | add1 +/// \ | | +/// \ ---- add2 | +/// | | +/// retval0 retval1 + +void CreateGraphDef(domi::tensorflow::GraphDef &graph_def) { + // 1. add node + auto placeholder0 = graph_def.add_node(); + auto placeholder1 = graph_def.add_node(); + auto add0 = graph_def.add_node(); + auto add1 = graph_def.add_node(); + auto mul0 = graph_def.add_node(); + auto mul1 = graph_def.add_node(); + auto add2 = graph_def.add_node(); + auto retval0 = graph_def.add_node(); + auto retval1 = graph_def.add_node(); + + // 2. set info + placeholder0->set_name("placeholder0"); + placeholder0->set_op("PlaceHolder"); + placeholder1->set_name("placeholder1"); + placeholder1->set_op("PlaceHolder"); + + add0->set_name("add0"); + add0->set_op("Add"); + add1->set_name("add1"); + add1->set_op("Add"); + add2->set_name("add2"); + add2->set_op("Add"); + + mul0->set_name("mul0"); + mul0->set_op("Mul"); + mul1->set_name("mul1"); + mul1->set_op("Mul"); + + retval0->set_name("retval0"); + retval0->set_op("_RetVal"); + retval1->set_name("retval1"); + retval1->set_op("_RetVal"); + + // 3. add edges + add0->add_input("placeholder0"); + add0->add_input("placeholder1"); + + mul0->add_input("placeholder0"); + mul0->add_input("placeholder1"); + + mul1->add_input("placeholder0"); + mul1->add_input("add0"); + mul1->add_input("^mul0"); + + add1->add_input("mul0"); + add1->add_input("placeholder1"); + + add2->add_input("mul1"); + add2->add_input("mul0"); + + retval0->add_input("add2:0"); + retval1->add_input("add1:0"); +} + TEST_F(STestTensorflowParser, tensorflow_parser_success) { RegisterCustomOp(); @@ -75,4 +471,662 @@ TEST_F(STestTensorflowParser, tensorflow_parser_success) { ASSERT_EQ(net_out_name.size(), 1); EXPECT_EQ(net_out_name.at(0), "add_test_1:0"); } + +TEST_F(STestTensorflowParser, tensorflow_model_Failed) { + ge::Graph graph; + std::string caseDir = __FILE__; + std::size_t idx = caseDir.find_last_of("/"); + caseDir = caseDir.substr(0, idx); + + std::string modelFile = caseDir + "/origin_models/model.pb"; + auto status = ge::aclgrphParseTensorFlow(modelFile.c_str(), graph); + EXPECT_EQ(status, ge::SUCCESS); + + modelFile = caseDir + "/origin_models/test_depth_wise_conv2d.pb"; + status = ge::aclgrphParseTensorFlow(modelFile.c_str(), graph); + EXPECT_EQ(status, ge::GRAPH_FAILED); +} + +TEST_F(STestTensorflowParser, tensorflow_model_not_exist) { + ge::Graph graph; + std::string caseDir = __FILE__; + std::size_t idx = caseDir.find_last_of("/"); + caseDir = caseDir.substr(0, idx); + + // model file is not exist + std::string modelFile = caseDir + "/origin_models/conv2d_explicit1_pad.pb"; + auto status = ge::aclgrphParseTensorFlow(modelFile.c_str(), graph); + EXPECT_EQ(status, ge::GRAPH_FAILED); +} + +TEST_F(STestTensorflowParser, parser_tensorflow_model) { + std::string caseDir = __FILE__; + std::size_t idx = caseDir.find_last_of("/"); + caseDir = caseDir.substr(0, idx); + std::string modelFile = caseDir + "/origin_models/tf_add.pb"; + const char *model_file = modelFile.c_str(); + std::string op_name = "ge_ascend_irgraph"; + ge::Graph graph(op_name); + + std::map parser_options = { + {ge::AscendString(ge::ir_option::INPUT_FORMAT), ge::AscendString("NHWC")}, + }; + auto ret_graph = ge::aclgrphParseTensorFlow(model_file, parser_options, graph); + EXPECT_EQ(ret_graph, ge::FAILED); + + // parser tensorflow model out_node_size is equal to index + string graph_name; + AclGrphParseUtil acl_graph_parse_util; + std::map out_nodes_with_node_and_index = { + {AscendString(ge::ir_option::OUT_NODES), AscendString("Placeholder:0;Placeholder_1:1")}}; + ParerSTestsUtils::ClearParserInnerCtx(); + auto ret = acl_graph_parse_util.ParseParamsBeforeGraph(out_nodes_with_node_and_index, graph_name); + ret_graph = ge::aclgrphParseTensorFlow(model_file, graph); + EXPECT_EQ(ret_graph, domi::FAILED); + + // parser tensorflow model success + modelFile = caseDir + "/origin_models/model.pb"; + model_file = modelFile.c_str(); + out_nodes_with_node_and_index = {{AscendString(ge::ir_option::OUT_NODES), AscendString("x:0;y:0")}}; + ParerSTestsUtils::ClearParserInnerCtx(); + ret = acl_graph_parse_util.ParseParamsBeforeGraph(out_nodes_with_node_and_index, graph_name); + ret_graph = ge::aclgrphParseTensorFlow(model_file, graph); + EXPECT_EQ(ret_graph, domi::SUCCESS); +} + +TEST_F(STestTensorflowParser, tensorflow_parser_to_json) +{ + TensorFlowModelParser modelParser; + std::string caseDir = __FILE__; + std::size_t idx = caseDir.find_last_of("/"); + caseDir = caseDir.substr(0, idx); + std::string modelFile = caseDir + "/origin_models/tf_add.pb"; + std::string jsonFile = caseDir + "/origin_models/test.json"; + const char *model_file = modelFile.c_str(); + const char *json_file = jsonFile.c_str(); + Status ret = modelParser.ToJson(model_file, json_file); + EXPECT_EQ(ret, SUCCESS); +} + +TEST_F(STestTensorflowParser, tensorflow_parserfrommemory_failed) +{ + TensorFlowModelParser modelParser; + std::string caseDir = __FILE__; + std::size_t idx = caseDir.find_last_of("/"); + caseDir = caseDir.substr(0, idx); + std::string modelFile = caseDir + "/origin_models/tf_add.pb"; + const char *data = modelFile.c_str(); + uint32_t size = 1; + ge::Graph graph; + std::map parser_params; + Status ret = ge::aclgrphParseTensorFlow(modelFile.c_str(), parser_params, graph); + ASSERT_EQ(ret, SUCCESS); + + modelFile = caseDir + "/origin_models/tf_add.pb"; + parser_params = {{AscendString(ge::ir_option::OUT_NODES), AscendString("Placeholder:0;Placeholder_1:0")}}; + ret = ge::aclgrphParseTensorFlow(modelFile.c_str(), parser_params, graph); + ge::ComputeGraphPtr compute_graph = ge::GraphUtils::GetComputeGraph(graph); + ret = modelParser.ParseFromMemory(data, size, compute_graph); + EXPECT_EQ(ret, INTERNAL_ERROR); +} + +TEST_F(STestTensorflowParser, modelparser_parsefrommemory_success) +{ + std::string caseDir = __FILE__; + std::size_t idx = caseDir.find_last_of("/"); + caseDir = caseDir.substr(0, idx); + std::string modelFile = caseDir + "/origin_models/tf_add.pb"; + const char* tmp_tf_pb_model = modelFile.c_str(); + ge::Graph graph; + std::map parser_params; + Status ret = ge::aclgrphParseTensorFlow(modelFile.c_str(), parser_params, graph); + ASSERT_EQ(ret, SUCCESS); + + ge::ComputeGraphPtr compute_graph = ge::GraphUtils::GetComputeGraph(graph); + TensorFlowModelParser modelParser; + MemBuffer* memBuffer = MemBufferFromFile(tmp_tf_pb_model); + PreChecker::Instance().HasError() == false; + ret = modelParser.ParseFromMemory((char*)memBuffer->data, memBuffer->size, compute_graph); + free(memBuffer->data); + delete memBuffer; +} + +TEST_F(STestTensorflowParser, weightsparser_parsefrommemory_success) +{ + std::string caseDir = __FILE__; + std::size_t idx = caseDir.find_last_of("/"); + caseDir = caseDir.substr(0, idx); + std::string modelFile = caseDir + "/origin_models/tf_add.pb"; + const char* tmp_tf_pb_model = modelFile.c_str(); + ge::Graph graph; + std::map parser_params; + Status ret = ge::aclgrphParseTensorFlow(modelFile.c_str(), parser_params, graph); + ASSERT_EQ(ret, SUCCESS); + + ge::ComputeGraphPtr compute_graph = ge::GraphUtils::GetComputeGraph(graph); + auto weights_parser = domi::WeightsParserFactory::Instance()->CreateWeightsParser(domi::TENSORFLOW); + MemBuffer* memBuffer = MemBufferFromFile(tmp_tf_pb_model); + ret = weights_parser->ParseFromMemory((char*)memBuffer->data, memBuffer->size, compute_graph); + free(memBuffer->data); + delete memBuffer; + EXPECT_EQ(SUCCESS, ret); +} + +std::string getGraphCallbackV2(string subgraph_name) +{ + std::string caseDir = __FILE__; + std::size_t idx = caseDir.find_last_of("/"); + caseDir = caseDir.substr(0, idx); + subgraph_name = caseDir + "/origin_models/tf_add.pb"; + return subgraph_name; +} + +TEST_F(STestTensorflowParser, parser_ParseProtoWithSubgraphV2) +{ + std::string caseDir = __FILE__; + std::size_t idx = caseDir.find_last_of("/"); + caseDir = caseDir.substr(0, idx); + const std::string root_proto = caseDir + "/origin_models/tf_add.pb"; + ge::Graph graph; + std::map parser_params; + Status ret = ge::aclgrphParseTensorFlow(root_proto.c_str(), parser_params, graph); + ASSERT_EQ(ret, SUCCESS); + + ge::ComputeGraphPtr root_graph = ge::GraphUtils::GetComputeGraph(graph); + domi::GetGraphCallbackV2 callback(&getGraphCallbackV2); + TensorFlowModelParser parser; + ret = parser.ParseProtoWithSubgraph(root_proto, callback, root_graph); +} + +TEST_F(STestTensorflowParser, parser_ConvertToGeDataType) +{ + // convert to ge type success + const uint32_t type1 = domi::tensorflow::DataType::DT_FLOAT; + TensorFlowModelParser parser; + ge::DataType dataType = parser.ConvertToGeDataType(type1); + ASSERT_EQ(dataType, ge::DataType::DT_FLOAT); + + const uint32_t type2 = 80; // invalid type + dataType = parser.ConvertToGeDataType(type2); + ASSERT_EQ(dataType, ge::DataType::DT_UNDEFINED); +} + +TEST_F(STestTensorflowParser, tensorflow_ParserProto_failed) +{ + std::string caseDir = __FILE__; + std::size_t idx = caseDir.find_last_of("/"); + caseDir = caseDir.substr(0, idx); + const std::string root_proto = caseDir + "/origin_models/avgpool3dgrad.pb.txt"; + domi::tensorflow::GraphDef graphDef; + ge::Graph graph; + std::map parser_params; + Status ret = ge::aclgrphParseTensorFlow(root_proto.c_str(), parser_params, graph); + ASSERT_EQ(ret, SUCCESS); + + ge::ComputeGraphPtr root_graph = ge::GraphUtils::GetComputeGraph(graph); + TensorFlowModelParser tensorflow_parser; + ret = tensorflow_parser.ParseProto(reinterpret_cast(&graphDef), root_graph); + EXPECT_EQ(PARAM_INVALID, ret); + + // proto解析失败 + bool protoRet = parser::ReadProtoFromText(root_proto.c_str(), &graphDef); + ASSERT_EQ(protoRet, false); + ret = tensorflow_parser.ParseProto(reinterpret_cast(&graphDef), root_graph); + ASSERT_EQ(ret, PARAM_INVALID); +} + +TEST_F(STestTensorflowParser, tensorflow_parserAllGraph_failed) +{ + std::string caseDir = __FILE__; + std::size_t idx = caseDir.find_last_of("/"); + caseDir = caseDir.substr(0, idx); + const std::string root_proto = caseDir + "/origin_models/conv2d.pb"; + domi::tensorflow::GraphDef graphDef; + CreateGraphDef(graphDef); + + auto no_op = graphDef.add_node(); + no_op->set_name("no_op"); + no_op->set_op("NoOp"); + no_op->add_input("placeholder0"); + no_op->add_input("placeholder1"); + + ge::Graph graph; + std::map parser_params; + Status ret = ge::aclgrphParseTensorFlow(root_proto.c_str(), parser_params, graph); + ASSERT_EQ(ret, SUCCESS); + + ge::ComputeGraphPtr root_graph = ge::GraphUtils::GetComputeGraph(graph); + TensorFlowModelParser tensorflow_parser; + ret = tensorflow_parser.ParseAllGraph(reinterpret_cast(&graphDef), root_graph); + EXPECT_EQ(INTERNAL_ERROR, ret); +} + +TEST_F(STestTensorflowParser, test_parse_acl_output_nodes) +{ + AclGrphParseUtil acl_graph_parse_util; + string graph_name; + // case 1: Normal with 'node and index' + ParerSTestsUtils::ClearParserInnerCtx(); + GetParserContext().type = domi::ONNX; + std::map out_nodes_with_node_and_index = { + {AscendString(ge::ir_option::OUT_NODES), AscendString("Out1:0;Out2:1")}}; + ParerSTestsUtils::ClearParserInnerCtx(); + auto ret = acl_graph_parse_util.ParseParamsBeforeGraph(out_nodes_with_node_and_index, graph_name); + ASSERT_EQ(ret, SUCCESS); + EXPECT_EQ(ge::GetParserContext().user_out_nodes.size(), 2); + EXPECT_EQ(ge::GetParserContext().out_nodes_map.size(), 2); + EXPECT_EQ(ge::GetParserContext().user_out_tensors.size(), 0); + + // case 2: Normal with 'tensor name' + ParerSTestsUtils::ClearParserInnerCtx(); + GetParserContext().type = domi::ONNX; + std::map out_nodes_with_tensor_name = { + {AscendString(ge::ir_option::OUT_NODES), AscendString("Out_tensor_1;Out_tensor_2")}}; + ret = acl_graph_parse_util.ParseParamsBeforeGraph(out_nodes_with_tensor_name, graph_name); + ASSERT_EQ(ret, SUCCESS); + EXPECT_EQ(ge::GetParserContext().user_out_nodes.size(), 0); + EXPECT_EQ(ge::GetParserContext().out_nodes_map.size(), 0); + EXPECT_EQ(ge::GetParserContext().user_out_tensors.size(), 2); + + // case 3: Failed with 'node and index' before 'tensor name' + ParerSTestsUtils::ClearParserInnerCtx(); + GetParserContext().type = domi::ONNX; + std::map out_nodes_mode_mixex_pre = { + {AscendString(ge::ir_option::OUT_NODES), AscendString("Out1:0;Out2:1;Out_tensor_1;Out_tensor_2")}}; + ret = acl_graph_parse_util.ParseParamsBeforeGraph(out_nodes_mode_mixex_pre, graph_name); + ASSERT_EQ(ret, PARAM_INVALID); + EXPECT_EQ(ge::GetParserContext().user_out_nodes.size(), 2); + EXPECT_EQ(ge::GetParserContext().out_nodes_map.size(), 2); + EXPECT_EQ(ge::GetParserContext().user_out_tensors.size(), 0); + + // case 4: Failed with 'node and index' inserted in 'tensor name' + ParerSTestsUtils::ClearParserInnerCtx(); + GetParserContext().type = domi::ONNX; + std::map out_nodes_mode_mixex_mid = { + {AscendString(ge::ir_option::OUT_NODES), AscendString("Out_tensor_1;Out1:0;Out2:1;Out_tensor_2")}}; + ret = acl_graph_parse_util.ParseParamsBeforeGraph(out_nodes_mode_mixex_mid, graph_name); + ASSERT_EQ(ret, PARAM_INVALID); + EXPECT_EQ(ge::GetParserContext().user_out_nodes.size(), 0); + EXPECT_EQ(ge::GetParserContext().out_nodes_map.size(), 0); + EXPECT_EQ(ge::GetParserContext().user_out_tensors.size(), 1); + + // case 5: Failed with 'node and index' after 'tensor name' + ParerSTestsUtils::ClearParserInnerCtx(); + GetParserContext().type = domi::ONNX; + std::map out_nodes_mode_mixex_post = { + {AscendString(ge::ir_option::OUT_NODES), AscendString("Out_tensor_1;Out_tensor_2;Out1:0;Out2:1")}}; + ret = acl_graph_parse_util.ParseParamsBeforeGraph(out_nodes_mode_mixex_post, graph_name); + ASSERT_EQ(ret, PARAM_INVALID); + EXPECT_EQ(ge::GetParserContext().user_out_nodes.size(), 0); + EXPECT_EQ(ge::GetParserContext().out_nodes_map.size(), 0); + EXPECT_EQ(ge::GetParserContext().user_out_tensors.size(), 2); +} + +TEST_F(STestTensorflowParser, parse_AutoMappingByOp) { + static const string KEY_STRING = "key_string"; + static const string KEY_INT = "key_int"; + static const string KEY_FLOAT = "key_float"; + static const string KEY_BOOL = "key_bool"; + static const string KEY_TYPE = "key_type"; + static const string VALUE_STRING = "string"; + static const int64_t VALUE_INT = 1; + static const float VALUE_FLOAT = 1.0; + static const bool VALUE_BOOL = true; + static const domi::tensorflow::DataType VALUE_TYPE = domi::tensorflow::DataType::DT_FLOAT; + + std::cout << "test data_type value_type: " << (int64_t)VALUE_TYPE << std::endl; + static const string VALUE_NAME = "test_name"; + ge::OpDescPtr op_desc = std::make_shared(); + NodeDef node_def; + domi::tensorflow::AttrValue value; + ge::Operator op = ge::OpDescUtils::CreateOperatorFromOpDesc(op_desc); + + node_def.set_name(VALUE_NAME); + value.set_s(VALUE_STRING); + TensorFlowUtil::AddNodeAttr(KEY_STRING, value, &node_def); + value.set_i(VALUE_INT); + TensorFlowUtil::AddNodeAttr(KEY_INT, value, &node_def); + value.set_f(VALUE_FLOAT); + TensorFlowUtil::AddNodeAttr(KEY_FLOAT, value, &node_def); + value.set_b(VALUE_BOOL); + TensorFlowUtil::AddNodeAttr(KEY_BOOL, value, &node_def); + value.set_type(VALUE_TYPE); + TensorFlowUtil::AddNodeAttr(KEY_TYPE, value, &node_def); + + domi::Status status = domi::AutoMappingFn(reinterpret_cast(&node_def), op); + EXPECT_EQ(domi::SUCCESS, status); + EXPECT_EQ(VALUE_NAME, op_desc->GetName()); + + string value_string = ""; + ge::AttrUtils::GetStr(op_desc, KEY_STRING, value_string); + EXPECT_EQ(VALUE_STRING, value_string); + + int64_t value_int = 0; + ge::AttrUtils::GetInt(op_desc, KEY_INT, value_int); + EXPECT_EQ(VALUE_INT, value_int); + + float value_float = 0.0; + ge::AttrUtils::GetFloat(op_desc, KEY_FLOAT, value_float); + EXPECT_EQ(VALUE_FLOAT, value_float); + + bool value_bool = false; + ge::AttrUtils::GetBool(op_desc, KEY_BOOL, value_bool); + EXPECT_EQ(VALUE_BOOL, value_bool); + + ge::DataType data_type = ge::DT_UNDEFINED; + ge::AttrUtils::GetDataType(op_desc, KEY_TYPE, data_type); + EXPECT_EQ(ge::DT_FLOAT, data_type); + + // test AutoMappingByOpFn + ge::OpDescPtr op_desc_dest = std::make_shared(); + ge::Operator op_dest = ge::OpDescUtils::CreateOperatorFromOpDesc(op_desc_dest); + + status = domi::AutoMappingByOpFn(op, op_dest); + EXPECT_EQ(domi::SUCCESS, status); + EXPECT_EQ(VALUE_NAME, op_dest.GetName()); + + value_string = ""; + ge::AttrUtils::GetStr(op_desc_dest, KEY_STRING, value_string); + EXPECT_EQ(VALUE_STRING, value_string); + + value_int = 0; + ge::AttrUtils::GetInt(op_desc_dest, KEY_INT, value_int); + EXPECT_EQ(VALUE_INT, value_int); + + value_float = 0.0; + ge::AttrUtils::GetFloat(op_desc_dest, KEY_FLOAT, value_float); + EXPECT_EQ(VALUE_FLOAT, value_float); + + value_bool = false; + ge::AttrUtils::GetBool(op_desc_dest, KEY_BOOL, value_bool); + EXPECT_EQ(VALUE_BOOL, value_bool); + + data_type = ge::DT_UNDEFINED; + ge::AttrUtils::GetDataType(op_desc_dest, KEY_TYPE, data_type); + EXPECT_EQ(ge::DT_FLOAT, data_type); +} + +TEST_F(STestTensorflowParser, parse_ParseNodeDef) +{ + NodeDef * node_def = new NodeDef(); + node_def->set_name("test_name"); + node_def->set_op("PlaceholderWithDefault"); + + bool isDatasetInit = true; + TensorFlowModelParser model_parser; + Status ret = model_parser.AdaptOpType(node_def, isDatasetInit); + EXPECT_EQ(domi::SUCCESS, ret); + + node_def->set_op("Add"); + ret = model_parser.AdaptOpType(node_def, isDatasetInit); + EXPECT_EQ(domi::SUCCESS, ret); + delete node_def; +} + +TEST_F(STestTensorflowParser, parse_AddFmkNode) +{ + TensorFlowModelParser modelParser; + std::string caseDir = __FILE__; + std::size_t idx = caseDir.find_last_of("/"); + caseDir = caseDir.substr(0, idx); + std::string modelFile = caseDir + "/origin_models/tf_add.pb"; + ge::Graph graph; + string graph_name; + AclGrphParseUtil acl_graph_parse_util; + std::map parser_options = {{AscendString(ge::ir_option::OUT_NODES), AscendString("Placeholder:0;Placeholder_1:0")}}; + ParerSTestsUtils::ClearParserInnerCtx(); + Status ret = acl_graph_parse_util.ParseParamsBeforeGraph(parser_options, graph_name); + ret = aclgrphParseTensorFlow(modelFile.c_str(), parser_options, graph); + ASSERT_EQ(ret, SUCCESS); + + ge::ComputeGraphPtr compute_graph = std::make_shared(GRAPH_DEFAULT_NAME); + tensorflow::GraphDef *graphDef = new (std::nothrow) tensorflow::GraphDef(); + ScopePassManager pass_manager; + std::shared_ptr scope_graph = pass_manager.BuildScopeGraph(graphDef); + + std::string fusion_op_name = "fusion_op_name"; + FusionScopesResult *fusion_rlt = new (std::nothrow) FusionScopesResult(); + EXPECT_NE(fusion_rlt, nullptr); + fusion_rlt->Init(); + GenFusionScopesResult(scope_graph, fusion_rlt, fusion_op_name); + GenOriginContext(&modelParser, fusion_op_name); + + // origin inner node def + NodeDef* node_def = MallocNodeDef("scope_node_1", "Add"); + EXPECT_NE(node_def, nullptr); + modelParser.fusion_op_nodedef_map_[fusion_op_name].push_back(node_def); + + bool train_flag_backup = ge::GetParserContext().train_flag; + ge::GetParserContext().train_flag = true; + + REGISTER_CUSTOM_OP("Identity") + .FrameworkType(domi::TENSORFLOW) + .OriginOpType("Identity") + .ParseParamsFn(ParseParams) + .ImplyType(ImplyType::TVM); + REGISTER_CUSTOM_OP("Constant") + .FrameworkType(domi::TENSORFLOW) + .OriginOpType("Const") + .ParseParamsFn(ParseParams) + .ImplyType(ImplyType::TVM); + + register_tbe_op(); + + std::vector node_name_list; + GenOriginNodeDef(&modelParser, node_name_list); + std::set malloc_node_name_list(node_name_list.begin(), node_name_list.end()); + node_name_list.push_back(fusion_op_name); + + ret = modelParser.AddFmkNode(compute_graph, scope_graph, node_name_list, false); + EXPECT_EQ(ret, PARAM_INVALID); + EXPECT_EQ(modelParser.scope_inner_node_map_.size(), 0); + EXPECT_EQ(modelParser.nodedef_map_.size(), 5); + + ret = modelParser.AddEdges(compute_graph); + EXPECT_EQ(ret, SUCCESS); + + // release resource + delete graphDef; + delete node_def; + modelParser.DeleteFuisonNodeDef(); + FreeNodeDefMap(&modelParser, malloc_node_name_list); + ge::GetParserContext().train_flag = train_flag_backup; +} + +TEST_F(STestTensorflowParser, parse_AddScopeInnerNode) +{ + TensorFlowModelParser modelParser; + std::string caseDir = __FILE__; + std::size_t idx = caseDir.find_last_of("/"); + caseDir = caseDir.substr(0, idx); + std::string modelFile = caseDir + "/origin_models/tf_add.pb"; + std::string op_name = "ge_ascend_irgraph"; + ge::Graph graph(op_name); + ge::ComputeGraphPtr compute_graph = ge::GraphUtils::GetComputeGraph(graph); + std::map parser_params = { + {AscendString(ge::ir_option::OUT_NODES), AscendString("Placeholder:0;Placeholder_1:0")}}; + Status ret = ge::aclgrphParseTensorFlow(modelFile.c_str(), parser_params, graph); + EXPECT_EQ(ret, SUCCESS); + + std::mutex graph_mutex; + tensorflow::NodeDef *node_def = new NodeDef(); + node_def->set_name("FastrcnnPredictions"); + node_def->set_op("FastrcnnPredictions"); + // can't find in scope_inner_node_map + ret = modelParser.AddScopeInnerNode(&modelParser, compute_graph, &graph_mutex, node_def); + EXPECT_EQ(ret, PARAM_INVALID); + delete node_def; +} + +TEST_F(STestTensorflowParser, dyncmic_rnn_scope_pass_plugin_test) { + ge::Graph graph; + + std::cout << __FILE__ << std::endl; + std::string caseDir = __FILE__; + std::size_t idx = caseDir.find_last_of("/"); + caseDir = caseDir.substr(0, idx); + std::string modelFile = caseDir + "/origin_models/tensor_array.pb"; + std::map params; + string key ="enable_scope_fusion_passes"; + string value ="ScopeDynamicRNNPass"; + params.insert(std::make_pair(ge::AscendString(key.c_str()), ge::AscendString(value.c_str()))); + auto status = aclgrphParseTensorFlow(modelFile.c_str(), params, graph); + EXPECT_EQ(status, SUCCESS); +} + +TEST_F(STestTensorflowParser, avgpool3dgrad_plugin_test_format_NDHWC) { + ge::Graph graph; + std::cout << __FILE__ << std::endl; + std::string caseDir = __FILE__; + std::size_t idx = caseDir.find_last_of("/"); + caseDir = caseDir.substr(0, idx); + std::string modelFile = caseDir + "/origin_models/avgpool3dgrad_case_1.pb"; + auto status = aclgrphParseTensorFlow(modelFile.c_str(), graph); + EXPECT_EQ(status, SUCCESS); +} + +TEST_F(STestTensorflowParser, tensorflow_merge_test) { + ge::Graph graph; + std::cout << __FILE__ << std::endl; + std::string caseDir = __FILE__; + std::size_t idx = caseDir.find_last_of("/"); + caseDir = caseDir.substr(0, idx); + std::string modelFile = caseDir + "/origin_models/merge.pb"; + auto status = aclgrphParseTensorFlow(modelFile.c_str(), graph); +} + +TEST_F(STestTensorflowParser, tensorflow_no_op_test) { + ge::Graph graph; + std::cout << __FILE__ << std::endl; + std::string caseDir = __FILE__; + std::size_t idx = caseDir.find_last_of("/"); + caseDir = caseDir.substr(0, idx); + std::string modelFile = caseDir + "/origin_models/test_no_op.pb"; + auto status = aclgrphParseTensorFlow(modelFile.c_str(), graph); + EXPECT_EQ(status, SUCCESS); +} + +TEST_F(STestTensorflowParser, tensorflow_identity_test) { + ge::Graph graph; + std::cout << __FILE__ << std::endl; + std::string caseDir = __FILE__; + std::size_t idx = caseDir.find_last_of("/"); + caseDir = caseDir.substr(0, idx); + std::string modelFile = caseDir + "/origin_models/test_identity.pb"; + auto status = aclgrphParseTensorFlow(modelFile.c_str(), graph); + EXPECT_EQ(status, SUCCESS); +} + +TEST_F(STestTensorflowParser, tensorflow_constant_test) { + ge::Graph graph; + std::cout << __FILE__ << std::endl; + std::string caseDir = __FILE__; + std::size_t idx = caseDir.find_last_of("/"); + caseDir = caseDir.substr(0, idx); + std::string modelFile = caseDir + "/origin_models/test_constant.pb"; + auto status = aclgrphParseTensorFlow(modelFile.c_str(), graph); + EXPECT_EQ(status, SUCCESS); + + TensorFlowConstantParser constantParser; + ge::OpDescPtr op_dest = make_shared("constant", ge::parser::CONSTANT); + NodeDef* node_def = initNodeDef(); + node_def->set_name("Constant"); + auto params = constantParser.ParseParams(node_def, op_dest); + EXPECT_EQ(params, SUCCESS); + + auto value = constantParser.ParseValue(node_def, op_dest); + EXPECT_EQ(value, SUCCESS); + + ConstantOperator op; + auto type = constantParser.ParseDType(node_def, &op); + EXPECT_EQ(type, SUCCESS); +} + +TEST_F(STestTensorflowParser, tensorflow_reshpae_test) { + ge::Graph graph; + std::cout << __FILE__ << std::endl; + std::string caseDir = __FILE__; + std::size_t idx = caseDir.find_last_of("/"); + caseDir = caseDir.substr(0, idx); + std::string modelFile = caseDir + "/origin_models/test_reshape.pb"; + auto status = aclgrphParseTensorFlow(modelFile.c_str(), graph); + EXPECT_EQ(status, SUCCESS); +} + +TEST_F(STestTensorflowParser, tensorflow_squeeze_test) { + ge::Graph graph; + std::cout << __FILE__ << std::endl; + std::string caseDir = __FILE__; + std::size_t idx = caseDir.find_last_of("/"); + caseDir = caseDir.substr(0, idx); + std::string modelFile = caseDir + "/origin_models/test_sequeeze.pb"; + auto status = aclgrphParseTensorFlow(modelFile.c_str(), graph); + EXPECT_EQ(status, SUCCESS); +} + +TEST_F(STestTensorflowParser, tensorflow_fill_test) { + ge::Graph graph; + std::cout << __FILE__ << std::endl; + std::string caseDir = __FILE__; + std::size_t idx = caseDir.find_last_of("/"); + caseDir = caseDir.substr(0, idx); + std::string modelFile = caseDir + "/origin_models/test_fill.pb"; + auto status = aclgrphParseTensorFlow(modelFile.c_str(), graph); + EXPECT_EQ(status, SUCCESS); +} + +TEST_F(STestTensorflowParser, tensorflow_shape_n_test) { + ge::Graph graph; + std::cout << __FILE__ << std::endl; + std::string caseDir = __FILE__; + std::size_t idx = caseDir.find_last_of("/"); + caseDir = caseDir.substr(0, idx); + std::string modelFile = caseDir + "/origin_models/test_shape_n.pb"; + auto status = aclgrphParseTensorFlow(modelFile.c_str(), graph); + EXPECT_EQ(status, SUCCESS); +} + +TEST_F(STestTensorflowParser, tensorflow_switch_test) { + ge::Graph graph; + std::cout << __FILE__ << std::endl; + std::string caseDir = __FILE__; + std::size_t idx = caseDir.find_last_of("/"); + caseDir = caseDir.substr(0, idx); + std::string modelFile = caseDir + "/origin_models/test_switch.pb"; + auto status = aclgrphParseTensorFlow(modelFile.c_str(), graph); + EXPECT_EQ(status, SUCCESS); + + TensorFlowRefSwitchParser refSwitchParser; + ge::OpDescPtr op_dest = make_shared("constant", ge::parser::CONSTANT); + NodeDef* node_def = initNodeDef(); + node_def->set_name("RefSwitch"); + auto params = refSwitchParser.ParseParams(node_def, op_dest); + EXPECT_EQ(params, SUCCESS); + + RefSwitchOperator op; + auto parseRet = refSwitchParser.ParseT(node_def, &op); + EXPECT_EQ(parseRet, SUCCESS); +} + +TEST_F(STestTensorflowParser, tensorflow_enter_test) { + ge::Graph graph; + std::cout << __FILE__ << std::endl; + std::string caseDir = __FILE__; + std::size_t idx = caseDir.find_last_of("/"); + caseDir = caseDir.substr(0, idx); + std::string modelFile = caseDir + "/origin_models/test_enter.pb"; + auto status = aclgrphParseTensorFlow(modelFile.c_str(), graph); + EXPECT_EQ(status, SUCCESS); +} + +TEST_F(STestTensorflowParser, tensorflow_VariableV2_test) { + ge::Graph graph; + std::string caseDir = __FILE__; + std::size_t idx = caseDir.find_last_of("/"); + caseDir = caseDir.substr(0, idx); + std::string modelFile = caseDir + "/origin_models/test_VariableV2.pb"; + auto status = aclgrphParseTensorFlow(modelFile.c_str(), graph); + EXPECT_EQ(status, SUCCESS); +} + } // namespace ge