@@ -264,8 +264,8 @@ TEST_F(VulkanComputeAPITest, virtual_transpose_test) {
264264 // (dim0, dim1), new_sizes, new_dim_order, new_axis_map, new_packed_dim_idx
265265 std::vector<std::vector<std::vector<int64_t >>> test_cases = {
266266 {{2 , 3 }, {7 , 9 , 13 , 11 }, {0 , 1 , 3 , 2 }, {1 , 0 , 2 , 2 }, {1 }},
267- {{2 , 1 }, {7 , 11 , 9 , 13 }, {0 , 2 , 1 , 3 }, {0 , 2 , 1 , 2 }, {0 }},
268- {{1 , 3 }, {7 , 13 , 11 , 9 }, {0 , 3 , 2 , 1 }, {2 , 1 , 0 , 2 }, {2 }},
267+ {{2 , 1 }, {7 , 11 , 9 , 13 }, {0 , 2 , 1 , 3 }, {0 , 2 , 1 , 1 }, {0 }},
268+ {{1 , 3 }, {7 , 13 , 11 , 9 }, {0 , 3 , 2 , 1 }, {2 , 1 , 0 , 0 }, {2 }},
269269 };
270270
271271 for (const auto & test_case : test_cases) {
@@ -3039,3 +3039,94 @@ TEST(VulkanComputeGraphOpsTest, int4pack_mm_test) {
30393039 test_int4pack_mm ({37 , 256 , 19 }, 64 , storage_type);
30403040 }
30413041}
3042+
3043+ void test_transpose_view_mm (
3044+ const int B,
3045+ const int M,
3046+ const int K,
3047+ const int N,
3048+ utils::StorageType storage_type) {
3049+ GraphConfig config;
3050+ config.set_storage_type_override (storage_type);
3051+ ComputeGraph graph (config);
3052+
3053+ std::vector<int64_t > mat1_size = {M, K};
3054+ std::vector<int64_t > mat2_t_size = {N, K};
3055+ std::vector<int64_t > out_size = {M, N};
3056+
3057+ std::vector<int64_t > mat1_small_size = {M - 4 , K - 3 };
3058+ std::vector<int64_t > mat2_t_small_size = {N - 1 , K - 3 };
3059+
3060+ if (B > 1 ) {
3061+ mat1_size.resize (3 );
3062+ mat1_size = {B, M, K};
3063+ mat2_t_size.resize (3 );
3064+ mat2_t_size = {B, N, K};
3065+ out_size.resize (3 );
3066+ out_size = {B, M, N};
3067+
3068+ mat1_small_size.resize (3 );
3069+ mat1_small_size = {B, M - 4 , K - 3 };
3070+ mat2_t_small_size.resize (3 );
3071+ mat2_t_small_size = {B, N - 1 , K - 3 };
3072+ }
3073+
3074+ // Build graph
3075+
3076+ IOValueRef mat1 =
3077+ graph.add_input_tensor (mat1_size, vkapi::kFloat , utils::kWidthPacked );
3078+ IOValueRef mat2_transpose =
3079+ graph.add_input_tensor (mat2_t_size, vkapi::kFloat , utils::kWidthPacked );
3080+
3081+ ValueRef mat2 = graph.add_tensor_view (mat2_transpose.value );
3082+
3083+ ValueRef dim0;
3084+ ValueRef dim1;
3085+
3086+ if (B > 1 ) {
3087+ dim0 = graph.add_scalar <int64_t >(1 );
3088+ dim1 = graph.add_scalar <int64_t >(2 );
3089+ } else {
3090+ dim0 = graph.add_scalar <int64_t >(0 );
3091+ dim1 = graph.add_scalar <int64_t >(1 );
3092+ }
3093+
3094+ IOValueRef out;
3095+ out.value = graph.add_tensor (out_size, vkapi::kFloat , utils::kWidthPacked );
3096+
3097+ VK_GET_OP_FN (" aten.transpose.int" )
3098+ (graph, {mat2_transpose.value , dim0, dim1, mat2});
3099+ VK_GET_OP_FN (" aten.mm.default" )(graph, {mat1.value , mat2, out.value });
3100+
3101+ out.staging = graph.set_output_tensor (out.value );
3102+
3103+ graph.prepare ();
3104+ graph.encode_prepack ();
3105+ graph.prepack ();
3106+ graph.encode_execute ();
3107+
3108+ for (int i = 1 ; i < 4 ; i++) {
3109+ float val_mat1 = i;
3110+ float val_mat2 = i + 1 ;
3111+ float val_out = K * (val_mat1 * val_mat2);
3112+
3113+ // Try at full size
3114+ graph.resize_input (0 , mat1_size);
3115+ graph.resize_input (1 , mat2_t_size);
3116+ graph.propagate_resize ();
3117+ execute_graph_and_check_output (graph, {val_mat1, val_mat2}, {val_out});
3118+
3119+ // Try at reduced sizes
3120+ val_out = (K - 3 ) * (val_mat1 * val_mat2);
3121+ graph.resize_input (0 , mat1_small_size);
3122+ graph.resize_input (1 , mat2_t_small_size);
3123+ graph.propagate_resize ();
3124+ execute_graph_and_check_output (graph, {val_mat1, val_mat2}, {val_out});
3125+ }
3126+ }
3127+
3128+ TEST (VulkanComputeGraphOpsTest, test_transpose_with_mm) {
3129+ for (auto storage_type : {utils::kBuffer , utils::kTexture3D }) {
3130+ test_transpose_view_mm (2 , 7 , 17 , 5 , storage_type);
3131+ }
3132+ }
0 commit comments