| 440 | |
| 441 | template <typename itype, typename otype> |
| 442 | void run_typecvt(CompNode cn) { |
| 443 | set_backend(Backend::MLIR); |
| 444 | auto graph = ComputingGraph::make(); |
| 445 | HostTensorGenerator<itype, RandomDistribution::UNIFORM> gen(-10, 10); |
| 446 | |
| 447 | auto host_x = gen({23, 42}, cn); |
| 448 | auto x = opr::Host2DeviceCopy::make(*graph, host_x); |
| 449 | auto y = opr::TypeCvt::make(x, otype()); |
| 450 | |
| 451 | auto ig_gen = std::make_unique<InternalGraphGenerator>(y.node()->owner_opr()); |
| 452 | |
| 453 | for (auto i : get_rev_topo_order(y)) { |
| 454 | if (!i->template same_type<opr::Host2DeviceCopy>()) { |
| 455 | ig_gen->add_opr(i); |
| 456 | } |
| 457 | } |
| 458 | |
| 459 | auto igraph = ig_gen->generate(); |
| 460 | auto y_jit = JITExecutor::make(igraph, ig_gen->orig_inps()); |
| 461 | |
| 462 | HostTensorND host_y, host_y_jit; |
| 463 | auto func = graph->compile( |
| 464 | {make_callback_copy(y, host_y), make_callback_copy(y_jit, host_y_jit)}); |
| 465 | func->execute(); |
| 466 | |
| 467 | MGB_ASSERT_TENSOR_EQ(host_y, host_y_jit); |
| 468 | }; |
| 469 | |
| 470 | #define add_typecvt_gtest(itype, otype) \ |
| 471 | TEST(TestJITMlirTypeCvt, itype##_to_##otype) { \ |