@@ -2055,6 +2055,79 @@ class joint_matrix {
20552055 matrix_accessor x;
20562056 const size_t num_elements;
20572057};
2058+
2059+ // / Multiplies 2 16x16 & 16x8 matrices and accumulates the result to a 16x8 b32
2060+ // / matrix
2061+ // / \tparam [in] MulType The type of the multiplication result
2062+ // / \tparam [in] ABType The type of the input matrices
2063+ // / \tparam [in] CDType The type of the output matrix
2064+ // / \tparam [in] ItemT The type of the sycl::nd_item index space class
2065+ // / \param [in] d0 The 1st element to be written to the output D matrix
2066+ // / \param [in] d1 The 2nd element to be written to the output D matrix
2067+ // / \param [in] d2 The 3rd element to be written to the output D matrix
2068+ // / \param [in] d3 The 4th element to be written to the output D matrix
2069+ // / \param [in] a0 The 1st element from A matrix to be multiplied with B matrix
2070+ // / \param [in] a1 The 2nd element from A matrix to be multiplied with B matrix
2071+ // / \param [in] a2 The 3rd element from A matrix to be multiplied with B matrix
2072+ // / \param [in] a3 The 4th element from A matrix to be multiplied with B matrix
2073+ // / \param [in] b0 The 1st element from B matrix to be multiplied with A matrix
2074+ // / \param [in] b1 The 2nd element from B matrix to be multiplied with A matrix
2075+ // / \param [in] c0 The 1st element from C matrix to be added with d0
2076+ // / \param [in] c1 The 2nd element from C matrix to be added with d1
2077+ // / \param [in] c2 The 3rd element from C matrix to be added with d2
2078+ // / \param [in] c3 The 4th element from C matrix to be added with d3
2079+ // / \param [in] item The sycl::nd_item index space class
2080+ template <typename MulType, typename ABType, typename CDType, typename ItemT>
2081+ __attribute__ ((optnone)) void
2082+ mma (CDType *d0, CDType *d1, CDType *d2, CDType *d3, ABType a0, ABType a1,
2083+ ABType a2, ABType a3, ABType b0, ABType b1, CDType c0, CDType c1, CDType c2,
2084+ CDType c3, const ItemT &item) {
2085+ int lane = item.get_sub_group ().get_local_linear_id ();
2086+
2087+ short ROW_LOAD_OFFSET = 4 * (lane / 4 );
2088+ short COL_LOAD_OFFSET = 8 * (lane % 4 );
2089+
2090+ ABType recv_a[4 * 4 ], recv_b[4 * 4 ];
2091+ for (int i = 0 ; i < 4 ; i++) {
2092+ recv_a[0 * 4 + i] = dpct::select_from_sub_group (item.get_sub_group (), a0,
2093+ ROW_LOAD_OFFSET + i);
2094+ recv_a[1 * 4 + i] = dpct::select_from_sub_group (item.get_sub_group (), a2,
2095+ ROW_LOAD_OFFSET + i);
2096+ recv_a[2 * 4 + i] = dpct::select_from_sub_group (item.get_sub_group (), a1,
2097+ ROW_LOAD_OFFSET + i);
2098+ recv_a[3 * 4 + i] = dpct::select_from_sub_group (item.get_sub_group (), a3,
2099+ ROW_LOAD_OFFSET + i);
2100+
2101+ recv_b[0 * 4 + i] = dpct::select_from_sub_group (item.get_sub_group (), b0,
2102+ COL_LOAD_OFFSET + i);
2103+ recv_b[1 * 4 + i] = dpct::select_from_sub_group (item.get_sub_group (), b1,
2104+ COL_LOAD_OFFSET + i);
2105+ recv_b[2 * 4 + i] = dpct::select_from_sub_group (item.get_sub_group (), b0,
2106+ COL_LOAD_OFFSET + 4 + i);
2107+ recv_b[3 * 4 + i] = dpct::select_from_sub_group (item.get_sub_group (), b1,
2108+ COL_LOAD_OFFSET + 4 + i);
2109+ }
2110+
2111+ auto *a = reinterpret_cast <MulType *>(recv_a);
2112+ auto *b = reinterpret_cast <MulType *>(recv_b);
2113+ for (int i = 0 ; i < 16 ; i++) {
2114+ auto a0 = static_cast <CDType>(a[i]);
2115+ auto a1 = static_cast <CDType>(a[i + 16 ]);
2116+ auto b0 = static_cast <CDType>(b[i]);
2117+ auto b1 = static_cast <CDType>(b[i + 16 ]);
2118+
2119+ c0 += a0 * b0;
2120+ c1 += a0 * b1;
2121+ c2 += a1 * b0;
2122+ c3 += a1 * b1;
2123+ }
2124+
2125+ *d0 = c0;
2126+ *d1 = c1;
2127+ *d2 = c2;
2128+ *d3 = c3;
2129+ }
2130+
20582131} // namespace matrix
20592132} // namespace experimental
20602133
0 commit comments