4848from tensorforge .backend .pir .core import SCALAR_LAYOUT , ScalarType , join_layout
4949from tensorforge .common .basic_types import Datatype
5050from tensorforge .common .exceptions import InternalError
51- from .. import broadcast , ranking , split
51+ from .. import broadcast , ranking , rowpack , split
5252from . import intel_spmd
5353from ..bitlayout import packed
5454from ..routes import lead_route
@@ -188,6 +188,25 @@ def enabled(ctx) -> bool:
188188 return ENABLED if asked is None else bool (asked )
189189
190190
191+ def moves_refused (ctx ) -> bool :
192+ """Whether this build moves its transfers ahead
193+ (`Options.enable_move_loads`) under the explicit vector, where DPAS is
194+ then not taken (`strategies`, `prepared_order`).
195+
196+ With the transfers moved, SeisSol's elastic volume at order 6 in single
197+ precision came out wrong on the CPU emulator (tfemu) against NumPy: nine
198+ of its 576 outputs, the ninth quantity's rows 10 to 15, up to 18 % off.
199+ Right with the moves off; right with only the wrap across the back edge
200+ (`Options.enable_wrap_loads`) left on; and each of its three products
201+ alone, and any two of them, right with the moves on. Until that
202+ interaction is found, DPAS under the explicit vector needs
203+ `enable_move_loads=0`. Nothing changes where the path is off, which is
204+ the default."""
205+ if ctx is None or not _simd_mode (ctx ):
206+ return False
207+ return bool (ctx .get_user_options ().enable_move_loads )
208+
209+
191210# --------------------------------------------------------------------------- #
192211# Where an element sits in a fragment
193212# --------------------------------------------------------------------------- #
@@ -786,16 +805,26 @@ def prepared_order(shape, dtype, ctx, columns=0, lead=0, depth=0,
786805 rows , cols = (int (x ) for x in shape )
787806 # The question `strategies` answers for MATRIX, which `ORDER` takes first
788807 # wherever it is offered.
789- dpas = enabled (ctx ) and atom_for ( dtype , columns = columns , lead = lead ,
790- depth = depth ,
791- budget = register_budget (ctx )) is not None
808+ dpas = ( enabled (ctx ) and not moves_refused ( ctx )
809+ and atom_for ( dtype , columns = columns , lead = lead , depth = depth ,
810+ budget = register_budget (ctx )) is not None )
792811 block = ATOMS ['tf32' ].k if dpas else 1
793812 padded = - (- cols // block ) * block
794813 return SlotMajorOrder (slot_major_order ((rows , cols ), threads , padded ),
795814 threads , padded ,
796815 parts = TF32_SPLIT_TERMS if dpas else 1 )
797816
798817
818+ def surface_order (order , ctx ):
819+ """An operator copy's tiles as a 2D surface (`MatrixPaths.surface_order`):
820+ the SPMD lowering's DPAS reads one so where asked
821+ (`intel_spmd.surface_order`, `Options.sycl_dpas_block2d`); the explicit
822+ vector reads none."""
823+ if ctx is None or _simd_mode (ctx ):
824+ return None
825+ return intel_spmd .surface_order (order , ctx )
826+
827+
799828def widths (threads , accumulator , ctx ):
800829 """None offered (`MatrixPaths.widths`): `Options.matrix_columns` is read
801830 by CDNA's lane-batched tiles alone, and the atom here is the count's
@@ -832,7 +861,8 @@ def strategies(shape, ctx):
832861
833862 `dpas_matmul`, too, only under the explicitly vectorized lowering: it
834863 emits `esimd::xmx::dpas` over `simd` fragments, which an SPMD kernel
835- cannot call. The SPMD lowering reaches the instruction another way, the
864+ cannot call -- and not while the build moves its transfers ahead
865+ (`moves_refused`). The SPMD lowering reaches the instruction another way, the
836866 OpenCL builtin over a sub-group of sixteen, whose fragments are spread
837867 over the work-items as the lowering spreads its rows (`intel_spmd`,
838868 `Options.sycl_dpas`); that path answers for SPMD alone, and only where
@@ -853,13 +883,27 @@ def strategies(shape, ctx):
853883 if not supports (shape .threads , shape .accumulator , shape .sparse ):
854884 return frozenset ()
855885 offered = set ()
856- if enabled (ctx ) and shape .explicit_simd and not shape .sparse :
886+ if (enabled (ctx ) and shape .explicit_simd and not shape .sparse
887+ and not moves_refused (ctx )):
857888 offered .add (Strategy .MATRIX )
858889 if BROADCAST_ENABLED and shape .explicit_simd and not shape .sparse :
859890 offered .add (Strategy .BROADCAST )
860891 return frozenset (offered )
861892
862893
894+ def row_caps (shape , n , ctx ):
895+ """What the matrix path does with a product's `n` columns past its
896+ last whole tile (`MatrixPaths.row_caps`, `Options.row_packing`): the
897+ SPMD lowering's DPAS carries or pads them (`intel_spmd.row_caps`);
898+ the explicit vector's pads them, its second `j0` block a tile of
899+ eight rows of which the remainder fills one (`dpas_matmul`)."""
900+ if not _simd_mode (ctx ):
901+ return intel_spmd .row_caps (n )
902+ height = ATOMS ['tf32' ].repeat
903+ return rowpack .RowCaps (height , frozenset ({rowpack .Packing .PAD }),
904+ rowpack .Packing .PAD )
905+
906+
863907def plan (strategy , shape , n , ctx ):
864908 """One arrangement over the whole output.
865909
@@ -907,6 +951,9 @@ def matmul(writer, ops, ctx, span):
907951 # caller that does should hear so rather than get the whole output.
908952 return False
909953 if span .strategy is Strategy .MATRIX :
954+ # Only the padded remainder here (`row_caps`): anything else asked
955+ # stops generation with what this path has.
956+ rowpack .plan_rows (N , row_caps (None , N , ctx ), ctx )
910957 if Datatype .F32 not in (ops .a , ops .b ) or ops .a != ops .b :
911958 # `splitFloatTF32` takes an F32 apart; handed anything else it
912959 # would produce two halves of a number it never had. The atom is
0 commit comments