parse_resize.cpp 22.3 KB
Newer Older
1
2
3
/*
 * The MIT License (MIT)
 *
4
 * Copyright (c) 2015-2023 Advanced Micro Devices, Inc. All rights reserved.
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 */
Paul Fultz II's avatar
Paul Fultz II committed
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#include <migraphx/onnx/op_parser.hpp>
#include <migraphx/onnx/checks.hpp>
#include <migraphx/ranges.hpp>
#include <migraphx/shape_for_each.hpp>
#include <migraphx/instruction.hpp>
#include <migraphx/make_op.hpp>

namespace migraphx {
inline namespace MIGRAPHX_INLINE_NS {
namespace onnx {

const auto& get_nearest_op(const std::string& mode)
{
    using nearest_op = std::function<std::size_t(std::size_t, double)>;
    static std::unordered_map<std::string, nearest_op> const nearest_ops = {
        {"round_prefer_floor",
         [=](std::size_t d_in, double val) {
             val = std::max(0.0, std::min(d_in - 1.0, val));
             return static_cast<std::size_t>(std::ceil((val - 0.5)));
         }},
        {"round_prefer_ceil",
         [=](std::size_t d_in, double val) {
             val = std::max(0.0, std::min(d_in - 1.0, val));
             return static_cast<std::size_t>(std::round((val)));
         }},
        {"floor",
         [=](std::size_t d_in, double val) {
             val = std::max(0.0, std::min(d_in - 1.0, val));
             return static_cast<std::size_t>(std::floor((val)));
         }},
        {"ceil", [=](std::size_t d_in, double val) {
             val = std::max(0.0, std::min(d_in - 1.0, val));
             return static_cast<std::size_t>(std::ceil((val)));
         }}};

59
    if(not contains(nearest_ops, mode))
Paul Fultz II's avatar
Paul Fultz II committed
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
    {
        MIGRAPHX_THROW("PARSE_RESIZE: nearest_mode " + mode + " not supported!");
    }

    return nearest_ops.at(mode);
}

const auto& get_original_idx_op(const std::string& mode)
{
    using original_idx_op = std::function<double(std::size_t, std::size_t, std::size_t, double)>;
    static std::unordered_map<std::string, original_idx_op> const idx_ops = {
        {"half_pixel",
         [=](std::size_t, std::size_t, std::size_t idx, double scale) {
             return (idx + 0.5) / scale - 0.5;
         }},
        {"pytorch_half_pixel",
         [=](std::size_t, std::size_t l_out, std::size_t idx, double scale) {
             return l_out > 1 ? (idx + 0.5) / scale - 0.5 : 0.0;
         }},
        {"align_corners",
         [=](std::size_t l_in, std::size_t l_out, std::size_t idx, double) {
81
             return (l_out == 1) ? 0.0 : (1.0 * idx * (l_in - 1.0) / (l_out - 1.0));
Paul Fultz II's avatar
Paul Fultz II committed
82
83
84
85
86
87
88
         }},
        {"asymmetric",
         [=](std::size_t, std::size_t, std::size_t idx, double scale) { return idx / scale; }},
        {"tf_half_pixel_for_nn", [=](std::size_t, std::size_t, std::size_t idx, double scale) {
             return (idx + 0.5) / scale;
         }}};

89
    if(not contains(idx_ops, mode))
Paul Fultz II's avatar
Paul Fultz II committed
90
91
92
93
94
95
96
    {
        MIGRAPHX_THROW("PARSE_RESIZE: coordinate_transformation_mode " + mode + " not supported!");
    }

    return idx_ops.at(mode);
}

97
98
99
static std::vector<int>
calc_neighbor_points(const std::vector<std::vector<std::vector<std::size_t>>>& vvv_ind,
                     int i_dim,
100
                     std::vector<std::vector<std::size_t>> vec_dims,
101
102
103
104
                     const shape& in_s)
{
    if(i_dim == vvv_ind.size())
    {
105
        std::vector<int> vec_ind(vec_dims.size());
106
107
108
109
110
111
        std::transform(vec_dims.begin(), vec_dims.end(), vec_ind.begin(), [&](auto idx) {
            return static_cast<int>(in_s.index(idx));
        });
        return vec_ind;
    }

112
    const auto& vv_lo = vvv_ind[i_dim][0];
113
114
115
116
117
118
119
120
121
122
123
124
125
    std::vector<std::vector<std::size_t>> vec_dims1;
    for(std::size_t start = 0; start < vec_dims.size(); start += vv_lo.size())
    {
        std::transform(vv_lo.begin(),
                       vv_lo.end(),
                       vec_dims.begin() + start,
                       std::back_inserter(vec_dims1),
                       [](auto i, auto dim) {
                           dim.push_back(i);
                           return dim;
                       });
    }

126
127
    const auto& vv_hi = vvv_ind[i_dim][1];
    for(std::size_t start = 0; start < vec_dims.size(); start += vv_hi.size())
128
129
130
131
132
133
134
135
136
137
    {
        std::transform(vv_hi.begin(),
                       vv_hi.end(),
                       vec_dims.begin() + start,
                       std::back_inserter(vec_dims1),
                       [](auto i, auto dim) {
                           dim.push_back(i);
                           return dim;
                       });
    }
138
139
    vec_dims.clear();
    return calc_neighbor_points(vvv_ind, i_dim + 1, std::move(vec_dims1), in_s);
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
}

static std::string get_coord_trans_mode(const onnx_parser::attribute_map& attr)
{
    std::string coord_trans_mode = "half_pixel";
    if(contains(attr, "coordinate_transformation_mode"))
    {
        coord_trans_mode = attr.at("coordinate_transformation_mode").s();
        // does not support transformation mode "tf_crop_and_resize"
        if(coord_trans_mode == "tf_crop_and_resize")
        {
            MIGRAPHX_THROW("PARSE_RESIZE: \"tf_crop_and_resize\" mode is not supported!");
        }
    }

    return coord_trans_mode;
}

static std::string get_mode(const onnx_parser::attribute_map& attr)
{
    std::string mode = "nearest";
    if(contains(attr, "mode"))
    {
        mode = attr.at("mode").s();
        if(mode != "nearest" and mode != "linear")
        {
            MIGRAPHX_THROW("PARSE_RESIZE: only nearest and linear modes are supported!");
        }
    }

    return mode;
}

static std::string get_nearest_mode(const onnx_parser::attribute_map& attr)
{
    std::string nearest_mode = "round_prefer_floor";
    if(contains(attr, "nearest_mode"))
    {
        nearest_mode = attr.at("nearest_mode").s();
    }

    return nearest_mode;
}

184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
static std::vector<double> get_scales(const onnx_parser::attribute_map& attr)
{
    std::vector<double> scales;
    if(contains(attr, "scales"))
    {
        copy(attr.at("scales").floats(), std::back_inserter(scales));
    }

    return scales;
}

static void parse_args(const std::vector<instruction_ref>& args,
                       const std::vector<size_t>& in_lens,
                       const std::string& op_name,
                       std::vector<double>& vec_scale,
                       std::vector<std::size_t>& out_lens)
{
    for(const auto& arg : args)
    {
        if(arg->name() == "undefined" or arg == args.front())
        {
            continue;
        }

        // skipped empty input
        auto lens = arg->get_shape().lens();
        if(lens.empty())
        {
            continue;
        }

        auto type = arg->get_shape().type();
        // output size
        if(type == shape::int64_type)
        {
            auto arg_out_s = arg->eval();
            check_arg_empty(arg_out_s,
                            "PARSE_" + op_name + ": dynamic output size is not supported!");
            arg_out_s.visit([&](const auto& ol) { out_lens.assign(ol.begin(), ol.end()); });

            if(out_lens.size() != in_lens.size())
            {
                MIGRAPHX_THROW("PARSE_" + op_name +
                               ": specified output size does not match input size");
            }

            // compute the scale
            vec_scale.resize(in_lens.size());
            std::transform(in_lens.begin(),
                           in_lens.end(),
                           out_lens.begin(),
                           vec_scale.begin(),
                           [](auto iss, auto oss) { return 1.0 * oss / iss; });
        }
        else
        {

            // scale input
            if(lens[0] == in_lens.size())
            {
                auto arg_scale = arg->eval();
                check_arg_empty(arg_scale,
                                "PARSE_" + op_name + ": dynamic input scale is not supported!");

                arg_scale.visit([&](const auto& v) { vec_scale.assign(v.begin(), v.end()); });
            }
        }
    }
}

Paul Fultz II's avatar
Paul Fultz II committed
254
255
struct parse_resize : op_parser<parse_resize>
{
Shucai Xiao's avatar
Shucai Xiao committed
256
    std::vector<op_desc> operators() const { return {{"Resize"}, {"Upsample"}}; }
Paul Fultz II's avatar
Paul Fultz II committed
257

258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
    // A helper for one case of parse().
    // Dynamic batch:  Only args[0] can have a dynamic shape, only the 0'th
    // dimension--batch size--can be non-fixed, and the only resize mode allowed is "nearest"
    instruction_ref dynamic_nearest_parse(const std::vector<size_t>& out_lens,
                                          const std::vector<double>& vec_scale,
                                          const op_desc& opd,
                                          onnx_parser::node_info& info,
                                          const std::vector<instruction_ref>& args) const
    {
        // coord transform mode
        std::string coord_trans_mode = get_coord_trans_mode(info.attributes);
        // mode: only nearest and linear modes are supported for now
        std::string mode = get_mode(info.attributes);

        // rounding option when using "nearest"
        std::string nearest_mode = get_nearest_mode(info.attributes);

        if(mode == "nearest")
        {
            auto some_dims = args[0]->get_shape().dyn_dims();

            bool mostly_fixed =
                std::all_of(some_dims.begin() + 1,
                            some_dims.end(),
282
                            [](const shape::dynamic_dimension& dd) { return dd.is_fixed(); });
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333

            if(not mostly_fixed)
                MIGRAPHX_THROW("PARSE_" + opd.op_name +
                               ": dynamic shape inputs other than batch size are not supported");

            // Get static dimension set and
            // Drop the 0'th dimension,
            auto fixed_dims = args[0]->get_shape().to_static(1).lens();
            fixed_dims.erase(fixed_dims.begin());
            // dimensions of the (scaled) output, also with the 0'th dimension dropped
            auto fixed_out_lens = out_lens;
            fixed_out_lens.erase(fixed_out_lens.begin());

            // create a shape with the scaled lens and no batch dimension
            migraphx::shape static_out_shape(args[0]->get_shape().type(), fixed_out_lens);

            //               map out_idx to in_idx
            auto idx_op     = get_original_idx_op(coord_trans_mode);
            auto nearest_op = get_nearest_op(nearest_mode);

            // For each element of static_out_shape, find the matching location of input shape.
            // The indexes we find will be an argument to the gather op.
            shape_for_each(static_out_shape, [&](const auto& out_idx_v, size_t) {
                std::vector<size_t> in_idx(out_idx_v.size());
                for(auto ii = 0; ii < fixed_dims.size(); ++ii)
                {
                    // Convert this index by scaling.
                    auto idx_val =
                        idx_op(fixed_dims[ii], fixed_out_lens[ii], out_idx_v[ii], vec_scale[ii]);
                    // round the scaled value to an int index
                    in_idx[ii] = nearest_op(fixed_dims[ii], idx_val);
                }
            });

            instruction_ref gather_ins{args[0]};
            // for each static dimension
            for(auto ii = 0; ii < fixed_dims.size(); ++ii)
            {
                std::vector<size_t> in_idx(fixed_out_lens[ii]);
                // for range of this dimension's size in output
                for(auto len : range(fixed_out_lens[ii]))
                {
                    // Convert this index by scaling.
                    auto idx_val =
                        idx_op(fixed_dims[ii], fixed_out_lens[ii], len, vec_scale[ii + 1]);

                    // round the scaled value to an index
                    in_idx[len] = nearest_op(fixed_dims[ii], idx_val);
                    // Put the value into index vector
                }
                // Create a 1D shape literal
334
                auto index_lit = info.add_literal(literal(
335
336
337
338
                    migraphx::shape(migraphx::shape::int64_type, {fixed_out_lens[ii]}), in_idx));

                // add a "gather" instruction
                gather_ins = info.add_instruction(
339
                    make_op("gather", {{"axis", 1 + ii}}), gather_ins, index_lit);
340
341
342
343
344
345
346
347
348
            }
            return gather_ins;
        }
        else
        {
            MIGRAPHX_THROW("PARSE_RESIZE: only nearest_mode supports dynamic batch size input");
        }
    }

Shucai Xiao's avatar
Shucai Xiao committed
349
    instruction_ref parse(const op_desc& opd,
Paul Fultz II's avatar
Paul Fultz II committed
350
351
352
353
                          const onnx_parser& /*parser*/,
                          onnx_parser::node_info info,
                          std::vector<instruction_ref> args) const
    {
354
355
        // coord transform mode
        std::string coord_trans_mode = get_coord_trans_mode(info.attributes);
Paul Fultz II's avatar
Paul Fultz II committed
356

357
358
        // mode: only nearest and linear modes are supported for now
        std::string mode = get_mode(info.attributes);
Paul Fultz II's avatar
Paul Fultz II committed
359
360

        // nearest mode
361
        std::string nearest_mode = get_nearest_mode(info.attributes);
Paul Fultz II's avatar
Paul Fultz II committed
362
363

        // check exclude_outside, only support 0
364
365
        if(contains(info.attributes, "exclude_outside") and
           info.attributes.at("exclude_outside").i() == 1)
Paul Fultz II's avatar
Paul Fultz II committed
366
        {
Shucai Xiao's avatar
Shucai Xiao committed
367
            MIGRAPHX_THROW("PARSE_" + opd.op_name + ": exclude_outside 1 is not supported!");
Paul Fultz II's avatar
Paul Fultz II committed
368
369
        }

370
        // input data shape info.  Convert static lens to dynamic to simplify referencing them later
371
        auto in_s = args[0]->get_shape().to_dynamic();
372
        if(args[0]->get_shape().dynamic() and in_s.ndim() < 2)
373
374
375
            MIGRAPHX_THROW(
                "PARSE_" + opd.op_name +
                ": requires 2 or more dimensions input, where first dimension is batch #");
376
        std::vector<migraphx::shape::dynamic_dimension> in_dims = in_s.dyn_dims();
Paul Fultz II's avatar
Paul Fultz II committed
377
378

        // output shape is explicitly specified
379
        std::vector<size_t> out_lens(in_s.ndim());
Paul Fultz II's avatar
Paul Fultz II committed
380
381

        // scale
382
        std::vector<double> vec_scale = get_scales(info.attributes);
Paul Fultz II's avatar
Paul Fultz II committed
383

384
        // Look at inputs and infer either output size or scale, depending on input type
385
        for(const auto& arg : args)
Paul Fultz II's avatar
Paul Fultz II committed
386
        {
387
388
            if(arg != args[0] and arg->get_shape().dynamic())
            {
389
390
                MIGRAPHX_THROW("PARSE_" + opd.op_name +
                               ": no dynamic input shapes allowed except the first one");
391
392
            }

393
394
395
            // skip first input and any empty inputs
            auto lens = arg->get_shape().to_static(1).lens();
            if(arg->name() == "undefined" or arg == args.front() or lens.empty())
396
397
398
            {
                continue;
            }
Paul Fultz II's avatar
Paul Fultz II committed
399

400
            auto type = arg->get_shape().type();
401
402
403

            // This input is inferred to mean output size if type == int64_type; otherwise
            // read it as the scales
404
            if(type == shape::int64_type)
Paul Fultz II's avatar
Paul Fultz II committed
405
            {
406
                auto arg_out_s = arg->eval();
Shucai Xiao's avatar
Shucai Xiao committed
407
408
                check_arg_empty(arg_out_s,
                                "PARSE_" + opd.op_name + ": dynamic output size is not supported!");
409
410
                out_lens.clear();
                arg_out_s.visit([&](auto ol) { out_lens.assign(ol.begin(), ol.end()); });
411

412
                if(out_lens.size() != in_s.ndim())
413
                {
Shucai Xiao's avatar
Shucai Xiao committed
414
                    MIGRAPHX_THROW("PARSE_" + opd.op_name +
415
                                   ": specified output rank does not match input rank");
416
417
                }

418
                // compute the scale in each dimension
419
                vec_scale.resize(in_s.ndim());
420
421
422

                std::transform(in_dims.begin(),
                               in_dims.end(),
423
424
                               out_lens.begin(),
                               vec_scale.begin(),
425
                               [](auto iss, auto oss) { return double(1.0 * oss / iss.max); });
426
                break;
Paul Fultz II's avatar
Paul Fultz II committed
427
            }
428
429
430
            else
            {
                // scale input
431
432
433
434
435
436
                auto arg_scale = arg->eval();
                check_arg_empty(arg_scale,
                                "PARSE_" + opd.op_name + ": dynamic input scale is not supported!");

                arg_scale.visit([&](auto v) { vec_scale.assign(v.begin(), v.end()); });
                if(in_dims.size() != vec_scale.size())
437
                {
438
439
                    MIGRAPHX_THROW("PARSE_" + opd.op_name +
                                   ": specified scale rank does not match input rank");
440
                }
441
442
443
444
445
446
447
448
449

                std::transform(in_dims.begin(),
                               in_dims.end(),
                               vec_scale.begin(),
                               out_lens.begin(),
                               [&](auto idx, auto scale) {
                                   // inferred output size is floor(idx.max * scale)
                                   return idx.max * scale;
                               });
450
                break;
451
            }
Paul Fultz II's avatar
Paul Fultz II committed
452
453
        }

454
        if(args[0]->get_shape().dynamic())
455
        {
456
            return dynamic_nearest_parse(out_lens, vec_scale, opd, info, args);
457
458
459
        }
        else
        {
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
            //
            //        Static input shape.
            //
            in_s         = args[0]->get_shape();
            auto in_lens = args[0]->get_shape().lens();

            shape out_s{in_s.type(), out_lens};
            std::size_t out_elements = out_s.elements();
            auto idx_op              = get_original_idx_op(coord_trans_mode);

            // reshape input to one-dimension
            std::vector<int64_t> rsp_lens = {static_cast<int64_t>(in_s.elements())};
            args[0]                       = info.make_contiguous(args[0]);
            auto rsp = info.add_instruction(make_op("reshape", {{"dims", rsp_lens}}), args[0]);

            if(mode == "nearest")
            {
                std::vector<int> ind(out_elements);

                // map out_idx to in_idx
                auto nearest_op = get_nearest_op(nearest_mode);
                shape_for_each(out_s, [&](const auto& out_idx_v, size_t out_idx) {
                    std::vector<size_t> in_idx(out_idx_v.size());
                    for(auto ii = 0; ii < in_lens.size(); ++ii)
                    {
                        auto idx_val =
                            idx_op(in_lens[ii], out_lens[ii], out_idx_v[ii], vec_scale[ii]);
                        in_idx[ii] = nearest_op(in_lens[ii], idx_val);
                    }
Paul Fultz II's avatar
Paul Fultz II committed
489

490
491
                    ind[out_idx] = static_cast<int64_t>(in_s.index(in_idx));
                });
492

493
494
495
496
497
498
                shape ind_s{shape::int32_type, out_lens};
                auto ins_ind = info.add_literal(literal(ind_s, ind));
                return info.add_instruction(make_op("gather", {{"axis", 0}}), rsp, ins_ind);
            }
            // linear mode
            else
Paul Fultz II's avatar
Paul Fultz II committed
499
            {
500
501
502
503
504
                auto nearest_floor = get_nearest_op("floor");
                auto nearest_ceil  = get_nearest_op("ceil");

                // get the number of dimensions
                std::size_t n_dim = out_lens.size();
Brian Pickrell's avatar
Brian Pickrell committed
505
506
507
                std::vector<std::vector<std::size_t>> vv_ind(
                    2, std::vector<std::size_t>(out_elements));
                std::vector<std::vector<std::vector<std::size_t>>> vvv_ind(n_dim, vv_ind);
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
                std::vector<std::vector<float>> delta(n_dim, std::vector<float>(out_elements));

                shape_for_each(out_s, [&](const auto& out_idx_v, size_t out_idx) {
                    for(auto ii = 0; ii < in_lens.size(); ++ii)
                    {
                        auto idx_val =
                            idx_op(in_lens[ii], out_lens[ii], out_idx_v[ii], vec_scale[ii]);
                        vvv_ind[ii][0][out_idx] = nearest_floor(in_lens[ii], idx_val);
                        vvv_ind[ii][1][out_idx] = nearest_ceil(in_lens[ii], idx_val);
                        delta[ii][out_idx]      = idx_val - vvv_ind[ii][0][out_idx];
                    }
                });

                auto ind = calc_neighbor_points(
                    vvv_ind, 0, std::vector<std::vector<std::size_t>>(out_elements), in_s);
                auto ind_lens = out_lens;
                ind_lens[0] *= (std::size_t{1} << n_dim);
                shape ind_s{shape::int32_type, ind_lens};
                auto ins_ind = info.add_literal(literal(ind_s, ind));
                auto data    = info.add_instruction(make_op("gather", {{"axis", 0}}), rsp, ins_ind);

                auto dim_lens = out_lens;
                dim_lens[0] *= (std::size_t{1} << (n_dim - 1));
                for(std::size_t i = 0; i < n_dim; ++i)
532
                {
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
                    shape dim_s{shape::float_type, dim_lens};
                    const auto& dim_delta = delta[n_dim - i - 1];
                    std::vector<float> delta_data;
                    for(std::size_t j = 0; j < dim_lens[0] / out_lens[0]; ++j)
                    {
                        delta_data.insert(delta_data.begin(), dim_delta.begin(), dim_delta.end());
                    }
                    auto ins_delta = info.add_literal(dim_s, delta_data);

                    // slice the data
                    int64_t slc_stride = dim_lens[0];
                    auto low           = info.add_instruction(
                        make_op("slice", {{"axes", {0}}, {"starts", {0}}, {"ends", {slc_stride}}}),
                        data);
                    auto hi = info.add_instruction(
                        make_op(
                            "slice",
550
                            {{"axes", {0}}, {"starts", {slc_stride}}, {"ends", {2 * slc_stride}}}),
551
552
553
554
555
556
                        data);
                    auto diff = info.add_instruction(make_op("sub"), hi, low);
                    auto ddf  = info.add_instruction(make_op("mul"), diff, ins_delta);
                    data      = info.add_instruction(make_op("add"), ddf, low);
                    dim_lens[0] /= 2;
                }
Paul Fultz II's avatar
Paul Fultz II committed
557

558
559
                return data;
            }
560
        }
Paul Fultz II's avatar
Paul Fultz II committed
561
562
563
564
    }
};

} // namespace onnx
565

Paul Fultz II's avatar
Paul Fultz II committed
566
567
} // namespace MIGRAPHX_INLINE_NS
} // namespace migraphx