MCPcopy Create free account
hub / github.com/ROCm/AMDMIGraphX / parse

Method parse

src/tf/parse_depthwiseconv.cpp:40–120  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

38 std::vector<op_desc> operators() const { return {{"DepthwiseConv2dNative"}}; }
39
40 instruction_ref parse(const op_desc& /*opd*/,
41 const tf_parser& parser,
42 tf_parser::node_info info,
43 std::vector<instruction_ref> args) const
44 {
45 op::convolution op;
46 size_t num_channels = args[0]->get_shape().lens()[1];
47 op.group = num_channels;
48
49 if(contains(info.attributes, "strides"))
50 {
51 std::vector<size_t> stride;
52 copy(info.attributes.at("strides").list().i(), std::back_inserter(stride));
53 parser.reorder_data(stride);
54 if(stride.size() != 4)
55 {
56 MIGRAPHX_THROW("strides should have 4 values");
57 }
58 op.stride[0] = stride[2];
59 op.stride[1] = stride[3];
60 }
61
62 auto weights = parser.to_kcxy(args[1]);
63 if(contains(info.attributes, "dilations"))
64 {
65 std::vector<size_t> dilation;
66 copy(info.attributes.at("dilations").list().i(), std::back_inserter(dilation));
67 parser.reorder_data(dilation);
68 if(dilation.size() != 4)
69 {
70 MIGRAPHX_THROW("dilation should have 4 values");
71 }
72 op.dilation[0] = dilation[2];
73 op.dilation[1] = dilation[3];
74 }
75
76 auto l0 = args[0];
77 if(contains(info.attributes, "padding"))
78 {
79 const std::string& pad_mode = info.attributes.at("padding").s();
80
81 if(pad_mode.find("SAME") != std::string::npos)
82 {
83 std::vector<size_t> weight_dims = weights->get_shape().lens();
84 size_t weight_h = weight_dims[2];
85 size_t weight_w = weight_dims[3];
86
87 auto input_dims = l0->get_shape().lens();
88 std::vector<int64_t> pads(input_dims.size());
89 calculate_padding(0, pads, input_dims[2], op.stride[0], op.dilation[0], weight_h);
90 calculate_padding(1, pads, input_dims[3], op.stride[1], op.dilation[1], weight_w);
91
92 if(pads[0] != pads[2] or pads[1] != pads[3])
93 {
94 std::vector<int64_t> padding = {0, 0, pads[0], pads[1], 0, 0, pads[2], pads[3]};
95 l0 = info.add_instruction(migraphx::make_op("pad", {{"pads", padding}}), l0);
96 }
97 else

Callers

nothing calls this directly

Calls 13

containsFunction · 0.85
calculate_paddingFunction · 0.85
lensMethod · 0.80
atMethod · 0.80
reorder_dataMethod · 0.80
to_kcxyMethod · 0.80
copyFunction · 0.50
make_opFunction · 0.50
get_shapeMethod · 0.45
sizeMethod · 0.45
findMethod · 0.45
add_instructionMethod · 0.45

Tested by

no test coverage detected