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

Function test_vm_if

tests/python/relax/test_vm_execbuilder.py:219–242  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

217
218
219def test_vm_if():
220 ib = relax.ExecBuilder()
221 with ib.function("main", num_inputs=3):
222 ib.emit_if(ib.r(0), 3)
223 ib.emit_call("test.vm.add", args=[ib.r(1), ib.r(2)], dst=ib.r(3))
224 ib.emit_goto(2)
225 ib.emit_call("test.vm.mul", args=[ib.r(1), ib.r(2)], dst=ib.r(3))
226 ib.emit_ret(ib.r(3))
227 ex = ib.get()
228 vm = relax.VirtualMachine(ex, tvm.cpu())
229 a = tvm.runtime.tensor(
230 np.random.rand(
231 4,
232 )
233 )
234 b = tvm.runtime.tensor(
235 np.random.rand(
236 4,
237 )
238 )
239 res = vm["main"](0, a, b)
240 tvm.testing.assert_allclose(res.numpy(), a.numpy() * b.numpy(), rtol=1e-7, atol=1e-7)
241 res = vm["main"](1, a, b)
242 tvm.testing.assert_allclose(res.numpy(), a.numpy() + b.numpy(), rtol=1e-7, atol=1e-7)
243
244
245def test_vm_invoke_closure():

Callers

nothing calls this directly

Calls 9

functionMethod · 0.95
emit_ifMethod · 0.95
rMethod · 0.95
emit_callMethod · 0.95
emit_gotoMethod · 0.95
emit_retMethod · 0.95
getMethod · 0.95
numpyMethod · 0.80
cpuMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…