()
| 20 | |
| 21 | |
| 22 | def test_replace_vars(): |
| 23 | g = mgb_graph.Graph() |
| 24 | g.options.async_exec_level = 0b100 |
| 25 | device = "xpux" |
| 26 | dtype = np.float32 |
| 27 | a = mgb_graph.InputNode(device=device, dtype=dtype, graph=g) |
| 28 | const = g.make_const(1.234, device=device) |
| 29 | add_op = Elemwise(Elemwise.Mode.ADD) |
| 30 | mul_op = Elemwise(Elemwise.Mode.MUL) |
| 31 | a_plus_a = apply_normal_varnode(add_op, a.outputs[0], a.outputs[0])[0] |
| 32 | a_plus_a_mul_const = apply_normal_varnode(mul_op, a_plus_a, const)[0] |
| 33 | rst = apply_normal_varnode(add_op, a_plus_a_mul_const, a.outputs[0])[0] |
| 34 | (new,) = cgtools.replace_vars([rst._node], {const._node: a_plus_a._node}) |
| 35 | out = mgb_graph.OutputNode(mgb_graph.VarNode(new)) |
| 36 | func = g.compile(out.outputs[0]) |
| 37 | func.execute() |
| 38 | x = make_dev_tensor(5.0, device=device) |
| 39 | a.set_value(x) |
| 40 | res = out.get_value().numpy() |
| 41 | np.testing.assert_equal(res, np.array([105.0])) |
| 42 | |
| 43 | |
| 44 | def test_replace_oprs(): |
nothing calls this directly
no test coverage detected