@@ -114,7 +114,9 @@ CUTE_DEVICE void qmm_naive_mainloop(
114114 gB .data () = recast_ptr<Quant>(raw_pointer_cast (gB .data ()) + gB .layout ()(0 , k_residue, 0 ) * cuda::std::min (8 , sizeof_bits_v<Quant>) / 8 );
115115 }
116116 gS = domain_offset (make_coord (0 , k_residue, 0 ), gS );
117- gZ = domain_offset (make_coord (0 , k_residue, 0 ), gZ );
117+ if constexpr (quant_has_bias_v<Quant>) {
118+ gZ = domain_offset (make_coord (0 , k_residue, 0 ), gZ );
119+ }
118120
119121 // Define smem layouts.
120122 auto [sA_layout , sB_layout ] = make_smem_layouts (cta_tiler);
@@ -177,8 +179,15 @@ CUTE_DEVICE void qmm_naive_mainloop(
177179 auto fetch_gmem = [&](int tile) {
178180 copy_if (copy_a, tApA, tAgA (_,_,_,tile), tArA);
179181 copy_if (copy_b, tBpB, tBgB (_,_,_,tile), tBrB);
180- copy (tBgS (_,_,_,tile), tBrS);
181- copy (tBgZ (_,_,_,tile), tBrZ);
182+ CUTE_UNROLL
183+ for (int n = 0 ; n < size<1 >(tBrS); ++n) {
184+ if (tBpB (n,0 )) {
185+ copy (tBgS (_,n,_,tile), tBrS (_,n,_));
186+ if constexpr (quant_has_bias_v<Quant>) {
187+ copy (tBgZ (_,n,_,tile), tBrZ (_,n,_));
188+ }
189+ }
190+ }
182191 };
183192 // RMEM => SMEM.
184193 auto store_smem = [&]() {
@@ -219,8 +228,15 @@ CUTE_DEVICE void qmm_naive_mainloop(
219228 for (int k = 0 ; k < size<2 >(tBrB); ++k) {
220229 if (get<1 >(tBcB (0 ,0 ,k)) >= -k_residue) {
221230 copy_if (copy_b, tBpB (_,k), tBgB_k (_,_,k), tBrB (_,_,k));
222- copy (tBgS_k (_,_,k), tBrS (_,_,k));
223- copy (tBgZ_k (_,_,k), tBrZ (_,_,k));
231+ CUTE_UNROLL
232+ for (int n = 0 ; n < size<1 >(tBrS); ++n) {
233+ if (tBpB (n,k)) {
234+ copy (tBgS_k (_,n,k), tBrS (_,n,k));
235+ if constexpr (quant_has_bias_v<Quant>) {
236+ copy (tBgZ_k (_,n,k), tBrZ (_,n,k));
237+ }
238+ }
239+ }
224240 }
225241 }
226242 } else {
0 commit comments