Skip to content

Commit 42d5031

Browse files
committed
fix reshape with block_local_data input
1 parent 2281e69 commit 42d5031

1 file changed

Lines changed: 13 additions & 1 deletion

File tree

modules/Nncase.Modules.NTT/Passes/NTTTIRSelectionPass.cs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,19 @@ private Expr GenerateReshape(Expr input, ref Expr output, bool sequeeze = false)
246246
// If the size is not same, we cannot bitcast.
247247
if ((inBuffer.MemSpan.Size == outBuffer.MemSpan.Size) && (bitcast || sequeeze))
248248
{
249-
output = inBuffer.With(name: outBuffer.Name, elemType: outBuffer.ElemType, dimensions: outBuffer.Dimensions.ToArray(), strides: outBuffer.Strides.ToArray(), distributedType: outBuffer.DistributedType);
249+
var newStrides = outBuffer.Strides.ToArray();
250+
if (inBuffer.MemSpan.Buffer.Location == MemoryLocation.BlockLocalData && bitcast)
251+
{
252+
var outType = outBuffer.DistributedType!;
253+
var threadAxis = outType.Placement.Rank - 1;
254+
int splitAxis = outType.AxisPolicies.ToArray().IndexOf(x => x is SBPSplit split && split.Axes.Contains(threadAxis));
255+
if (splitAxis >= 0)
256+
{
257+
Enumerable.Range(0, splitAxis).ToArray().ForEach(i => newStrides[i] *= outType.Placement.Hierarchy[threadAxis]);
258+
}
259+
}
260+
261+
output = inBuffer.With(name: outBuffer.Name, elemType: outBuffer.ElemType, dimensions: outBuffer.Dimensions.ToArray(), strides: newStrides, distributedType: outBuffer.DistributedType);
250262
return T.Nop();
251263
}
252264
else

0 commit comments

Comments
 (0)