()
| 255 | |
| 256 | |
| 257 | def test_simple_replace_all_uses(): |
| 258 | @tvm.script.ir_module |
| 259 | class Lv0To1: |
| 260 | @R.function |
| 261 | def main(x: R.Tensor((32, 32), "float32")) -> R.Tensor((32, 32), "float32"): |
| 262 | # lv0 => lv1 |
| 263 | # / \ |
| 264 | # lv2 lv3 |
| 265 | # \ / |
| 266 | # lv4 |
| 267 | with R.dataflow(): |
| 268 | lv0: R.Tensor((32, 32), "float32") = R.call_dps_packed( |
| 269 | "my_relu", (x,), R.Tensor((32, 32), dtype="float32") |
| 270 | ) |
| 271 | lv1: R.Tensor((32, 32), "float32") = R.call_dps_packed( |
| 272 | "my_sigmoid", (x,), R.Tensor((32, 32), dtype="float32") |
| 273 | ) |
| 274 | lv2: R.Tensor((32, 32), "float32") = R.call_dps_packed( |
| 275 | "my_add", (x, lv0), R.Tensor((32, 32), dtype="float32") |
| 276 | ) |
| 277 | lv3: R.Tensor((32, 32), "float32") = R.call_dps_packed( |
| 278 | "my_mul", (x, lv0), R.Tensor((32, 32), dtype="float32") |
| 279 | ) |
| 280 | lv4: R.Tensor((32, 32), "float32") = R.call_dps_packed( |
| 281 | "my_whatever", (lv2, lv3), R.Tensor((32, 32), dtype="float32") |
| 282 | ) |
| 283 | R.output(lv4) |
| 284 | return lv4 |
| 285 | |
| 286 | root_fn = Lv0To1["main"] |
| 287 | dfb = root_fn.body.blocks[0] |
| 288 | |
| 289 | n2binding = name_to_binding(root_fn) |
| 290 | |
| 291 | rwt = DataflowBlockRewrite(dfb, root_fn) |
| 292 | rwt.replace_all_uses(n2binding["lv0"][0].var, n2binding["lv1"][0].var) |
| 293 | rwt.remove_unused(n2binding["lv0"][0].var) |
| 294 | |
| 295 | assert_immutability(rwt, dfb, root_fn) |
| 296 | |
| 297 | n2binding_after = name_to_binding(rwt.mutated_root_fn()) |
| 298 | assert "lv0" not in n2binding_after |
| 299 | |
| 300 | |
| 301 | def test_simple_module_update(): |
nothing calls this directly
no test coverage detected
searching dependent graphs…