Skip to content

[CuTeDSL] Allow reassoc fastmath flag on vector reduction ops - #3384

Open
antoniofrighetto wants to merge 2 commits into
NVIDIA:mainfrom
antoniofrighetto:feature/add-fastmath-vector-reduction
Open

[CuTeDSL] Allow reassoc fastmath flag on vector reduction ops#3384
antoniofrighetto wants to merge 2 commits into
NVIDIA:mainfrom
antoniofrighetto:feature/add-fastmath-vector-reduction

Conversation

@antoniofrighetto

Copy link
Copy Markdown

Let Vector.reduce() accept optional fastmath flags (e.g., reassoc), meant to be leveraged by callers during MLIR/LLVM lowering.

Let Vector.reduce() accept optional fastmath flags (e.g., `reassoc`),
meant to be leveraged by callers during MLIR/LLVM lowering.

@brandon-yujie-sun brandon-yujie-sun left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for contributing the codes! LGTM with some minor questions :-)

Comment thread python/CuTeDSL/_mlir_helpers/vector.py Outdated
kind, self, acc=p_acc, reduction_dims=partial_dims, loc=loc, ip=ip
)
raw = vector.reduction(elem_ty, kind, vec_1d, acc=acc, loc=loc, ip=ip)
raw = vector.reduction(elem_ty, kind, vec_1d, acc=acc, **fmf_kwargs, loc=loc, ip=ip)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good, but for the multi_reduction case, shall we raise error to mention it's not supported?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added, thanks. Raising ValueError when handling multi-dimensional reductions earlier (so dropped passing the flag here too; not sure if we somehow meant to only reject partial reductions, and allow passing the flag here).

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the update. LGTM

module = ir.Module.create()
vec_ty = ir.VectorType.get([16], ir.F32Type.get())
with ir.InsertionPoint(module.body):
fn = func.FuncOp("test", ir.FunctionType.get([vec_ty], []))

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we'd also need a func.ReturnOp([]) to make it a real valid func op?

fn = func.FuncOp("test", ir.FunctionType.get([vec_ty], []))
with ir.InsertionPoint(fn.add_entry_block()):
Vector(fn.arguments[0]).reduce("add", fastmath=fastmath)
return str(module)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe do a module.operation.verify() before returning to make sure the constructed op is valid so that the validation on the serialized string would be meaningful?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure thing, thanks!

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

Successfully merging this pull request may close these issues.

2 participants