Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PDL patterns #279

Open
giuseros opened this issue Feb 17, 2022 · 1 comment
Open

PDL patterns #279

giuseros opened this issue Feb 17, 2022 · 1 comment

Comments

@giuseros
Copy link
Collaborator

Hi all,
I am trying to use the PDL patterns to double tile a generic matmul-like operation:

def add_matmul_schedule(module):
  dimM, dimN, dimK = [0, 0], [1, 1], [0, 1]
  isa_linalg_matmul = match_op_with_dynamic_or_static_sizes(
      module,
      equivalent_op_name='linalg.matmul',
      dynamic_spec_list=['d', 'd', 'd'],
      op_dim_spec_list=[dimM, dimN, dimK])
  
  with InsertionPoint(module.body):
    sequence = transform.SequenceOp()
    with ir.InsertionPoint(sequence.body.blocks[0]):
      matched = transform.MatchOp(isa_linalg_matmul)
      tiled = transform.TileOp(matched, sizes=[128, 128, 128], interchange=[0,2,1], pad=False)
      tiled2 = transform.TileOp(tiled, sizes=[8,8,1], interchange=[0,1,2], pad=True, pack_paddings=[1,1,0], hoist_paddings=[4,3,0], transpose_paddings=[[0,1], [0,1], [0,1]])

The second TileOp hits this assertion:

python3: /home/giuseppe/gh_llvm_project/mlir/lib/Dialect/Linalg/Transforms/Transforms.cpp:220: mlir::LogicalResult padOperandToSmallestStaticBoundingBox(mlir::OpBuilder &, linalg::LinalgOp, mlir::OpOperand *, const mlir::linalg::PaddingValueComputationFunction &, const mlir::linalg::PaddingNoFoldComputationFunction &, mlir::Value &): Assertion `staticSizes.size() == shape.size() && "expect the dynamic and static ranks to match"' failed.

While investigating, I was wondering if I am doing the right thing, or something is wrong with my code. @nicolasvasilache is this the way it's supposed to be used?

Thanks,
Giuseppe

@giuseros
Copy link
Collaborator Author

Ok, so I think that the problem was here:

// Handle the sliced out types in a conservative fashion: all dimensions
  // become dynamic and a later canonicalization is expected to recover static
  // types.
  // TODO: should we relax this and use something less strict?

So basically, if I do:

tiled = transform.TileOp(matched, sizes=[128, 128, 128], interchange=[0,2,1], pad=False)
 tiled2 = transform.TileOp(tiled, sizes=[8,8,1], interchange=[0,1,2], pad=False)
padded = transform.TileOp(tiled2, [],  pack_paddings=[1,1,0], hoist_paddings=[4,3,0], transpose_paddings=[[0,1], [0,1], [0,1]]))

Everything seems to work. @nicolasvasilache , naive question: what about having a transform.PadOp operation? Any drawbacks?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant