|
|
@@ -3723,7 +3723,7 @@ TEST(TestGoptInference, PreProcessCase1) { |
|
|
|
ASSERT_TRUE(y_opt.node()->owner_opr()->same_type<opr::RelayoutFormat>()); |
|
|
|
} |
|
|
|
|
|
|
|
TEST(TestGoptInference, WarpAndPreProcessCase) { |
|
|
|
TEST(TestGoptInference, WarpAndPreProcessCase0) { |
|
|
|
REQUIRE_GPU(1); |
|
|
|
HostTensorGenerator<dtype::Uint8, RandomDistribution::UNIFORM> gen(0, 255); |
|
|
|
auto cn = CompNode::load("gpu0"); |
|
|
@@ -3774,7 +3774,57 @@ TEST(TestGoptInference, WarpAndPreProcessCase) { |
|
|
|
graph->compile({{y_opt, {}}}) |
|
|
|
->to_json() |
|
|
|
->writeto_fpath(output_file( |
|
|
|
"TestGoptInference.WarpAndPreProcessCase.json")); |
|
|
|
"TestGoptInference.WarpAndPreProcessCase0.json")); |
|
|
|
|
|
|
|
HostTensorND host_y_opt, host_y; |
|
|
|
auto func = graph->compile({make_callback_copy(y, host_y), |
|
|
|
make_callback_copy(y_opt, host_y_opt)}); |
|
|
|
func->execute(); |
|
|
|
MGB_ASSERT_TENSOR_NEAR(host_y, host_y_opt, 1e-5); |
|
|
|
} |
|
|
|
|
|
|
|
TEST(TestGoptInference, WarpAndPreProcessCase1) { |
|
|
|
REQUIRE_GPU(1); |
|
|
|
HostTensorGenerator<dtype::Uint8, RandomDistribution::UNIFORM> gen(0, 255); |
|
|
|
auto cn = CompNode::load("gpu0"); |
|
|
|
auto graph = ComputingGraph::make(); |
|
|
|
graph->options().graph_opt_level = 0; |
|
|
|
|
|
|
|
size_t n = 1; |
|
|
|
size_t c = 3; |
|
|
|
size_t h = 16; |
|
|
|
size_t w = 16; |
|
|
|
auto host_x1 = gen({n, h, w, c}, cn); |
|
|
|
auto x = opr::Host2DeviceCopy::make(*graph, host_x1); |
|
|
|
|
|
|
|
auto mat_host = std::make_shared<HostTensorND>(cn, TensorShape{n, 3, 3}, |
|
|
|
dtype::Float32()); |
|
|
|
warp_perspective_mat_gen(*mat_host, n, h, w); |
|
|
|
auto mat = opr::Host2DeviceCopy::make(*graph, mat_host).rename("mat"); |
|
|
|
|
|
|
|
opr::WarpPerspective::Param warp_param; |
|
|
|
warp_param.format = opr::WarpPerspective::Param::Format::NHWC; |
|
|
|
auto x_warp = |
|
|
|
opr::WarpPerspective::make(x, mat, TensorShape{h, w}, warp_param); |
|
|
|
auto x_nchw = opr::Dimshuffle::make(x_warp, {0, 3, 1, 2}, 4, cn); |
|
|
|
|
|
|
|
auto result = opr::TypeCvt::make(x_nchw, dtype::Float32(), cn); |
|
|
|
|
|
|
|
auto y = result; |
|
|
|
SymbolVar y_opt; |
|
|
|
auto options = gopt::OptimizeForInferenceOptions{}; |
|
|
|
options.enable_fuse_preprocess(); |
|
|
|
unpack_vector(gopt::optimize_for_inference({y}, options), y_opt); |
|
|
|
|
|
|
|
ASSERT_TRUE(y_opt.node()->owner_opr()->same_type<opr::WarpPerspective>()); |
|
|
|
|
|
|
|
ASSERT_EQ(opr::WarpPerspective::Param::Format::NHWC_NCHW, |
|
|
|
find_opr<opr::WarpPerspective>(y_opt).param().format); |
|
|
|
|
|
|
|
graph->compile({{y_opt, {}}}) |
|
|
|
->to_json() |
|
|
|
->writeto_fpath(output_file( |
|
|
|
"TestGoptInference.WarpAndPreProcessCase1.json")); |
|
|
|
|
|
|
|
HostTensorND host_y_opt, host_y; |
|
|
|
auto func = graph->compile({make_callback_copy(y, host_y), |
|
|
|