@R.function def foo(x: R.Tensor((128, 128), "float32")) -> R.Tensor(None, "float32", ndim=2): out = R.call_dps_packed("extern_func", x, R.Tensor((128, 128), dtype="float32")) return out
()
| 23 | |
| 24 | |
| 25 | def test_function_simple(): |
| 26 | """ |
| 27 | @R.function |
| 28 | def foo(x: R.Tensor((128, 128), "float32")) -> R.Tensor(None, "float32", ndim=2): |
| 29 | out = R.call_dps_packed("extern_func", x, R.Tensor((128, 128), dtype="float32")) |
| 30 | return out |
| 31 | """ |
| 32 | # create with Script IRBuilder |
| 33 | with IRBuilder() as ir_builder: |
| 34 | with R.function(): |
| 35 | R.func_name("foo") |
| 36 | R.func_attr({"Primitive": True}) |
| 37 | x = R.arg("x", relax.TensorStructInfo((128, 128), "float32")) |
| 38 | R.func_ret_struct_info(relax.TensorStructInfo(dtype="float32", ndim=2)) |
| 39 | y = R.emit( |
| 40 | R.call_dps_packed( |
| 41 | "extern_func", x, relax.TensorStructInfo((128, 128), dtype="float32") |
| 42 | ) |
| 43 | ) |
| 44 | out = R.emit( |
| 45 | R.call_dps_packed( |
| 46 | "extern_dps_func", y, relax.TensorStructInfo((128, 128), dtype="float32") |
| 47 | ) |
| 48 | ) |
| 49 | IRBuilder.name("out", out) |
| 50 | R.func_ret_value(out) |
| 51 | func = ir_builder.get() |
| 52 | # create with BlockBuilder |
| 53 | x = relax.Var("x", relax.TensorStructInfo((128, 128), "float32")) |
| 54 | bb = relax.BlockBuilder() |
| 55 | with bb.function("foo", (x,), attrs={"Primitive": True}): |
| 56 | y = bb.emit( |
| 57 | relax.call_dps_packed( |
| 58 | "extern_func", x, relax.TensorStructInfo((128, 128), dtype="float32") |
| 59 | ) |
| 60 | ) |
| 61 | out = bb.emit( |
| 62 | relax.call_dps_packed( |
| 63 | "extern_dps_func", y, relax.TensorStructInfo((128, 128), dtype="float32") |
| 64 | ) |
| 65 | ) |
| 66 | bb.emit_func_output(out) |
| 67 | mod = bb.get() |
| 68 | |
| 69 | tvm.ir.assert_structural_equal(func, mod["foo"]) |
| 70 | # check names |
| 71 | assert func.params[0].name_hint == "x" |
| 72 | assert func.body.body.name_hint == "out" |
| 73 | |
| 74 | |
| 75 | def test_emits(): |
nothing calls this directly
no test coverage detected
searching dependent graphs…