forked from bytecodealliance/wasmtime
-
Notifications
You must be signed in to change notification settings - Fork 4
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
Add Fibonacci benchmark #128
Merged
+205
−11
Merged
Changes from all commits
Commits
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
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,64 @@ | ||
;; TODO(akashin): Add Rust code to generate this file to repository. | ||
;; For now see https://github.com/near/wasmtime/issues/90#issuecomment-1823140768. | ||
(module | ||
(type (;0;) (func (param i64 i64))) | ||
(type (;1;) (func)) | ||
(import "env" "assert_eq" (func (;0;) (type 0))) | ||
(func (;1;) (type 1) | ||
(local i64 i64 i32) | ||
i64.const 1 | ||
local.set 0 | ||
i64.const 0 | ||
local.set 1 | ||
i32.const 10000 | ||
local.set 2 | ||
loop ;; label = @1 | ||
local.get 0 | ||
local.get 1 | ||
i64.add | ||
local.tee 1 | ||
local.get 0 | ||
i64.add | ||
local.tee 0 | ||
local.get 1 | ||
i64.add | ||
local.tee 1 | ||
local.get 0 | ||
i64.add | ||
local.tee 0 | ||
local.get 1 | ||
i64.add | ||
local.tee 1 | ||
local.get 0 | ||
i64.add | ||
local.tee 0 | ||
local.get 1 | ||
i64.add | ||
local.tee 1 | ||
local.get 0 | ||
i64.add | ||
local.tee 0 | ||
local.get 1 | ||
i64.add | ||
local.tee 1 | ||
local.get 0 | ||
i64.add | ||
local.set 0 | ||
local.get 2 | ||
i32.const -10 | ||
i32.add | ||
local.tee 2 | ||
br_if 0 (;@1;) | ||
end | ||
local.get 1 | ||
i64.const -2872092127636481573 | ||
call 0) | ||
(start 1) | ||
(memory (;0;) 16) | ||
(global (;0;) (mut i32) (i32.const 1048576)) | ||
(global (;1;) i32 (i32.const 1048576)) | ||
(global (;2;) i32 (i32.const 1048576)) | ||
(export "memory" (memory 0)) | ||
(export "main" (func 1)) | ||
(export "__data_end" (global 1)) | ||
(export "__heap_base" (global 2))) |
54 changes: 54 additions & 0 deletions
54
cranelift/zkasm_data/benchmarks/fibonacci/generated/handwritten_wat.zkasm
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,54 @@ | ||
start: | ||
zkPC + 2 => RR | ||
:JMP(function_1) | ||
:JMP(finalizeExecution) | ||
function_1: | ||
SP + 1 => SP | ||
RR :MSTORE(SP - 1) | ||
SP + 6 => SP | ||
C :MSTORE(SP - 1) | ||
D :MSTORE(SP - 2) | ||
E :MSTORE(SP - 3) | ||
B :MSTORE(SP - 4) | ||
0n => A | ||
A :MSTORE(SP + 8) | ||
0n => A | ||
1n => D | ||
D => B | ||
:JMP(label_1_1) | ||
label_1_1: | ||
$ => E :ADD | ||
B :MSTORE(SP) | ||
4294967296n => B | ||
$ => A :MLOAD(SP + 8) | ||
$ => A :ADD | ||
A :MSTORE(SP + 8) | ||
42949672960000n => B | ||
$ => A :EQ | ||
4294967296n => B | ||
0 => D | ||
0 => C | ||
${A * B} => A :ARITH | ||
A => B | ||
0 => A | ||
$ => A :EQ | ||
A :JMPZ(label_1_3) | ||
$ => A :MLOAD(SP) | ||
E => B | ||
:JMP(label_1_1) | ||
label_1_3: | ||
15574651946073070043n => B | ||
$ => A :MLOAD(SP) | ||
B :ASSERT | ||
$ => C :MLOAD(SP - 1) | ||
$ => D :MLOAD(SP - 2) | ||
$ => E :MLOAD(SP - 3) | ||
$ => B :MLOAD(SP - 4) | ||
SP - 6 => SP | ||
$ => RR :MLOAD(SP - 1) | ||
SP - 1 => SP | ||
:JMP(RR) | ||
finalizeExecution: | ||
${beforeLast()} :JMPN(finalizeExecution) | ||
:JMP(start) | ||
INCLUDE "helpers/2-exp.zkasm" |
65 changes: 65 additions & 0 deletions
65
cranelift/zkasm_data/benchmarks/fibonacci/generated/helpers/2-exp.zkasm
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,65 @@ | ||
two_power: | ||
0x1n => B :JMP(RR) ;2**0 | ||
0x2n => B :JMP(RR) ;2**1 | ||
0x4n => B :JMP(RR) ;2**2 | ||
0x8n => B :JMP(RR) ;2**3 | ||
0x10n => B :JMP(RR) ;2**4 | ||
0x20n => B :JMP(RR) ;2**5 | ||
0x40n => B :JMP(RR) ;2**6 | ||
0x80n => B :JMP(RR) ;2**7 | ||
0x100n => B :JMP(RR) ;2**8 | ||
0x200n => B :JMP(RR) ;2**9 | ||
0x400n => B :JMP(RR) ;2**10 | ||
0x800n => B :JMP(RR) ;2**11 | ||
0x1000n => B :JMP(RR) ;2**12 | ||
0x2000n => B :JMP(RR) ;2**13 | ||
0x4000n => B :JMP(RR) ;2**14 | ||
0x8000n => B :JMP(RR) ;2**15 | ||
0x10000n => B :JMP(RR) ;2**16 | ||
0x20000n => B :JMP(RR) ;2**17 | ||
0x40000n => B :JMP(RR) ;2**18 | ||
0x80000n => B :JMP(RR) ;2**19 | ||
0x100000n => B :JMP(RR) ;2**20 | ||
0x200000n => B :JMP(RR) ;2**21 | ||
0x400000n => B :JMP(RR) ;2**22 | ||
0x800000n => B :JMP(RR) ;2**23 | ||
0x1000000n => B :JMP(RR) ;2**24 | ||
0x2000000n => B :JMP(RR) ;2**25 | ||
0x4000000n => B :JMP(RR) ;2**26 | ||
0x8000000n => B :JMP(RR) ;2**27 | ||
0x10000000n => B :JMP(RR) ;2**28 | ||
0x20000000n => B :JMP(RR) ;2**29 | ||
0x40000000n => B :JMP(RR) ;2**30 | ||
0x80000000n => B :JMP(RR) ;2**31 | ||
0x100000000n => B :JMP(RR) ;2**32 | ||
0x200000000n => B :JMP(RR) ;2**33 | ||
0x400000000n => B :JMP(RR) ;2**34 | ||
0x800000000n => B :JMP(RR) ;2**35 | ||
0x1000000000n => B :JMP(RR) ;2**36 | ||
0x2000000000n => B :JMP(RR) ;2**37 | ||
0x4000000000n => B :JMP(RR) ;2**38 | ||
0x8000000000n => B :JMP(RR) ;2**39 | ||
0x10000000000n => B :JMP(RR) ;2**40 | ||
0x20000000000n => B :JMP(RR) ;2**41 | ||
0x40000000000n => B :JMP(RR) ;2**42 | ||
0x80000000000n => B :JMP(RR) ;2**43 | ||
0x100000000000n => B :JMP(RR) ;2**44 | ||
0x200000000000n => B :JMP(RR) ;2**45 | ||
0x400000000000n => B :JMP(RR) ;2**46 | ||
0x800000000000n => B :JMP(RR) ;2**47 | ||
0x1000000000000n => B :JMP(RR) ;2**48 | ||
0x2000000000000n => B :JMP(RR) ;2**49 | ||
0x4000000000000n => B :JMP(RR) ;2**50 | ||
0x8000000000000n => B :JMP(RR) ;2**51 | ||
0x10000000000000n => B :JMP(RR) ;2**52 | ||
0x20000000000000n => B :JMP(RR) ;2**53 | ||
0x40000000000000n => B :JMP(RR) ;2**54 | ||
0x80000000000000n => B :JMP(RR) ;2**55 | ||
0x100000000000000n => B :JMP(RR) ;2**56 | ||
0x200000000000000n => B :JMP(RR) ;2**57 | ||
0x400000000000000n => B :JMP(RR) ;2**58 | ||
0x800000000000000n => B :JMP(RR) ;2**59 | ||
0x1000000000000000n => B :JMP(RR) ;2**60 | ||
0x2000000000000000n => B :JMP(RR) ;2**61 | ||
0x4000000000000000n => B :JMP(RR) ;2**62 | ||
0x8000000000000000n => B :JMP(RR) ;2**63 |
18 changes: 9 additions & 9 deletions
18
cranelift/zkasm_data/fibonacci.wat → .../benchmarks/fibonacci/handwritten_wat.wat
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 |
---|---|---|
@@ -1,32 +1,32 @@ | ||
(module | ||
(import "env" "assert_eq" (func $assert_eq (param i32) (param i32))) | ||
(import "env" "assert_eq" (func $assert_eq (param i64) (param i64))) | ||
(func $main | ||
(local $counter i32) | ||
(local $fp i32) | ||
(local $f i32) | ||
(local $fp i64) | ||
(local $f i64) | ||
(local.set $counter (i32.const 0)) | ||
(local.set $fp (i32.const 0)) | ||
(local.set $f (i32.const 1)) | ||
(local.set $fp (i64.const 0)) | ||
(local.set $f (i64.const 1)) | ||
(block | ||
(loop | ||
(local.get $fp) | ||
(local.get $f) | ||
(local.set $fp (local.get $f)) | ||
(local.set $f (i32.add)) | ||
(local.set $f (i64.add)) | ||
(local.set $counter | ||
(i32.add | ||
(local.get $counter) | ||
(i32.const 1))) | ||
(br_if 1 | ||
(i32.eq | ||
(local.get $counter) | ||
(i32.const 10) | ||
(i32.const 10000) | ||
) | ||
) | ||
(br 0) | ||
) | ||
) | ||
(local.get $f) | ||
(i32.const 89) | ||
(local.get $fp) | ||
(i64.const -2872092127636481573) | ||
call $assert_eq) | ||
(start $main)) |
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,3 @@ | ||
Test,Status,Cycles | ||
from_rust,compilation failed, | ||
handwritten_wat,pass,190024 | ||
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 |
---|---|---|
@@ -1,5 +1,6 @@ | ||
Suite path,Passing count,Total count,Total cycles | ||
cranelift/zkasm_data,25,26,1023 | ||
cranelift/zkasm_data/benchmarks/fibonacci,1,2,190024 | ||
cranelift/zkasm_data/spectest/conversions,3,24,45 | ||
cranelift/zkasm_data/spectest/i32,155,364,4589 | ||
cranelift/zkasm_data/spectest/i64,161,374,4042 |
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.
LGTM. Just interesting, what is ratio from cycles to seconds?
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.
Yeah, that would be very interesting to know. I'll be working on figuring this out next.
We basically know that ZK ASM is ~10KHz machine, so now we also need to benchmark that Fibonacci code on normal processor and compute the ratio.