-
Notifications
You must be signed in to change notification settings - Fork 2k
[CuTeDSL] Allow reassoc fastmath flag on vector reduction ops
#3384
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| # SPDX-FileCopyrightText: Copyright (c) 2025 - 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
| # SPDX-License-Identifier: LicenseRef-NvidiaProprietary | ||
| # | ||
| # Use of this software is governed by the terms and conditions of the | ||
| # NVIDIA End User License Agreement (EULA), available at: | ||
| # https://docs.nvidia.com/cutlass/latest/media/docs/pythonDSL/license.html | ||
| # | ||
| # Any use, reproduction, disclosure, or distribution of this software | ||
| # and related documentation outside the scope permitted by the EULA | ||
| # is strictly prohibited. | ||
|
|
||
| """ | ||
| Unit test for the ``fastmath`` parameter on ``Vector.reduce``. | ||
| """ | ||
|
|
||
| import unittest | ||
|
|
||
| from cutlass._mlir import ir | ||
| from cutlass._mlir.dialects import arith, func | ||
| from cutlass._mlir_helpers.vector import Vector | ||
|
|
||
|
|
||
| def _reduce_ir(fastmath=None): | ||
| """Return the IR for a ``Vector.reduce("add")`` over ``vector<16xf32>``.""" | ||
| with ir.Context(), ir.Location.unknown(): | ||
| 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], [])) | ||
| with ir.InsertionPoint(fn.add_entry_block()): | ||
| Vector(fn.arguments[0]).reduce("add", fastmath=fastmath) | ||
| func.ReturnOp([]) | ||
| module.operation.verify() | ||
| return str(module) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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?
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sure thing, thanks! |
||
|
|
||
|
|
||
| class TestVectorReduceFastmath(unittest.TestCase): | ||
| def test_fastmath_flag(self): | ||
| self.assertIn("fastmath<reassoc>", _reduce_ir(arith.FastMathFlags.reassoc)) | ||
| self.assertNotIn("reassoc", _reduce_ir()) | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| unittest.main() | ||
There was a problem hiding this comment.
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?