@@ -746,15 +746,28 @@ def make_weight_file(self, weights, weight_file_mode, weight_file_name):
746746 # AXI-MM / fetch_weights path (MLO and external_mem): external memory
747747 # (DDR, HBM, ...) holds one IWSIMD group per DWC output beat, each
748748 # byte-aligned to DS_BITS_BA = roundup(IWSIMD*bitwidth, 8) bits. IWSIMD
749- # is (PE*SIMD)/TH for TH>1, SIMD otherwise. The within-group ordering
750- # must match the memstreamer (PE-flipped, TH sub-tile order undone):
751- # unflipped would swap PE lanes when IWSIMD*bitwidth <= 8 packs several
752- # PEs into one byte. For TH>1 weight_tensor_pe_flipped is already in
753- # IWSIMD-sized chunks (tinner == (PE*SIMD)/TH == IWSIMD).
749+ # is (PE*SIMD)/TH for TH>1, SIMD otherwise.
750+ #
751+ # The within-group ordering depends on how fetch_weights delivers the
752+ # stream to the MVU:
753+ # - TH>1 (tiled MVAU): the stream passes straight through to the tiled
754+ # MVU, which expects the PE-flipped, TH-sub-tile-undone ordering.
755+ # weight_tensor_pe_flipped is already in IWSIMD-sized chunks
756+ # (tinner == (PE*SIMD)/TH == IWSIMD).
757+ # - TH=1 (standard MVAU): the stream goes through local_weight_buffer,
758+ # which distributes consecutive SIMD groups across PE lanes 0..PE-1
759+ # (pe-minor) and pairs weight SIMD lane s with activation SIMD lane s.
760+ # That reconstruction needs the natural (unflipped) PE/SIMD order:
761+ # PE-flipping reverses the PE lanes and SIMD-flipping scrambles the
762+ # dot product.
754763 th = self .get_nodeattr ("TH" )
755764 iwsimd = (pe * simd ) // th if th > 1 else simd
756765 iwsimd_group_bits = roundup_to_integer_multiple (iwsimd * export_wdt .bitwidth (), 8 )
757- weight_tensor_iwsimd_groups = weight_tensor_pe_flipped .reshape (1 , - 1 , iwsimd )
766+ if th > 1 :
767+ weight_tensor_iwsimd = weight_tensor_pe_flipped
768+ else :
769+ weight_tensor_iwsimd = weight_tensor_unflipped .reshape (1 , - 1 , pe * simd ).copy ()
770+ weight_tensor_iwsimd_groups = weight_tensor_iwsimd .reshape (1 , - 1 , iwsimd )
758771 weight_tensor_iwsimd_groups = pack_innermost_dim_as_hex_string (
759772 weight_tensor_iwsimd_groups , export_wdt , iwsimd_group_bits , prefix = ""
760773 )
0 commit comments