Skip to content

Commit

Permalink
add unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
wilson-seok committed Feb 12, 2025
1 parent 411068a commit 3364d95
Showing 1 changed file with 103 additions and 0 deletions.
103 changes: 103 additions & 0 deletions src/plugins/intel_gpu/tests/unit/fusions/deconvolution_fusion_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,25 @@ struct deconv_eltw_test_params {
size_t expected_not_fused_primitives;
};

struct deconv_new_shape_infer_test_params {
ov::PartialShape in_shape;
ov::PartialShape out_shape;
ov::PartialShape kernel;
ov::Strides stride;
ov::CoordinateDiff pad;
ov::Strides dilation;
uint32_t groups;
data_types data_type;
format input_format;
data_types weights_type;
format weights_format;
data_types default_type;
format default_format;
size_t expected_fused_primitives;
size_t expected_fused_primitives_onednn;
size_t expected_not_fused_primitives;
};

class DeconvolutionFusingTest : public ::BaseFusingTest<deconv_test_params> {
public:
void execute(deconv_test_params& p, bool is_caching_test = false) {
Expand Down Expand Up @@ -94,6 +113,60 @@ class DeconvolutionFusingTest : public ::BaseFusingTest<deconv_test_params> {
}
};

class DeconvolutionFusingNewShapeInferTest : public ::BaseFusingTest<deconv_new_shape_infer_test_params> {
public:
void SetUp() override {
rg.set_seed(GET_SUITE_NAME);
cfg_fused = get_test_default_config(engine);
cfg_not_fused = get_test_default_config(engine);

cfg_fused.set_property(ov::intel_gpu::optimize_data(true));
cfg_fused.set_property(ov::intel_gpu::allow_new_shape_infer(true));
cfg_not_fused.set_property(ov::intel_gpu::optimize_data(false));
cfg_not_fused.set_property(ov::intel_gpu::allow_new_shape_infer(true));
cfg_not_fused.set_property(ov::intel_gpu::allow_static_input_reorder(true));
}

void execute(deconv_new_shape_infer_test_params& p, bool is_caching_test = false) {
execute(p, get_mem(get_input_layout(p)), is_caching_test);
}
void execute(deconv_new_shape_infer_test_params& p, cldnn::memory::ptr input_prim, bool is_caching_test = false) {
if (engine.get_device_info().supports_immad)
p.expected_fused_primitives = p.expected_fused_primitives_onednn;

network::ptr network_not_fused = get_network(this->engine, this->topology_non_fused, cfg_not_fused, get_test_stream_ptr(cfg_not_fused), is_caching_test);
network::ptr network_fused = get_network(this->engine, this->topology_fused, cfg_fused, get_test_stream_ptr(cfg_fused), is_caching_test);
network_fused->set_input_data("input", input_prim);
network_not_fused->set_input_data("input", input_prim);

compare(*network_not_fused, *network_fused, p);
auto find_conv = [](primitive_info& p) -> bool {
if (p.original_id == "deconv")
return true;
return false;
};

auto pi_fused = network_fused->get_primitives_info();
auto info_fused = std::find_if(pi_fused.begin(), pi_fused.end(), find_conv);
if (info_fused != pi_fused.end())
std::cout << "kernel: " << info_fused->kernel_id << std::endl;
}

layout get_input_layout(deconv_new_shape_infer_test_params& p) {
auto pad = p.pad;
std::vector<int> pad_ = { 0, 0, static_cast<int>(pad[0]) };
return layout{ p.in_shape, p.data_type, p.input_format, padding{ pad_ } };
}

layout get_weights_layout(deconv_new_shape_infer_test_params& p) {
return layout{ p.kernel, p.weights_type, p.weights_format };
}

layout get_bias_layout(deconv_new_shape_infer_test_params& p) {
return layout{ ov::PartialShape{1, static_cast<int64_t>(p.out_shape.get_shape().at(1)), 1}, p.default_type, format::bfyx };
}
};

class ConvEltwTest : public ::BaseFusingTest<deconv_eltw_test_params> {
public:

Expand Down Expand Up @@ -147,6 +220,9 @@ class ConvEltwTest : public ::BaseFusingTest<deconv_eltw_test_params> {
#define CASE_DECONV_FP32_7 { 1, 16, 4, 5 }, { 1, 32, 7, 9 }, { 1, 1, 1, 1 }, { 2, 2 }, { 0, 0 }, { 1, 1 }, 1, data_types::f32, format::b_fs_yx_fsv16, data_types::f32, format::is_os_yx_isv16_osv16, data_types::f32, format::bfyx
#define CASE_DECONV_FP32_8 { 1, 32, 4, 5 }, { 1, 32, 7, 9 }, { 1, 1, 3, 3 }, { 2, 2 }, { 1, 1 }, { 1, 1 }, 32, data_types::f32, format::b_fs_yx_fsv16, data_types::f32, format::gs_oiyx_gsv16, data_types::f32, format::bfyx

// 1D deconv
#define CASE_DECONV_1D_FP32_1 { 1, 512, 1500 }, { 1, 256, 12008 }, { 256, 512, 16 }, { 8 }, { 0 }, { 1 }, 1, data_types::f32, format::bfyx, data_types::f32, format::oiyx, data_types::f32, format::bfyx

#define CASE_DECONV_FP16_1 { 1, 15, 4, 5 }, { 1, 30, 6, 7 }, { 1, 1, 3, 3 }, { 1, 1 }, { 0, 0 }, { 1, 1 }, 1, data_types::f16, format::bfyx, data_types::f16, format::oiyx, data_types::f16, format::bfyx
#define CASE_DECONV_FP16_2 { 1, 16, 4, 5 }, { 1, 32, 6, 7 }, { 1, 1, 3, 3 }, { 1, 1 }, { 0, 0 }, { 1, 1 }, 1, data_types::f16, format::b_fs_yx_fsv16, data_types::f16, format::is_os_yx_isv16_osv16, data_types::f16, format::bfyx
#define CASE_DECONV_FP16_3 { 1, 16, 4, 5 }, { 1, 32, 4, 5 }, { 1, 1, 1, 1 }, { 1, 1 }, { 0, 0 }, { 1, 1 }, 1, data_types::f16, format::b_fs_yx_fsv16, data_types::f16, format::is_os_yx_isv16_osv16, data_types::f16, format::bfyx
Expand Down Expand Up @@ -390,6 +466,33 @@ INSTANTIATE_TEST_SUITE_P(fusings_gpu, deconv_bias, ::testing::ValuesIn(std::vect
deconv_test_params{ CASE_DECONV_S8S8_3D_3, 2, 2, 3 },
}));

class deconv_bias_1d : public DeconvolutionFusingNewShapeInferTest {};
TEST_P(deconv_bias_1d, basic) {
auto p = GetParam();
create_topologies(
input_layout("input", get_input_layout(p)),
data("weights", get_mem(get_weights_layout(p))),
data("bias", get_mem(get_bias_layout(p))),
deconvolution("deconv", input_info("input"), { "weights" }, p.groups, p.stride, p.pad, p.dilation),
eltwise("bias_add", { input_info("deconv"), input_info("bias") }, eltwise_mode::sum),
reorder("out", input_info("bias_add"), p.default_format, data_types::f32)
);

if (engine.get_device_info().supports_immad &&
p.default_type == data_types::f16 &&
p.weights_format == format::is_os_yx_isv16_osv16) {
GTEST_SKIP(); // Issue: 94154
}

// Need much higher tolerance because of deconvolution -> convolution optimization
tolerance = 1.f;
execute(p);
}

INSTANTIATE_TEST_SUITE_P(fusings_gpu, deconv_bias_1d, ::testing::ValuesIn(std::vector<deconv_new_shape_infer_test_params>{
deconv_new_shape_infer_test_params{ CASE_DECONV_1D_FP32_1, 2, 2, 3 },
}));

class deconv_scale : public DeconvolutionFusingTest {};
TEST_P(deconv_scale, basic) {
auto p = GetParam();
Expand Down

0 comments on commit 3364d95

Please sign in to comment.