MCPcopy Index your code
hub / github.com/apache/tvm / test_function_simple

Function test_function_simple

tests/python/relax/test_tvmscript_ir_builder.py:25–72  ·  view source on GitHub ↗

@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

()

Source from the content-addressed store, hash-verified

23
24
25def 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
75def test_emits():

Callers

nothing calls this directly

Calls 9

emitMethod · 0.95
functionMethod · 0.95
emit_func_outputMethod · 0.95
getMethod · 0.95
IRBuilderClass · 0.90
call_dps_packedMethod · 0.80
functionMethod · 0.45
nameMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…