generate_root_modules.cpp 18.1 KB
Newer Older
umang yadav's avatar
umang yadav committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
/*
 * The MIT License (MIT)
 *
 * Copyright (c) 2015-2023 Advanced Micro Devices, Inc. All rights reserved.
 *
 * 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.
 */
#include <cstddef>
#include <limits>
#include <iterator>
#include <unordered_map>
#include <unordered_set>

#include <migraphx/env.hpp>
#include <migraphx/algorithm.hpp>
#include <migraphx/stringutils.hpp>
#include <migraphx/generate_root_modules.hpp>
#include <migraphx/pass_manager.hpp>
#include <migraphx/dead_code_elimination.hpp>
#include <migraphx/instruction.hpp>
#include <migraphx/program.hpp>
#include <migraphx/make_op.hpp>
#include <migraphx/iterator_for.hpp>
#include <migraphx/ranges.hpp>

Umang Yadav's avatar
Umang Yadav committed
42
MIGRAPHX_DECLARE_ENV_VAR(MIGRAPHX_DEBUG_ROOT_GENERATOR)
umang yadav's avatar
umang yadav committed
43
44
45
46
47
48
49
50
51
namespace migraphx {
inline namespace MIGRAPHX_INLINE_NS {

// copied from fuse_pointwise.cpp
static literal get_scalar(instruction_ref ins)
{
    if(ins->name() == "contiguous")
        return get_scalar(ins->inputs().front());
    const auto& s = ins->get_shape();
umang yadav's avatar
umang yadav committed
52
    if(s.elements() != 1 and not(s.scalar()))
umang yadav's avatar
umang yadav committed
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
        return {};
    if(not ins->can_eval())
        return {};
    auto e = ins->eval();
    literal r{};
    // needed for bool as visit_at invokes as() which promotes bool to int8
    // Without this we'll break type checks for logical ops that are fused.
    if(e.get_shape().type() == shape::bool_type)
    {
        r = literal{e.at<bool>()};
    }
    else
    {
        e.visit_at([&](auto x) { r = literal{x}; });
    }
    return r;
}

/*
Given target assignments (tass) for the instructions, generate run_on_target modules subgraphs
automatically. Input graph should be uncompiled migraphx program. target assignments (tass) map
should have a map of instruction to target_id. Instructions that are not inside tass map are
considered to be targeted for the "Ref" by default. params, literals and other builtins shouldn't be
Umang Yadav's avatar
Umang Yadav committed
76
77
78
79
80
part of the tass, only compute and certain reshaper instructions should be part of tass. Copy, sync
and alloc instructions would be generated by compiler at later stage, so those shouldn't be
considered. (TODO): CustomOps may require special handling.

Ref is used as default target for instructions that do not have assignments.
umang yadav's avatar
umang yadav committed
81
82

Step 1:
Umang Yadav's avatar
Umang Yadav committed
83
84
85
86
87
88
89
Identify subgraph boundaries:
(a) Boundaries can happen when any output of a node doesn't have same target
assignment as the node itself.
(b) Boundaries can happen when any output of any node doesn't have all its inputs with same target
assignment as the node itself.

For example graphs like following:
umang yadav's avatar
umang yadav committed
90
91
92
93
94
1.  Ref --> Target X --> Ref
2.  Ref --> Target X --> Target Y
3.  Target X --> Target Y --> Target Z , in this case target X and target Z can be same
4.  Target X --> "@return"
5.  Target X --> Ref --> "@return"
Umang Yadav's avatar
Umang Yadav committed
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
6.  When there is a fork in graph :
         Ref
          |
    -------------
    |           |
    |           |
Target X       Ref

7. When there is merge in a graph :

    Target X        Ref
       |             |
       ---------------
             |
         Target X
umang yadav's avatar
umang yadav committed
110
111
112
113
114
115
116
117
118
119
120

Each of those identified regions could have futher nested sub modules which needs to be handled
separately.

Step 2:
Collect parameters and return instructions for the subgraphs identified in Step 1.

Step 3:
Create modules using information collected in step 2 and insert run_on_target instructions.
*/

umang yadav's avatar
umang yadav committed
121
struct auto_gen_root_modules
umang yadav's avatar
umang yadav committed
122
123
{

umang yadav's avatar
umang yadav committed
124
    auto_gen_root_modules(migraphx::program& p, const target_assignments& target_assignments)
umang yadav's avatar
umang yadav committed
125
126
127
        : tass(target_assignments)
    {
        auto* mm = p.get_main_module();
Umang Yadav's avatar
Umang Yadav committed
128
        // initialize tid_counter, it is used to create meaningful names for the target modules
129
130
131
132
133
134
135
        for(const auto& i : tass)
        {
            if(tid_counter.find(i.second) == tid_counter.end())
            {
                update_tid_counter(i.second);
            }
        }
umang yadav's avatar
umang yadav committed
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
        find_subgraphs(mm, p);
        dead_code_elimination{}.apply(p);
    }

    void update_tid_counter(std::size_t tid)
    {
        if(tid_counter.find(tid) != tid_counter.end())
        {
            tid_counter[tid]++;
        }
        else
        {
            tid_counter[tid] = 0;
        }
    }

152
153
    bool has_different_tass(migraphx::instruction_ref current_ins,
                            std::optional<std::size_t> previous_tid)
Umang Yadav's avatar
Umang Yadav committed
154
    {
Umang Yadav's avatar
Umang Yadav committed
155
        if(tass.find(current_ins) == tass.end())
Umang Yadav's avatar
Umang Yadav committed
156
        {
Umang Yadav's avatar
Umang Yadav committed
157
            return previous_tid.has_value();
Umang Yadav's avatar
Umang Yadav committed
158
        }
Umang Yadav's avatar
Umang Yadav committed
159
160
        return tass.at(current_ins) !=
               previous_tid.value_or(std::numeric_limits<std::size_t>::max());
Umang Yadav's avatar
Umang Yadav committed
161
162
    }

Umang Yadav's avatar
Umang Yadav committed
163
164
    /*
    Merge node is defined as node where two or more branches converge.
165

Umang Yadav's avatar
Umang Yadav committed
166
167
168
169
170
        NodeX   NodeY
        |       |
        ---------
            |
           NodeZ
171

Umang Yadav's avatar
Umang Yadav committed
172
173
174
175
    For the partitioner, if any of the merge node's input doesn't have same tid as the merge node
    itself then, it is classified as boundary for subgraph.
    */
    bool is_merge_node(migraphx::instruction_ref ins, std::optional<std::size_t> ins_tid)
Umang Yadav's avatar
Umang Yadav committed
176
177
    {
        const auto inputs = ins->inputs();
Umang Yadav's avatar
Umang Yadav committed
178
179
        size_t in_degree  = inputs.size();
        if(in_degree == 1)
Umang Yadav's avatar
Umang Yadav committed
180
        {
Umang Yadav's avatar
Umang Yadav committed
181
            return false;
Umang Yadav's avatar
Umang Yadav committed
182
        }
Umang Yadav's avatar
Umang Yadav committed
183
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
        size_t input_from_other_tid_module = 0;
        size_t num_default_tids            = 0;
        size_t num_different_tids          = 0;
        size_t num_same_tid                = 0;
        // std::unordered_map<size_t, size_t> in_tid_freq_map;
        for(const auto& input_ins : inputs)
        {
            if(skip_ins.find(input_ins) != skip_ins.end())
            {
                input_from_other_tid_module++;
            }
            else if(tass.find(input_ins) == tass.end())
            {
                num_default_tids++;
            }
            else if(tass.at(input_ins) != ins_tid)
            {
                num_different_tids++;
            }
            else
            {
                num_same_tid++;
            }
        }
        assert(input_from_other_tid_module + num_default_tids + num_different_tids + num_same_tid ==
               in_degree);
        if(input_from_other_tid_module > 1)
        {
            return true;
        }
Umang Yadav's avatar
Umang Yadav committed
213
214
        else if((input_from_other_tid_module + num_default_tids == in_degree) or
                (num_same_tid + num_default_tids == in_degree))
Umang Yadav's avatar
Umang Yadav committed
215
216
217
        {
            return false;
        }
Umang Yadav's avatar
Umang Yadav committed
218
        (void)(num_different_tids);
Umang Yadav's avatar
Umang Yadav committed
219
        return true;
Umang Yadav's avatar
Umang Yadav committed
220
221
    }

Umang Yadav's avatar
Umang Yadav committed
222
223
    /*
    Fork node is defined as node where graph forks into two  or more branches
224

Umang Yadav's avatar
Umang Yadav committed
225
226
227
228
229
            NodeX
              |
        ------------
        |          |
      NodeY      NodeZ
230

Umang Yadav's avatar
Umang Yadav committed
231
232
233
    For the partitioner, if any of the fork node's output doesn't have same tid as the fork node
    itself then, it is classified as boundary for subgraph.
    */
Umang Yadav's avatar
Umang Yadav committed
234
    bool is_fork_node(migraphx::instruction_ref ins, std::size_t ins_tid)
Umang Yadav's avatar
Umang Yadav committed
235
236
    {
        const auto outputs = ins->outputs();
Umang Yadav's avatar
Umang Yadav committed
237
238
        if(outputs.size() == 1)
        {
Umang Yadav's avatar
Umang Yadav committed
239
            return false;
Umang Yadav's avatar
Umang Yadav committed
240
        }
Umang Yadav's avatar
Umang Yadav committed
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259

        // if all the outputs are for the "default" or with same tid then it is not a fork but
        // rather simply a boundary
        std::unordered_map<std::size_t, std::size_t> output_tids;
        for(const auto& output_ins : outputs)
        {
            if(tass.find(output_ins) != tass.end())
            {
                auto out_tid = tass.at(output_ins);
                if(output_tids.find(out_tid) == output_tids.end())
                {
                    output_tids[out_tid] = 1;
                }
                else
                {
                    output_tids[out_tid]++;
                }
            }
        }
Umang Yadav's avatar
Umang Yadav committed
260
261
262

        if(output_tids.empty() or
           (output_tids.size() == 1 and output_tids.cbegin()->second == outputs.size()))
Umang Yadav's avatar
Umang Yadav committed
263
264
265
266
        {
            return false;
        }

Umang Yadav's avatar
Umang Yadav committed
267
        return std::any_of(outputs.begin(), outputs.end(), [&](auto output_ins) {
268
269
270
271
            if(output_ins->name() == "return")
            {
                return false;
            }
Umang Yadav's avatar
Umang Yadav committed
272
            return (tass.find(output_ins) != tass.end() and tass.at(output_ins) != ins_tid);
Umang Yadav's avatar
Umang Yadav committed
273
        });
Umang Yadav's avatar
Umang Yadav committed
274
275
    }

umang yadav's avatar
umang yadav committed
276
277
278
279
    void find_subgraphs(migraphx::module_ref mm, migraphx::program& p)
    {
        // sort the graph in reverse post order DFS order
        mm->sort();
Umang Yadav's avatar
Umang Yadav committed
280
        if(enabled(MIGRAPHX_DEBUG_ROOT_GENERATOR{}))
umang yadav's avatar
umang yadav committed
281
282
283
284
        {
            std::cout << "sorted module: \n";
            mm->debug_print();
        }
Umang Yadav's avatar
Umang Yadav committed
285
        bool fork_node                         = false;
Umang Yadav's avatar
Fixes  
Umang Yadav committed
286
        std::optional<std::size_t> current_tid = nullopt;
umang yadav's avatar
umang yadav committed
287
288
        for(auto ins : iterator_for(*mm))
        {
Umang Yadav's avatar
Umang Yadav committed
289
            if(enabled(MIGRAPHX_DEBUG_ROOT_GENERATOR{}))
umang yadav's avatar
umang yadav committed
290
291
292
293
            {
                std::cout << "looking at instruction: \n";
                ins->debug_print();
            }
Umang Yadav's avatar
Umang Yadav committed
294
295
296
            if(fork_node)
            {
                assert(current_tid.has_value());
Umang Yadav's avatar
Umang Yadav committed
297
                generate_run_on_target_modules(mm, p, ins, current_tid);
Umang Yadav's avatar
Umang Yadav committed
298
299
300
301
302
303
304
305
                if(not same_tid_ins_vec.empty())
                {
                    current_tid = nullopt;
                    same_tid_ins_set.erase(ins);
                    same_tid_ins_vec.pop_back();
                }
                fork_node = false;
            }
umang yadav's avatar
umang yadav committed
306
307
            // skip all params, literal and builtins other than return, skip "run_on_target_mod"
            // ins
umang yadav's avatar
umang yadav committed
308
309
            if((starts_with(ins->name(), "@") and ins->name() != "@return") or
               skip_ins.count(ins) != 0)
umang yadav's avatar
umang yadav committed
310
311
312
            {
                continue;
            }
Umang Yadav's avatar
Fixes  
Umang Yadav committed
313
            if(not current_tid.has_value())
umang yadav's avatar
umang yadav committed
314
            {
Umang Yadav's avatar
Umang Yadav committed
315
                if(tass.find(ins) != tass.end())
Umang Yadav's avatar
Fixes  
Umang Yadav committed
316
317
318
319
                {
                    current_tid = std::make_optional<std::size_t>(tass.at(ins));
                    same_tid_ins_vec.push_back(ins);
                    same_tid_ins_set.insert(ins);
Umang Yadav's avatar
Umang Yadav committed
320
                    fork_node = is_fork_node(ins, current_tid.value());
Umang Yadav's avatar
Umang Yadav committed
321
                }
umang yadav's avatar
umang yadav committed
322
323
324
            }
            else
            {
325
                if(ins->name() == "@return" or has_different_tass(ins, current_tid) or
Umang Yadav's avatar
Fixes  
Umang Yadav committed
326
327
                   is_merge_node(ins, current_tid))
                {
Umang Yadav's avatar
Umang Yadav committed
328
                    generate_run_on_target_modules(mm, p, ins, current_tid);
Umang Yadav's avatar
Fixes  
Umang Yadav committed
329
330
331
332
333
334
335
336
                }
                else if(tass.at(ins) == current_tid.value())
                {
                    same_tid_ins_vec.push_back(ins);
                    same_tid_ins_set.insert(ins);
                }
                else
                {
Umang Yadav's avatar
Umang Yadav committed
337
                    MIGRAPHX_THROW("GenerateRootModules: this case shouldn't occur");
Umang Yadav's avatar
Fixes  
Umang Yadav committed
338
                }
Umang Yadav's avatar
Umang Yadav committed
339
340
                fork_node = is_fork_node(
                    ins, current_tid.value_or(std::numeric_limits<std::size_t>::max()));
umang yadav's avatar
umang yadav committed
341
342
            }

Umang Yadav's avatar
Umang Yadav committed
343
            if(not ins->module_inputs().empty())
umang yadav's avatar
umang yadav committed
344
345
346
347
348
            {
                std::vector<instruction_ref> same_tid_ins_vec_copy        = {};
                std::unordered_set<instruction_ref> same_tid_ins_set_copy = {};
                std::swap(same_tid_ins_set_copy, same_tid_ins_set);
                std::swap(same_tid_ins_vec_copy, same_tid_ins_vec);
umang yadav's avatar
umang yadav committed
349
                for(auto* sub_mod : ins->module_inputs())
umang yadav's avatar
umang yadav committed
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
                {
                    find_subgraphs(sub_mod, p);
                }
                std::swap(same_tid_ins_set_copy, same_tid_ins_set);
                std::swap(same_tid_ins_vec_copy, same_tid_ins_vec);
                mm->replace_instruction(
                    ins, ins->get_operator(), ins->inputs(), ins->module_inputs());
            }
        }
        assert(same_tid_ins_set.empty() and same_tid_ins_vec.empty());
    }

    void generate_run_on_target_modules(migraphx::module_ref mm,
                                        migraphx::program& p,
                                        migraphx::instruction_ref ins,
Umang Yadav's avatar
Umang Yadav committed
365
                                        std::optional<std::size_t>& current_tid)
umang yadav's avatar
umang yadav committed
366
367
368
369
    {
        assert(same_tid_ins_vec.size() == same_tid_ins_set.size());
        if(same_tid_ins_vec.empty())
        {
Umang Yadav's avatar
Umang Yadav committed
370
            assert(not current_tid.has_value());
umang yadav's avatar
umang yadav committed
371
372
373
            return;
        }
        // gather all parameters
Umang Yadav's avatar
Umang Yadav committed
374
375
        std::unordered_set<instruction_ref> params_set;
        std::vector<instruction_ref> params_vec;
umang yadav's avatar
umang yadav committed
376
        // gather all return values
377
        std::vector<instruction_ref> return_ins;
umang yadav's avatar
umang yadav committed
378
379
380
381
382
383
384
        for(auto tins : iterator_for(same_tid_ins_vec))
        {
            auto inputs  = (*tins)->inputs();
            auto outputs = (*tins)->outputs();
            transform_if(
                inputs.cbegin(),
                inputs.cend(),
Umang Yadav's avatar
Umang Yadav committed
385
                std::back_inserter(params_vec),
umang yadav's avatar
umang yadav committed
386
                [&](auto in_param) {
Umang Yadav's avatar
Umang Yadav committed
387
388
                    return (params_set.count(in_param) == 0 and
                            same_tid_ins_set.count(in_param) == 0);
umang yadav's avatar
umang yadav committed
389
                },
Umang Yadav's avatar
Umang Yadav committed
390
391
392
393
                [&](auto in_param) {
                    params_set.insert(in_param);
                    return in_param;
                });
umang yadav's avatar
umang yadav committed
394
395
396
397
            if(std::any_of(outputs.begin(), outputs.end(), [&](const auto out_ins) {
                   return same_tid_ins_set.count(out_ins) == 0;
               }))
            {
398
                return_ins.push_back(*tins);
umang yadav's avatar
umang yadav committed
399
400
            }
        }
Umang Yadav's avatar
Umang Yadav committed
401
        if(enabled(MIGRAPHX_DEBUG_ROOT_GENERATOR{}))
umang yadav's avatar
umang yadav committed
402
403
        {
            std::cout << "params ins: \n";
Umang Yadav's avatar
Umang Yadav committed
404
            for(auto tmp : iterator_for(params_vec))
umang yadav's avatar
umang yadav committed
405
406
407
            {
                (*tmp)->debug_print();
            }
Umang Yadav's avatar
Umang Yadav committed
408
            std::cout << "return ins: \n";
umang yadav's avatar
umang yadav committed
409
410
411
412
413
414
            for(auto tmp : iterator_for(return_ins))
            {
                (*tmp)->debug_print();
            }
        }

Umang Yadav's avatar
Umang Yadav committed
415
416
417
        auto* tmod = p.create_module("target_mod_" + std::to_string(current_tid.value()) + "_" +
                                     std::to_string(tid_counter[current_tid.value()]));
        update_tid_counter(current_tid.value());
umang yadav's avatar
umang yadav committed
418
419
420
        std::unordered_map<instruction_ref, instruction_ref> params_map;
        std::size_t param_counter = 0;
        std::vector<instruction_ref> rot_ins_params;
Umang Yadav's avatar
Umang Yadav committed
421
        for(auto pins : iterator_for(params_vec))
umang yadav's avatar
umang yadav committed
422
423
424
425
426
427
428
429
430
431
432
433
434
        {
            auto scalar = get_scalar(*pins);
            if(scalar.empty())
            {
                params_map[*pins] = tmod->add_parameter("param:" + std::to_string(param_counter++),
                                                        (*pins)->get_shape());
                rot_ins_params.push_back(*pins);
            }
            else
            {
                params_map[*pins] = tmod->add_literal(scalar);
            }
        }
umang yadav's avatar
umang yadav committed
435

umang yadav's avatar
umang yadav committed
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
        // TODO: what if params_map is empty ?
        assert(not params_map.empty());
        for(auto tins : iterator_for(same_tid_ins_vec))
        {
            auto inputs = (*tins)->inputs();
            std::vector<instruction_ref> new_inputs;
            std::transform(inputs.begin(),
                           inputs.end(),
                           std::back_inserter(new_inputs),
                           [&](auto input_ins) { return params_map.at(input_ins); });
            auto tmod_tins = tmod->add_instruction(
                (*tins)->get_operator(), new_inputs, (*tins)->module_inputs());
            // add parameter to params map so that it can be looked up by other insturctions
            params_map[*tins] = tmod_tins;
        }
umang yadav's avatar
umang yadav committed
451

umang yadav's avatar
umang yadav committed
452
453
454
455
456
        std::vector<instruction_ref> rins;
        std::unordered_map<instruction_ref, std::size_t> return_ins_idx_map;
        for(auto ritr : iterator_for(return_ins))
        {
            rins.push_back(params_map.at(*ritr));
457
            return_ins_idx_map[*ritr] = std::distance(return_ins.begin(), ritr);
umang yadav's avatar
umang yadav committed
458
459
        }
        tmod->add_return(rins);
umang yadav's avatar
umang yadav committed
460

Umang Yadav's avatar
Umang Yadav committed
461
        if(enabled(MIGRAPHX_DEBUG_ROOT_GENERATOR{}))
umang yadav's avatar
umang yadav committed
462
463
464
465
        {
            std::cout << "Created target module: " << tmod->name() << "\n";
            tmod->debug_print();
        }
umang yadav's avatar
umang yadav committed
466

umang yadav's avatar
umang yadav committed
467
        // add run_on_target ins
Umang Yadav's avatar
Umang Yadav committed
468
469
470
471
472
        auto rot_ins =
            mm->insert_instruction(ins,
                                   make_op("run_on_target", {{"target_id", current_tid.value()}}),
                                   rot_ins_params,
                                   {tmod});
umang yadav's avatar
umang yadav committed
473
        skip_ins.insert(rot_ins);
umang yadav's avatar
umang yadav committed
474

umang yadav's avatar
umang yadav committed
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
        // fetch return instructions from tuple
        for(auto mm_rins : iterator_for(return_ins))
        {
            auto tuple_elem_ins = mm->insert_instruction(
                ins,
                make_op("get_tuple_elem", {{"index", return_ins_idx_map.at(*mm_rins)}}),
                rot_ins);
            skip_ins.insert(tuple_elem_ins);
            // replace returns from tmod in main module
            mm->replace_instruction(*mm_rins, tuple_elem_ins);
        }
        dead_code_elimination{}.apply(*mm);
        // update current_tid
        same_tid_ins_set.clear();
        same_tid_ins_vec.clear();
        if(tass.find(ins) != tass.end())
        {
Umang Yadav's avatar
Umang Yadav committed
492
            current_tid = std::make_optional<std::size_t>(tass.at(ins));
umang yadav's avatar
umang yadav committed
493
494
495
496
497
            same_tid_ins_set.insert(ins);
            same_tid_ins_vec.push_back(ins);
        }
        else
        {
Umang Yadav's avatar
Umang Yadav committed
498
            current_tid = nullopt;
umang yadav's avatar
umang yadav committed
499
        }
Umang Yadav's avatar
Umang Yadav committed
500
        if(enabled(MIGRAPHX_DEBUG_ROOT_GENERATOR{}))
umang yadav's avatar
umang yadav committed
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
        {
            std::cout << "Main module after creation of target module: " << tmod->name() << "\n";
            mm->debug_print();
        }
    }

    private:
    const target_assignments tass;
    std::unordered_map<std::size_t, std::size_t> tid_counter;
    std::unordered_set<instruction_ref> skip_ins;
    std::vector<instruction_ref> same_tid_ins_vec;
    std::unordered_set<instruction_ref> same_tid_ins_set;
};

void generate_root_modules(migraphx::program& p, const target_assignments& tass)
{
umang yadav's avatar
umang yadav committed
517
    auto_gen_root_modules(p, tass);
umang yadav's avatar
umang yadav committed
518
519
520
521
}

} // namespace MIGRAPHX_INLINE_NS
} // namespace migraphx