Simple case of inlining Inlining can be done either by providing a string name or a GlobalVar.
(key_type)
| 27 | |
| 28 | @pytest.mark.parametrize("key_type", [tvm.ir.GlobalVar, str]) |
| 29 | def test_inline_simple(key_type): |
| 30 | """Simple case of inlining |
| 31 | |
| 32 | Inlining can be done either by providing a string name or a |
| 33 | GlobalVar. |
| 34 | """ |
| 35 | |
| 36 | @I.ir_module |
| 37 | class Before: |
| 38 | @R.function(private=True) |
| 39 | def main(A: R.Tensor([16, 16], "int32")) -> R.Tensor([16, 32], "int32"): |
| 40 | B = A * A |
| 41 | C = Before.subroutine(B) |
| 42 | D = C + C |
| 43 | return D |
| 44 | |
| 45 | @R.function(private=True) |
| 46 | def subroutine(B: R.Tensor([16, 16], "int32")) -> R.Tensor([16, 32], "int32"): |
| 47 | C = R.concat([B, B], axis=1) |
| 48 | return C |
| 49 | |
| 50 | @R.function(private=True) |
| 51 | def expected(A: R.Tensor([16, 16], "int32")) -> R.Tensor([16, 32], "int32"): |
| 52 | B = A * A |
| 53 | C = R.concat([B, B], axis=1) |
| 54 | D = C + C |
| 55 | return D |
| 56 | |
| 57 | gvar = Before.get_global_var("subroutine") |
| 58 | if key_type is tvm.ir.GlobalVar: |
| 59 | key = gvar |
| 60 | elif key_type is str: |
| 61 | key = gvar.name_hint |
| 62 | else: |
| 63 | raise TypeError(f"Unknown key_type: {key_type}") |
| 64 | |
| 65 | after = Before["main"].inline_functions({key: Before[gvar]}) |
| 66 | |
| 67 | tvm.ir.assert_structural_equal(expected, after) |
| 68 | |
| 69 | |
| 70 | def test_ambiguous_function_name(): |
nothing calls this directly
no test coverage detected
searching dependent graphs…