@@ -533,3 +533,29 @@ TEST_F(test_layout_to_memory_desc, regression_3d_shape_format_selection) {
533533 EXPECT_EQ (get_format_tag_from_desc (desc_byxf), dnnl::memory::format_tag::acb);
534534 // Format tags should be different (abc vs acb)
535535}
536+
537+ TEST_F (test_layout_to_memory_desc, zero_batch_ab_format) {
538+ // batch=0 should not cause division-by-zero; inner dims should be preserved
539+ layout l = layout{ov::PartialShape{0 , 256 }, data_types::f32 , format::bfyx};
540+ auto desc = layout_to_memory_desc (l, dnnl::memory::format_tag::ab);
541+ EXPECT_EQ (desc.get_ndims (), 2 );
542+ EXPECT_EQ (desc.get_dims ()[0 ], 0 );
543+ EXPECT_EQ (desc.get_dims ()[1 ], 256 );
544+ }
545+
546+ TEST_F (test_layout_to_memory_desc, zero_feature_ba_format) {
547+ // feature=0 should not cause division-by-zero; inner dims should be preserved
548+ layout l = layout{ov::PartialShape{256 , 0 }, data_types::f32 , format::bfyx};
549+ auto desc = layout_to_memory_desc (l, dnnl::memory::format_tag::ba);
550+ EXPECT_EQ (desc.get_ndims (), 2 );
551+ EXPECT_EQ (desc.get_dims ()[0 ], 0 );
552+ EXPECT_EQ (desc.get_dims ()[1 ], 256 );
553+ }
554+
555+ TEST_F (test_layout_to_memory_desc, zero_batch_default_format) {
556+ // All-zero batch with default format should not crash
557+ layout l = layout{ov::PartialShape{0 , 64 , 32 , 32 }, data_types::f16 , format::bfyx};
558+ EXPECT_NO_THROW ({
559+ auto desc = layout_to_memory_desc (l, dnnl::memory::format_tag::undef);
560+ });
561+ }
0 commit comments