-
Notifications
You must be signed in to change notification settings - Fork 318
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[arcilator] Introduce integrated JIT for simulation execution (#6783)
This PR adds a JIT runtime for arcilator, backed by MLIR's ExecutionEngine. This JIT allows executing `arc.sim` operations directly from the arcilator binary.
- Loading branch information
1 parent
4b075de
commit 83a8292
Showing
13 changed files
with
393 additions
and
122 deletions.
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,26 @@ | ||
// RUN: arcilator %s --run --jit-entry=main | FileCheck %s | ||
// REQUIRES: arcilator-jit | ||
|
||
// CHECK: output = 5 | ||
|
||
hw.module @adder(in %a: i8, in %b: i8, out c: i8) { | ||
%res = comb.add %a, %b : i8 | ||
hw.output %res : i8 | ||
} | ||
|
||
func.func @main() { | ||
%two = arith.constant 2 : i8 | ||
%three = arith.constant 3 : i8 | ||
|
||
arc.sim.instantiate @adder as %model { | ||
arc.sim.set_input %model, "a" = %two : i8, !arc.sim.instance<@adder> | ||
arc.sim.set_input %model, "b" = %three : i8, !arc.sim.instance<@adder> | ||
|
||
arc.sim.step %model : !arc.sim.instance<@adder> | ||
|
||
%res = arc.sim.get_port %model, "c" : i8, !arc.sim.instance<@adder> | ||
arc.sim.emit "output", %res : i8 | ||
} | ||
|
||
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 |
---|---|---|
@@ -0,0 +1,50 @@ | ||
// RUN: arcilator %s --run --jit-entry=main | FileCheck %s | ||
// REQUIRES: arcilator-jit | ||
|
||
// CHECK: counter_value = 0 | ||
// CHECK-NEXT: counter_value = 1 | ||
// CHECK-NEXT: counter_value = 2 | ||
// CHECK-NEXT: counter_value = 3 | ||
// CHECK-NEXT: counter_value = 4 | ||
// CHECK-NEXT: counter_value = 5 | ||
// CHECK-NEXT: counter_value = 6 | ||
// CHECK-NEXT: counter_value = 7 | ||
// CHECK-NEXT: counter_value = 8 | ||
// CHECK-NEXT: counter_value = 9 | ||
// CHECK-NEXT: counter_value = a | ||
|
||
hw.module @counter(in %clk: i1, out o: i8) { | ||
%seq_clk = seq.to_clock %clk | ||
|
||
%reg = seq.compreg %added, %seq_clk : i8 | ||
|
||
%one = hw.constant 1 : i8 | ||
%added = comb.add %reg, %one : i8 | ||
|
||
hw.output %reg : i8 | ||
} | ||
|
||
func.func @main() { | ||
%zero = arith.constant 0 : i1 | ||
%one = arith.constant 1 : i1 | ||
%lb = arith.constant 0 : index | ||
%ub = arith.constant 10 : index | ||
%step = arith.constant 1 : index | ||
|
||
arc.sim.instantiate @counter as %model { | ||
%init_val = arc.sim.get_port %model, "o" : i8, !arc.sim.instance<@counter> | ||
arc.sim.emit "counter_value", %init_val : i8 | ||
|
||
scf.for %i = %lb to %ub step %step { | ||
arc.sim.set_input %model, "clk" = %one : i1, !arc.sim.instance<@counter> | ||
arc.sim.step %model : !arc.sim.instance<@counter> | ||
arc.sim.set_input %model, "clk" = %zero : i1, !arc.sim.instance<@counter> | ||
arc.sim.step %model : !arc.sim.instance<@counter> | ||
|
||
%counter_val = arc.sim.get_port %model, "o" : i8, !arc.sim.instance<@counter> | ||
arc.sim.emit "counter_value", %counter_val : i8 | ||
} | ||
} | ||
|
||
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 |
---|---|---|
@@ -0,0 +1,8 @@ | ||
// RUN: ! (arcilator %s --run --jit-entry=unknown 2> %t) && FileCheck --input-file=%t %s | ||
// REQUIRES: arcilator-jit | ||
|
||
// CHECK: entry point not found: 'unknown' | ||
|
||
func.func @main() { | ||
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 |
---|---|---|
@@ -0,0 +1,6 @@ | ||
// RUN: ! (arcilator %s --run --jit-entry=foo 2> %t) && FileCheck --input-file=%t %s | ||
// REQUIRES: arcilator-jit | ||
|
||
// CHECK: entry point 'foo' was found but on an operation of type 'llvm.mlir.global' while an LLVM function was expected | ||
|
||
llvm.mlir.global @foo(0 : i32) : i32 |
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,8 @@ | ||
// RUN: ! (arcilator %s --run --jit-entry=main 2> %t) && FileCheck --input-file=%t %s | ||
// REQUIRES: arcilator-jit | ||
|
||
// CHECK: entry point 'main' must have no arguments | ||
|
||
func.func @main(%a: 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 |
---|---|---|
@@ -0,0 +1,10 @@ | ||
// RUN: arcilator %s --run | FileCheck %s | ||
// REQUIRES: arcilator-jit | ||
|
||
// CHECK: result = 4 | ||
|
||
func.func @entry() { | ||
%four = arith.constant 4 : i32 | ||
arc.sim.emit "result", %four : 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
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.
83a8292
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 am once again completely confused by the result of the Windows build...
83a8292
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 have no explanation for this either but after a little shuffling of includes it appears to be some absurd interaction between
#include "mlir/ExecutionEngine/ExecutionEngine.h"
and#include "circt/InitAllPasses.h"
. Untangling this is a bit of a nightmare, so I can just speculate in the general direction of namespace pollution. Since we are not actually callingregisterAllPasses()
we can probably sidestep this by only including the passes we really need.83a8292
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.
Ah, that's interesting, thanks for the help. Right now I am trying to not build the JIT infra on Windows, but I should probably try what you suggested.
83a8292
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 guess I just found the culprit: https://github.com/llvm/circt/blob/main/include/circt/Conversion/HWToBTOR2.h
83a8292
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 have dropped InitAllPasses from Arcilator for now, I have a CI build test running to see if it fixes the issue.
83a8292
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.
Unfortunately dropping it did not resolve the issue. What is your suggestion exactly @fzi-hielscher?
83a8292
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 would hope that this solves the problem: #6844