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

[Calyx] Binary Floating Point MulF Operator #7769

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

jiahanxie353
Copy link
Contributor

Add support for floating point multiplication in Calyx

@rachitnigam
Copy link
Contributor

Okay, I think we should move the floating point operators into their own separate definition because they are so much more complicated. Can we get the syntax: calyx.ieee754.add and calyx.ieee754.mul working instead of adding the floating-point operations directly into the same namespace as everything else?

@jiahanxie353
Copy link
Contributor Author

marking ready for review again!


module attributes {calyx.entrypoint = "main"} {
// CHECK: import "primitives/float/mulFN.futil";
calyx.component @main(%in0: i32, %clk: i1 {clk}, %reset: i1 {reset}, %go: i1 {go}) -> (%out0: i32, %done: i1 {done}) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Please add a CHECK-NEXT: for this line.

wait it is added here right? I believe you are looking for std_mulFN_0 = std_mulFN(8, 24, 32)?

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah, can this not use CHECK-NEXT since we know exactly which line produces the primitive?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

you mean we don't need to check std_mulFN_0 = std_mulFN(8, 24, 32) at all?

Copy link
Contributor

Choose a reason for hiding this comment

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

No, can we ensure that the code is generated precisely as a consequence of that one line?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sounds good, I'm updating to CHECK-DAG to ensure your request of checking the code is generated by the correct line sequentially; as well as avoiding checking some boilerplate code that will be otherwise generated by CHECK-NEXT. Please let me know if it makes sense.

Copy link
Member

@cgyurgyik cgyurgyik left a comment

Choose a reason for hiding this comment

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

A few smaller comments.

@@ -424,6 +424,10 @@ class ComponentLoweringStateInterface {
Block *body = component.getBodyBlock();
builder.setInsertionPoint(body, body->begin());
auto name = TLibraryOp::getOperationName().split(".").second;
if (std::is_same<calyx::AddFNOp, TLibraryOp>::value)
name = "std_addFN";
Copy link
Member

Choose a reason for hiding this comment

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

Nit: isn't the better way to do this is remove the .ieee754 prefix for any F operations?

Copy link
Contributor Author

@jiahanxie353 jiahanxie353 Nov 13, 2024

Choose a reason for hiding this comment

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

The entire prefix + name is calyx.ieee754.add/calyx.ieee754.mul, removing ieee754 will simply become add/mul; but we want std_addFN/std_mulFN after emitting to Calyx native compiler.

Copy link
Member

Choose a reason for hiding this comment

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

More concretely, I think there is a better way to do this than manually write a new if statement for each floating point operation. It'd be nice to avoid this every time:

if (std::is_same<calyx::<MyNewFloatingPointOp, TLibraryOP>::value)
  name = "std_MyNewFloatingPointOp";

Ideally, since we're already distinguishing them without a _std prefix, we could infer this is some floating point operation, and then check what standard it conforms too.

/// Returns the technical floating point this operation conforms to, e.g., "ieee754"
/// (This should probably be an enum, which is subsequently converted to a string.)
std::string standard() { ... }

if (auto fOp = dyn_cast<FloatingPointOp>(op)):
  name.remove(llvm::join(".", fOp.standard()));
  name.prepend("std_");

(I'm not saying you should spend a lot of time doing this, it is a mere suggestion. In general, I do think the conforming technical standard of a floating point operation should be a field of the op so it can referenced during pattern rewrites.)

Copy link
Contributor Author

@jiahanxie353 jiahanxie353 Nov 14, 2024

Choose a reason for hiding this comment

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

I've thought about this, I don't think it's worth it now.
In the foreseeable future, only IEEE754 floating point is integrated; and moreover, only Add and Mul are present in the Berkeley HardFloat.
My opinion is we can address future needs and refactor the code when there is an actual, concrete need.
But I totally get what you are saying.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sorry, let me take it back.
When doing some research on the floating point comparison issue #7821, I found Berkeley HardFloat has division, square root, and comparisons as well.
So I definitely need to use a better design to incorporate all of these calyx::FloatingPointOps, as you suggested.

@@ -1019,11 +1024,15 @@ void Emitter::emitLibraryFloatingPoint(Operation *op) {
return;
}

StringRef opName = op->getName().getStringRef();
std::string opName;
if (isa<calyx::AddFNOp>(op))
Copy link
Member

Choose a reason for hiding this comment

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

Same here.

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

Successfully merging this pull request may close these issues.

4 participants