-
Notifications
You must be signed in to change notification settings - Fork 317
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
[Arc][Sim] Lower Sim DPI func to func.func and support dpi call in Arc #7386
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
3f09368
[Arc] Lower Sim DPI ops to Arc
uenoku 2e949e2
Lower DPI func to func.func
uenoku e611127
Add Func dependency
uenoku 78747eb
Address comments
uenoku 2532e2e
Add test for sim.dpi.call
uenoku 2232d9b
add more test
uenoku b71560b
Tweak test
uenoku File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// RUN: arcilator %s --run --jit-entry=main | FileCheck %s | ||
// REQUIRES: arcilator-jit | ||
|
||
// CHECK: c = 0 | ||
// CHECK-NEXT: c = 5 | ||
sim.func.dpi @dpi(in %a : i32, in %b : i32, out c : i32) attributes {verilogName = "adder_func"} | ||
func.func @adder_func(%arg0: i32, %arg1: i32, %arg2: !llvm.ptr) { | ||
%0 = arith.addi %arg0, %arg1 : i32 | ||
llvm.store %0, %arg2 : i32, !llvm.ptr | ||
return | ||
} | ||
hw.module @adder(in %clock : i1, in %a : i32, in %b : i32, out c : i32) { | ||
%seq_clk = seq.to_clock %clock | ||
|
||
%0 = sim.func.dpi.call @dpi(%a, %b) clock %seq_clk : (i32, i32) -> i32 | ||
hw.output %0 : i32 | ||
} | ||
func.func @main() { | ||
%c2_i32 = arith.constant 2 : i32 | ||
%c3_i32 = arith.constant 3 : i32 | ||
%one = arith.constant 1 : i1 | ||
%zero = arith.constant 0 : i1 | ||
arc.sim.instantiate @adder as %arg0 { | ||
arc.sim.set_input %arg0, "a" = %c2_i32 : i32, !arc.sim.instance<@adder> | ||
arc.sim.set_input %arg0, "b" = %c3_i32 : i32, !arc.sim.instance<@adder> | ||
arc.sim.set_input %arg0, "clock" = %one : i1, !arc.sim.instance<@adder> | ||
|
||
arc.sim.step %arg0 : !arc.sim.instance<@adder> | ||
arc.sim.set_input %arg0, "clock" = %zero : i1, !arc.sim.instance<@adder> | ||
%0 = arc.sim.get_port %arg0, "c" : i32, !arc.sim.instance<@adder> | ||
arc.sim.emit "c", %0 : i32 | ||
|
||
arc.sim.step %arg0 : !arc.sim.instance<@adder> | ||
arc.sim.set_input %arg0, "clock" = %one : i1, !arc.sim.instance<@adder> | ||
%2 = arc.sim.get_port %arg0, "c" : i32, !arc.sim.instance<@adder> | ||
arc.sim.emit "c", %2 : i32 | ||
} | ||
return | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,5 +11,6 @@ add_circt_conversion_library(CIRCTConvertToArcs | |
CIRCTArc | ||
CIRCTHW | ||
CIRCTSeq | ||
CIRCTSim | ||
MLIRTransforms | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Just out of curiosity: since the
sim.func.dpi.call
function seems like it accepts bothsim.func.dpi
andfunc.func
callables, would this code also work with a secondsim.func.dpi.call
that calls the@adder_func
directly?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.
Directly calling
@adder_func
doesn't work since it's output value is passed by reference in argument. If@adder_func
was a normal dataflow-ish func.func such asfunc.func @adder_func_ok(%arg0: i32, %arg1: i32) -> i32
, we can call it directly.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.
Ooooh you're right, sorry, I overlooked that difference in the operand layout. Makes sense!