Move kraken,scheme,python,cpp fib tests over to koka_bench, add WAVM as a tested compiler backend for the Kraken benchmarks

This commit is contained in:
Nathan Braswell
2022-06-28 00:38:37 -04:00
parent 999d21746e
commit 4663982f1b
18 changed files with 248 additions and 8 deletions

View File

@@ -19,6 +19,40 @@
inherit system; inherit system;
overlays = [ moz_overlay.overlay ]; overlays = [ moz_overlay.overlay ];
}; };
wavm = pkgs.stdenv.mkDerivation rec {
pname = "wavm";
version = "0.0.0";
src = pkgs.fetchurl {
url = "https://github.com/WAVM/WAVM/releases/download/nightly%2F2022-05-14/wavm-0.0.0-prerelease-linux.tar.gz";
sha256 = "sha256-+PpnwPJDty6XCjjuHVFwiHc1q+k0zPF11EbRpqSKfyY=";
};
nativeBuildInputs = [
pkgs.autoPatchelfHook
];
buildInputs = [
pkgs.stdenv.cc.cc.lib
];
sourceRoot = ".";
installPhase = ''
mkdir -p $out/bin
cp -r bin/wavm $out/bin/
cp -r include/ $out
cp -r lib64/ $out
cp -r share/ $out
#install -m755 -D studio-link-standalone-v${version} $out/bin/studio-link
'';
meta = with pkgs.lib; {
homepage = "https://wavm.github.io/";
description = "WAVM WebAssembly Engine";
platforms = platforms.linux;
};
};
in { in {
devShell = pkgs.mkShell { devShell = pkgs.mkShell {
buildInputs = with pkgs; [ buildInputs = with pkgs; [
@@ -35,6 +69,8 @@
clang clang
kakoune kakoune
wavm
hyperfine graph-cli hyperfine graph-cli
(rust-bin.stable.latest.default.override { (rust-bin.stable.latest.default.override {
targets = [ "wasm32-wasi" ]; targets = [ "wasm32-wasi" ];

View File

@@ -15,3 +15,6 @@ add_subdirectory(haskell)
add_subdirectory(java) add_subdirectory(java)
add_subdirectory(ocaml) add_subdirectory(ocaml)
add_subdirectory(swift) add_subdirectory(swift)
add_subdirectory(python)
add_subdirectory(scheme)

8
koka_bench/copy_wrapper.sh Executable file
View File

@@ -0,0 +1,8 @@
#!/usr/bin/env bash
OUR_DIR="$(dirname $(readlink -f $0))"
SOURCE="$1"
OUT_DIR="$2"
OUT_NAME="$3"
mkdir -p "$OUT_DIR"
cp $SOURCE "$OUT_DIR/$OUT_NAME"

View File

@@ -2,7 +2,7 @@ set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED YES) set(CMAKE_CXX_STANDARD_REQUIRED YES)
set(CMAKE_CXX_EXTENSIONS NO) set(CMAKE_CXX_EXTENSIONS NO)
foreach (source IN ITEMS rbtree.cpp nqueens.cpp cfold.cpp deriv.cpp) foreach (source IN ITEMS rbtree.cpp nqueens.cpp cfold.cpp deriv.cpp fib.cpp)
get_filename_component(name "${source}" NAME_WE) get_filename_component(name "${source}" NAME_WE)
set(name "cpp-${name}") set(name "cpp-${name}")

17
koka_bench/cpp/fib.cpp Normal file
View File

@@ -0,0 +1,17 @@
#include <math.h>
#include <string.h>
#include <iostream>
int fib(int n) {
if (n == 0) {
return 1;
} else if (n == 1) {
return 1;
} else {
return fib(n-1) + fib(n-2);
}
}
int main(int argc, char **argv) {
printf("%d\n", fib(atoi(argv[1])));
return 0;
}

View File

@@ -1,4 +1,4 @@
set(sources rbtree.kk nqueens.kk nqueens-int.kk cfold.kk deriv.kk) set(sources rbtree.kk nqueens.kk nqueens-int.kk cfold.kk deriv.kk fib.kk)
set(koka koka) set(koka koka)

13
koka_bench/koka/fib.kk Normal file
View File

@@ -0,0 +1,13 @@
module nqueens
import std/num/int32
import std/os/env
pub fun fib( n : int ) : div int
match n
0 -> 1
1 -> 1
x -> fib(x - 1) + fib(x - 2)
pub fun main()
fib(get-args().head("").parse-int.default(30)).println

View File

@@ -1,4 +1,4 @@
set(sources rbtree.kp rbtree-opt.kp nqueens.kp cfold.kp deriv.kp) set(sources rbtree.kp rbtree-opt.kp nqueens.kp cfold.kp deriv.kp fib.kp fib-let.kp)
set(kraken "../../kraken_wrapper.sh") set(kraken "../../kraken_wrapper.sh")

View File

@@ -0,0 +1,38 @@
((wrap (vau root_env (quote)
((wrap (vau (let1)
(let1 lambda (vau se (p b1) (wrap (eval (array vau p b1) se)))
(let1 current-env (vau de () de)
(let1 cons (lambda (h t) (concat (array h) t))
(let1 Y (lambda (f3)
((lambda (x1) (x1 x1))
(lambda (x2) (f3 (wrap (vau app_env (& y) (lapply (x2 x2) y app_env)))))))
(let1 vY (lambda (f)
((lambda (x3) (x3 x3))
(lambda (x4) (f (vau de1 (& y) (vapply (x4 x4) y de1))))))
(let1 let (vY (lambda (recurse) (vau de2 (vs b) (cond (= (len vs) 0) (eval b de2)
true (vapply let1 (array (idx vs 0) (idx vs 1) (array recurse (slice vs 2 -1) b)) de2)))))
(let (
lcompose (lambda (g f) (lambda (& args) (lapply g (array (lapply f args)))))
rec-lambda (vau se (n p b) (eval (array Y (array lambda (array n) (array lambda p b))) se))
fib (rec-lambda fib (n) (cond (= 0 n) 1
(= 1 n) 1
true (let (
fib_minus_1 (fib (- n 1))
fib_minus_2 (fib (- n 2))
) (+ fib_minus_1 fib_minus_2))))
monad (array 'write 1 (str "running fib") (vau (written code)
(array 'args (vau (args code)
(array 'exit (fib (read-string (idx args 1))))
))
))
) monad)
; end of all lets
))))))
; impl of let1
)) (vau de (s v b) (eval (array (array wrap (array vau (array s) b)) v) de)))
; impl of quote
)) (vau (x5) x5))

35
koka_bench/kraken/fib.kp Normal file
View File

@@ -0,0 +1,35 @@
((wrap (vau root_env (quote)
((wrap (vau (let1)
(let1 lambda (vau se (p b1) (wrap (eval (array vau p b1) se)))
(let1 current-env (vau de () de)
(let1 cons (lambda (h t) (concat (array h) t))
(let1 Y (lambda (f3)
((lambda (x1) (x1 x1))
(lambda (x2) (f3 (wrap (vau app_env (& y) (lapply (x2 x2) y app_env)))))))
(let1 vY (lambda (f)
((lambda (x3) (x3 x3))
(lambda (x4) (f (vau de1 (& y) (vapply (x4 x4) y de1))))))
(let1 let (vY (lambda (recurse) (vau de2 (vs b) (cond (= (len vs) 0) (eval b de2)
true (vapply let1 (array (idx vs 0) (idx vs 1) (array recurse (slice vs 2 -1) b)) de2)))))
(let (
lcompose (lambda (g f) (lambda (& args) (lapply g (array (lapply f args)))))
rec-lambda (vau se (n p b) (eval (array Y (array lambda (array n) (array lambda p b))) se))
fib (rec-lambda fib (n) (cond (= 0 n) 1
(= 1 n) 1
true (+ (fib (- n 1)) (fib (- n 2)))))
monad (array 'write 1 (str "running fib") (vau (written code)
(array 'args (vau (args code)
(array 'exit (fib (read-string (idx args 1))))
))
))
) monad)
; end of all lets
))))))
; impl of let1
)) (vau de (s v b) (eval (array (array wrap (array vau (array s) b)) v) de)))
; impl of quote
)) (vau (x5) x5))

View File

@@ -10,7 +10,14 @@ mv ./csc_out.wasm "$OUT_DIR/$OUT_NAME.wasm"
printf '#!/usr/bin/env bash\nwasmtime "$(dirname $(readlink -f $0))/'"$OUT_NAME"'.wasm" $@' > "$OUT_DIR/$OUT_NAME" printf '#!/usr/bin/env bash\nwasmtime "$(dirname $(readlink -f $0))/'"$OUT_NAME"'.wasm" $@' > "$OUT_DIR/$OUT_NAME"
chmod 755 "$OUT_DIR/$OUT_NAME" chmod 755 "$OUT_DIR/$OUT_NAME"
printf '#!/usr/bin/env bash\nWAVM_OBJECT_CACHE_DIR=$(pwd) wavm run "$(dirname $(readlink -f $0))/'"$OUT_NAME"'.wasm" $@' > "$OUT_DIR/$OUT_NAME-wavm"
chmod 755 "$OUT_DIR/$OUT_NAME-wavm"
scheme --script "$OUR_DIR/../partial_eval.scm" $SOURCE no_compile scheme --script "$OUR_DIR/../partial_eval.scm" $SOURCE no_compile
mv ./csc_out.wasm "$OUT_DIR/$OUT_NAME-slow.wasm" mv ./csc_out.wasm "$OUT_DIR/$OUT_NAME-slow.wasm"
printf '#!/usr/bin/env bash\nwasmtime "$(dirname $(readlink -f $0))/'"$OUT_NAME-slow"'.wasm" $@' > "$OUT_DIR/$OUT_NAME-slow" printf '#!/usr/bin/env bash\nwasmtime "$(dirname $(readlink -f $0))/'"$OUT_NAME-slow"'.wasm" $@' > "$OUT_DIR/$OUT_NAME-slow"
chmod 755 "$OUT_DIR/$OUT_NAME-slow" chmod 755 "$OUT_DIR/$OUT_NAME-slow"
printf '#!/usr/bin/env bash\nWAVM_OBJECT_CACHE_DIR=$(pwd) wavm run "$(dirname $(readlink -f $0))/'"$OUT_NAME-slow"'.wasm" $@' > "$OUT_DIR/$OUT_NAME-slow-wavm"
chmod 755 "$OUT_DIR/$OUT_NAME-slow-wavm"

View File

@@ -0,0 +1,22 @@
set(copy_wrapper "../../copy_wrapper.sh")
set(sources python-fib.py python-fib-let.py)
foreach (source IN LISTS sources)
get_filename_component(name "${source}" NAME_WE)
set(out_dir "${CMAKE_CURRENT_BINARY_DIR}/out/bench")
set(out_path "${out_dir}/${name}")
add_custom_command(
OUTPUT ${out_path}
COMMAND ${copy_wrapper} "${CMAKE_CURRENT_SOURCE_DIR}/${source}" ${out_dir} ${name}
DEPENDS ${source}
VERBATIM)
add_custom_target(update-${name} ALL DEPENDS "${out_path}")
add_executable(${name}-exe IMPORTED)
set_target_properties(${name}-exe PROPERTIES IMPORTED_LOCATION "${out_path}")
endforeach ()

View File

@@ -0,0 +1,13 @@
#!/usr/bin/env python3
import sys
def fib(n):
if n == 0:
return 1
elif n == 1:
return 1
else:
r1 = fib(n-1)
r2 = fib(n-2)
return r1 + r2
print(fib(int(sys.argv[1])))

11
koka_bench/python/python-fib.py Executable file
View File

@@ -0,0 +1,11 @@
#!/usr/bin/env python3
import sys
def fib(n):
if n == 0:
return 1
elif n == 1:
return 1
else:
return fib(n-1) + fib(n-2)
print(fib(int(sys.argv[1])))

View File

@@ -0,0 +1,22 @@
set(copy_wrapper "../../copy_wrapper.sh")
set(sources scheme-fib.scm scheme-fib-let.scm)
foreach (source IN LISTS sources)
get_filename_component(name "${source}" NAME_WE)
set(out_dir "${CMAKE_CURRENT_BINARY_DIR}/out/bench")
set(out_path "${out_dir}/${name}")
add_custom_command(
OUTPUT ${out_path}
COMMAND ${copy_wrapper} "${CMAKE_CURRENT_SOURCE_DIR}/${source}" ${out_dir} ${name}
DEPENDS ${source}
VERBATIM)
add_custom_target(update-${name} ALL DEPENDS "${out_path}")
add_executable(${name}-exe IMPORTED)
set_target_properties(${name}-exe PROPERTIES IMPORTED_LOCATION "${out_path}")
endforeach ()

View File

@@ -0,0 +1,8 @@
#!/usr/bin/env -S scheme --script
(pretty-print ((letrec ((fib (lambda (n) (cond ((equal? n 0) 1)
((equal? n 1) 1)
(#t (let (
(r1 (fib (- n 1)))
(r2 (fib (- n 2)))
) (+ r1 r2)))))))
fib) (read (open-input-string (list-ref (command-line) 1)))))

View File

@@ -0,0 +1,5 @@
#!/usr/bin/env -S scheme --script
(pretty-print ((letrec ((fib (lambda (n) (cond ((equal? n 0) 1)
((equal? n 1) 1)
(#t (+ (fib (- n 1)) (fib (- n 2))))))))
fib) (read (open-input-string (list-ref (command-line) 1)))))

View File

@@ -16,16 +16,18 @@ mkdir -p slow
find build -type f -name \*slow\* -exec mv {} slow \; find build -type f -name \*slow\* -exec mv {} slow \;
cp ./build/kraken/out/bench/kraken-* ./slow cp ./build/kraken/out/bench/kraken-* ./slow
nix develop -i -c bash -c 'ulimit -s unlimited && find build -type f -executable -name \*fib\* -printf "\"%p 30\"\n" | xargs hyperfine --ignore-failure --warmup 2 --export-markdown fib_table.md --export-csv fib_table.csv'
nix develop -i -c bash -c 'ulimit -s unlimited && find build -type f -executable -name \*nqueens\* -printf "\"%p 10\"\n" | xargs hyperfine --ignore-failure --warmup 2 --export-markdown nqueens_table.md --export-csv nqueens_table.csv' nix develop -i -c bash -c 'ulimit -s unlimited && find build -type f -executable -name \*nqueens\* -printf "\"%p 10\"\n" | xargs hyperfine --ignore-failure --warmup 2 --export-markdown nqueens_table.md --export-csv nqueens_table.csv'
nix develop -i -c bash -c 'ulimit -s unlimited && find build -type f -executable -name \*rbtree\* -printf "\"%p 42000\"\n" | xargs hyperfine --ignore-failure --warmup 2 --export-markdown rbtree_table.md --export-csv rbtree_table.csv' nix develop -i -c bash -c 'ulimit -s unlimited && find build -type f -executable -name \*rbtree\* -printf "\"%p 42000\"\n" | xargs hyperfine --ignore-failure --warmup 2 --export-markdown rbtree_table.md --export-csv rbtree_table.csv'
nix develop -i -c bash -c 'ulimit -s unlimited && find build -type f -executable -name \*cfold\* -printf "\"%p 5\"\n" | xargs hyperfine --ignore-failure --warmup 2 --export-markdown cfold_table.md --export-csv cfold_table.csv' nix develop -i -c bash -c 'ulimit -s unlimited && find build -type f -executable -name \*cfold\* -printf "\"%p 5\"\n" | xargs hyperfine --ignore-failure --warmup 2 --export-markdown cfold_table.md --export-csv cfold_table.csv'
nix develop -i -c bash -c 'ulimit -s unlimited && find build -type f -executable -name \*deriv\* -printf "\"%p 8\"\n" | xargs hyperfine --ignore-failure --warmup 2 --export-markdown deriv_table.md --export-csv deriv_table.csv' nix develop -i -c bash -c 'ulimit -s unlimited && find build -type f -executable -name \*deriv\* -printf "\"%p 8\"\n" | xargs hyperfine --ignore-failure --warmup 2 --export-markdown deriv_table.md --export-csv deriv_table.csv'
#nix develop -i -c bash -c 'ulimit -s unlimited && find slow -type f -executable -name \*nqueens\* -printf "\"%p 7\"\n" | xargs hyperfine --ignore-failure --warmup 2 --export-markdown slow_nqueens_table.md --export-csv slow_nqueens_table.csv'
#nix develop -i -c bash -c 'ulimit -s unlimited && find slow -type f -executable -name \*cfold\* -printf "\"%p 5\"\n" | xargs hyperfine --ignore-failure --warmup 2 --export-markdown slow_cfold_table.md --export-csv slow_cfold_table.csv' nix develop -i -c bash -c 'ulimit -s unlimited && find slow -type f -executable -name \*nqueens\* -printf "\"%p 7\"\n" | xargs hyperfine --ignore-failure --warmup 2 --export-markdown slow_nqueens_table.md --export-csv slow_nqueens_table.csv'
#nix develop -i -c bash -c 'ulimit -s unlimited && find slow -type f -executable -name \*deriv\* -printf "\"%p 3\"\n" | xargs hyperfine --ignore-failure --warmup 2 --export-markdown slow_deriv_table.md --export-csv slow_deriv_table.csv' nix develop -i -c bash -c 'ulimit -s unlimited && find slow -type f -executable -name \*cfold\* -printf "\"%p 5\"\n" | xargs hyperfine --ignore-failure --warmup 2 --export-markdown slow_cfold_table.md --export-csv slow_cfold_table.csv'
#nix develop -i -c bash -c 'ulimit -s unlimited && find slow -type f -executable -name \*rbtree\* -printf "\"%p 100\"\n" | xargs hyperfine --ignore-failure --warmup 2 --export-markdown slow_rbtree_table.md --export-csv slow_rbtree_table.csv' nix develop -i -c bash -c 'ulimit -s unlimited && find slow -type f -executable -name \*deriv\* -printf "\"%p 3\"\n" | xargs hyperfine --ignore-failure --warmup 2 --export-markdown slow_deriv_table.md --export-csv slow_deriv_table.csv'
nix develop -i -c bash -c 'ulimit -s unlimited && find slow -type f -executable -name \*rbtree\* -printf "\"%p 100\"\n" | xargs hyperfine --ignore-failure --warmup 2 --export-markdown slow_rbtree_table.md --export-csv slow_rbtree_table.csv'
nix develop -i -c bash -c 'ulimit -s unlimited && find slow -type f -executable -name \*fib\* -printf "\"%p 30\"\n" | xargs hyperfine --ignore-failure --warmup 2 --export-markdown slow_fib_table.md --export-csv slow_fib_table.csv'
for x in *_table.csv for x in *_table.csv
do do