()
| 42 | |
| 43 | |
| 44 | def test_replace_oprs(): |
| 45 | g = mgb_graph.Graph() |
| 46 | g.options.async_exec_level = 0b100 |
| 47 | device = "xpux" |
| 48 | dtype = np.float32 |
| 49 | a = mgb_graph.InputNode(device=device, dtype=dtype, graph=g) |
| 50 | const = g.make_const(1.25, device=device) |
| 51 | add_op = Elemwise(Elemwise.Mode.ADD) |
| 52 | mul_op = Elemwise(Elemwise.Mode.MUL) |
| 53 | a_plus_a = apply_normal_varnode(add_op, a.outputs[0], a.outputs[0])[0] |
| 54 | old_opr = a_plus_a.op |
| 55 | a_plus_a_mul_const = apply_normal_varnode(mul_op, a_plus_a, const)[0] |
| 56 | a_mul_a = apply_normal_varnode(mul_op, a.outputs[0], a.outputs[0])[0] |
| 57 | new_opr = a_mul_a.op |
| 58 | (new,) = cgtools.replace_oprs( |
| 59 | [a_plus_a_mul_const._node], {old_opr._node: new_opr._node} |
| 60 | ) |
| 61 | out = mgb_graph.OutputNode(mgb_graph.VarNode(new)) |
| 62 | func = g.compile(out.outputs[0]) |
| 63 | func.execute() |
| 64 | x = make_dev_tensor(5.0, device=device) |
| 65 | a.set_value(x) |
| 66 | res = out.get_value().numpy() |
| 67 | np.testing.assert_equal(res, np.array([5.0 * 5.0 * 1.25])) |
| 68 | |
| 69 | |
| 70 | def test_graph_traversal(): |
nothing calls this directly
no test coverage detected