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

[FIRRTL] Add DPI call intrinsic and lowering pass #7139

Merged
merged 11 commits into from
Jun 13, 2024
Merged

Conversation

uenoku
Copy link
Member

@uenoku uenoku commented Jun 5, 2024

This PR adds DPICallIntrinsicOp and its lowering pass. DPICallIntrinsicOp is lowered into sim.func.dpi.call and sim.func.dpi ops. At FIRRTL level DPICallIntrinsicOp doesn't have symbols and instead LowerDPI pass accumulates callsites and creates symbols for dpi functions. LowerDPI pass directly lowers FIRRTL intrinsic into Sim dialect since FIRRTL doesn't have DPI/Function construct. LowerDPI pass could be simplified (or migrated into LowerToHW) once FIRRTL gets 1st class support for Function. Unrealized conversion cast is used to mix FIRRTL and HW type values before LowerToHW.

@@ -59,7 +59,7 @@ def FatalOp : SimOp<"fatal"> {

def DPIFuncOp : SimOp<"func.dpi",
[IsolatedFromAbove, Symbol, OpAsmOpInterface,
FunctionOpInterface, HasParent<"mlir::ModuleOp">]> {
FunctionOpInterface]> {
Copy link
Member Author

Choose a reason for hiding this comment

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

This is similar change to 09df7f5. It was necessary to put DPI func op into circuit op to make the lowering composable.

lib/Dialect/Sim/SimOps.cpp Outdated Show resolved Hide resolved
| Port | Direction | Type | Description |
| ----------------- | --------- | -------- | ------------------------------- |
| clock (optional) | input | Clock | Optional clock operand |
| enable | input | UInt<1> | Enable signal |
Copy link
Member Author

Choose a reason for hiding this comment

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

enable is not optional at Chisel level to follow the same design as verification intrinsic.

Copy link
Contributor

@dtzSiFive dtzSiFive left a comment

Choose a reason for hiding this comment

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

Generally looks great!!!

Thanks for the comments to point out or explain various things!

Added some feedback, minor nits.

docs/Dialects/FIRRTL/FIRRTLIntrinsics.md Outdated Show resolved Hide resolved
docs/Dialects/FIRRTL/FIRRTLIntrinsics.md Outdated Show resolved Hide resolved
lib/Dialect/FIRRTL/Transforms/LowerDPI.cpp Show resolved Hide resolved
FModuleOp module;
SmallVector<DPICallIntrinsicOp> dpiOps;
};
SmallVector<DpiCallCollections> results;
Copy link
Contributor

Choose a reason for hiding this comment

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

Consider a reserve.

Copy link
Member Author

Choose a reason for hiding this comment

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

Since we cannot know the actual number of FModuleOp beforehand I reserved 64.

Copy link
Contributor

Choose a reason for hiding this comment

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

Probably 64 won't fit on the stack / small size, so maybe make the SmallVector 0-length (or 64?) or whatever seems good. Not blocking, just a stray thought since tab still open :).

test/Dialect/FIRRTL/lower-dpi.mlir Outdated Show resolved Hide resolved
test/Dialect/FIRRTL/lower-dpi.mlir Outdated Show resolved Hide resolved
test/Dialect/FIRRTL/lower-intrinsics.mlir Outdated Show resolved Hide resolved
@@ -0,0 +1,54 @@
; RUN: firtool %s --format=fir | FileCheck %s

FIRRTL version 4.0.0
Copy link
Contributor

Choose a reason for hiding this comment

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

🤩 awesome seeing this end-to-end!!

Copy link
Contributor

@dtzSiFive dtzSiFive left a comment

Choose a reason for hiding this comment

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

LGTM, this is great!!!

Consider adding a small test case for the error re:mismatched DPI signatures just to make sure that works (and continues to)?

Copy link
Contributor

@fabianschuiki fabianschuiki left a comment

Choose a reason for hiding this comment

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

Awesome! LGTM

Base automatically changed from dev/hidetou/dpi-sim to main June 13, 2024 10:11
@uenoku
Copy link
Member Author

uenoku commented Jun 13, 2024

Added an error test, thank you for review!

@uenoku uenoku merged commit 44becae into main Jun 13, 2024
4 checks passed
@uenoku uenoku deleted the dev/hidetou/lower-dpi branch June 13, 2024 11:54
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.

None yet

3 participants