()
| 217 | |
| 218 | |
| 219 | def 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 | |
| 245 | def test_vm_invoke_closure(): |
nothing calls this directly
no test coverage detected
searching dependent graphs…