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

AsyncBril #305

Open
wants to merge 34 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
d5f33f5
add support for promise type in json
he-andy Dec 9, 2023
fbaf8e8
add type checking for promises
he-andy Dec 9, 2023
d64ffd6
Type checking for resolve and promise, minus return types of functions
emwangs Dec 9, 2023
6c6e490
Merge branch 'main' of https://github.com/he-andy/bril
emwangs Dec 9, 2023
c232bbd
Remove print statement
emwangs Dec 9, 2023
96bdc81
add support for parallel execution and writing to stdout
he-andy Dec 9, 2023
a01cc6f
Merge
emwangs Dec 9, 2023
bf36273
change instruction counter to atomic
he-andy Dec 9, 2023
bfca993
Merge branch 'main' of github.com:he-andy/bril
he-andy Dec 9, 2023
6cd7cfa
Benchmarks for async
emwangs Dec 9, 2023
26dc804
terminate unresolved handlers after function exit
he-andy Dec 9, 2023
51e672b
Merge branch 'main' of github.com:he-andy/bril
he-andy Dec 9, 2023
ffbc095
changce gcd args
emwangs Dec 9, 2023
b971fcd
Merge branch 'main' of https://github.com/he-andy/bril
emwangs Dec 9, 2023
266c7e4
Added atomic type
emwangs Dec 10, 2023
d428ce0
Added new async valueOps
emwangs Dec 10, 2023
8280fc4
change mutex to rwlock on heap
he-andy Dec 10, 2023
90da5ab
Merge branch 'main' of github.com:he-andy/bril
he-andy Dec 10, 2023
92ff066
type check atomic things
emwangs Dec 10, 2023
ea038b4
Merge branch 'main' of https://github.com/he-andy/bril
emwangs Dec 10, 2023
6187622
add support for atomici64
he-andy Dec 10, 2023
a3ad035
Change name to swapatomic
emwangs Dec 10, 2023
2b92bc7
cargo.toml
he-andy Dec 10, 2023
16bd3a3
merge conflicts
he-andy Dec 10, 2023
2f8f9fb
fix type conversion for atomics
he-andy Dec 10, 2023
3516fa8
Added atomics benchmarks
emwangs Dec 10, 2023
a59a175
Merge branch 'main' of https://github.com/he-andy/bril
emwangs Dec 10, 2023
0a50e31
fix some warnings
he-andy Dec 10, 2023
94046f1
Merge branch 'main' of github.com:he-andy/bril
he-andy Dec 10, 2023
651fb5c
add mutex benchmark
he-andy Dec 11, 2023
9de464d
remove extra files
he-andy Dec 11, 2023
82f822b
Add Bril book page for AsyncBril
evanmwilliams Dec 11, 2023
45762ca
fixed documentation
evanmwilliams Dec 11, 2023
46f4349
fix documentation (again)
evanmwilliams Dec 11, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions benchmarks/async/atomic.bril
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
@main {
one : int = const 1;
size : atomicint = newatomic one;
expect : int = const 1;
upd : int = const 2;
res : int = cas size expect upd;

three : int = const 3;
res1 : int = loadatomic size;
res2 : int = swapatomic size three;
res3 : int = loadatomic size;
print res;
print res1;
print res2;
print res3;
}
57 changes: 57 additions & 0 deletions benchmarks/async/atomic_promise.bril
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
@main {
zero : int = const 0;

a : atomicint = newatomic zero;
res1 : promise<int> = call @incr1 a;
res2 : promise<int> = call @incr1 a;
res3 : promise<int> = call @incr1 a;
res4 : promise<int> = call @incr1 a;
res5 : promise<int> = call @incr1 a;
res6 : promise<int> = call @incr1 a;
res7 : promise<int> = call @incr1 a;
res8 : promise<int> = call @incr1 a;
res9 : promise<int> = call @incr1 a;
res10 : promise<int> = call @incr1 a;

res11 : promise<int> = call @incr1 a;
res12 : promise<int> = call @incr1 a;
res13 : promise<int> = call @incr1 a;
res14 : promise<int> = call @incr1 a;
res15 : promise<int> = call @incr1 a;
res16 : promise<int> = call @incr1 a;
res17 : promise<int> = call @incr1 a;
res18 : promise<int> = call @incr1 a;
res19 : promise<int> = call @incr1 a;
res20 : promise<int> = call @incr1 a;

res21 : promise<int> = call @incr1 a;
res22 : promise<int> = call @incr1 a;
res23 : promise<int> = call @incr1 a;
res24 : promise<int> = call @incr1 a;
res25 : promise<int> = call @incr1 a;
res26 : promise<int> = call @incr1 a;
res27 : promise<int> = call @incr1 a;
res28 : promise<int> = call @incr1 a;
res29 : promise<int> = call @incr1 a;
res30 : promise<int> = call @incr1 a;

.loop:
res : int = loadatomic a;
print res;
jmp .loop;
}

@incr1(r: atomicint) : promise<int> {
.loop:
res : int = loadatomic r;
one : int = const 1;
upd : int = add res one;

old : int = cas r res upd;

eq: bool = eq old res;
br eq .end .loop;
.end:
zero : int = const 0;
ret zero;
}
99 changes: 99 additions & 0 deletions benchmarks/async/mutex.bril
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
@main {
size: int = const 1000;

arr: ptr<int> = alloc size;
zero: int = const 0;
lock: atomicint = newatomic zero;

one: int = const 1;
two: int = const 2;
three: int = const 3;
four: int = const 4;
five: int = const 5;
six: int = const 6;
seven: int = const 7;
eight: int = const 8;
nine: int = const 9;
ten: int = const 10;

i: int = const 0;
.loopfill:
ptr_i : ptr<int> = ptradd arr i;
store ptr_i zero;
i : int = add i one;
cond: bool = lt i size;
br cond .loopfill .endfill;
.endfill:

p1: promise<int> = call @increment_array arr size lock one;
p2: promise<int> = call @increment_array arr size lock two;
p3: promise<int> = call @increment_array arr size lock three;
p4: promise<int> = call @increment_array arr size lock four;
p5: promise<int> = call @increment_array arr size lock five;
p6: promise<int> = call @increment_array arr size lock six;
p7: promise<int> = call @increment_array arr size lock seven;
p8: promise<int> = call @increment_array arr size lock eight;
p9: promise<int> = call @increment_array arr size lock nine;
p10: promise<int> = call @increment_array arr size lock ten;

res1: int = resolve p1;
res2: int = resolve p2;
res3: int = resolve p3;
res4: int = resolve p4;
res5: int = resolve p5;
res6: int = resolve p6;
res7: int = resolve p7;
res8: int = resolve p8;
res9: int = resolve p9;
res10: int = resolve p10;

i: int = const 0;
.loop:

ptr_i : ptr<int> = ptradd arr i;
arr_i : int = load ptr_i;
print arr_i;
i : int = add i one;
cond: bool = lt i size;
br cond .loop .end;
.end:
free arr;
}

@increment_array(arr: ptr<int>, size: int, lock: atomicint, inc_amt: int) : promise<int> {
i : int = const 0;
one : int = const 1;

.loop:
ptr_i : ptr<int> = ptradd arr i;
call @acquire_lock lock;
arr_i : int = load ptr_i;
upd_i : int = add arr_i inc_amt;
store ptr_i upd_i;
call @release_lock lock;
i : int = add i one;
cond: bool = lt i size;
br cond .loop .end;
.end:
ret i;
}

@acquire_lock(lock: atomicint) {
.loop:
res: int = loadatomic lock;
one: int = const 1;
eq: bool = eq one res;
br eq .loop .acquire_lock;
.acquire_lock:
upd: int = add res one;
old: int = cas lock res upd;
eq: bool = eq old res;
br eq .end .loop;
.end:
ret;
}

@release_lock(lock: atomicint) {
zero: int = const 0;
val: int = swapatomic lock zero;
}
18 changes: 18 additions & 0 deletions benchmarks/async/promise1.bril
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
@main {
size: int = const 4;
size2: bool = const false;
prom: promise<int> = call @mod size;
prom2: promise<bool> = call @mod2 size2;
x : int = resolve prom;
y : bool = resolve prom2;
print x;
print y;
}

@mod(r: int): promise<int> {
ret r;
}

@mod2(r: bool): promise<bool> {
ret r;
}
19 changes: 19 additions & 0 deletions benchmarks/async/promise2.bril
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
@main {
size: int = const 4;
size2: bool = const false;
prom: promise<int> = call @mod size;
prom2: promise<bool> = call @mod2 size2;

}

@mod(r: int): promise<int> {
a : int = const 1;
print a;
ret r;
}

@mod2(r: bool): promise<bool> {
a : int = const 2;
print a;
ret r;
}
138 changes: 138 additions & 0 deletions benchmarks/async/promise_arr.bril
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
# An implementation of Quicksort using the Lomuto partition scheme, adapted from the pseudocode on Wikipedia
# Adapted from Alice Sze's Quicksort benchmark

@main {
zero: int = const 0;
one : int = const 1;
two : int = const 2;
three : int = const 3;
four : int = const 4;
five : int = const 5;
six : int = const 6;

size: int = const 6;
array1: ptr<int> = call @pack size one zero two five three four;
array2: ptr<int> = call @pack size six five four three two one;

size_minus_one: int = sub size one;

array1_done : promise<ptr<int>> = call @qsort array1 zero size_minus_one;
array2_done : promise<ptr<int>> = call @qsort array2 zero size_minus_one;

# Print array
array1_ptr : ptr<int> = resolve array1_done;
array2_ptr : ptr<int> = resolve array2_done;

call @print_array array1 size;
call @print_array array2 size;

free array1;
free array2;
}

@qsort(array : ptr<int>, l: int, r:int) : promise<ptr<int>> {
# if l >= r or r < 0, return
l_ge_r: bool = ge l r;
zero: int = const 0;
neg_r: bool = lt r zero;
ret_cond: bool = or l_ge_r neg_r;

br ret_cond .done .continue;

.continue:
p: int = call @partition array l r;
one: int = const 1;
p_minus_one: int = sub p one;
p_plus_one: int = add p one;

call @qsort array l p_minus_one;
call @qsort array p_plus_one r;

.done:
size : int = const 6;
call @print_array array size
ret array;
}

@partition(array : ptr<int>, l: int, r:int) : int {
# choose the last element as the pivot
pivot_loc: ptr<int> = ptradd array r;
pivot: int = load pivot_loc;
one: int = const 1;
i:int = sub l one;
j:int = id i;

.loop.init:
j:int = add j one;
cond: bool = lt j r;
br cond .body .post.loop;

.body:
j_loc: ptr<int> = ptradd array j;
a_j: int = load j_loc;
swap_cond: bool = le a_j pivot;
br swap_cond .swap .loop.init;

.swap:
# increment i by 1
i: int = add i one;

# swap the current element with the element at the temporary pivot index i
i_loc: ptr<int> = ptradd array i;
a_i: int = load i_loc;
store j_loc a_i;
store i_loc a_j;
jmp .loop.init;

.post.loop:
i:int = add i one;
i_loc: ptr<int> = ptradd array i;
a_i: int = load i_loc;
store i_loc pivot;
store pivot_loc a_i;
ret i;
}

# allocate an array of the given size and pack the input values into the array
@pack(size: int, n1: int, n2: int, n3: int, n4: int, n5: int, n6: int) : ptr<int> {
one: int = const 1;
i: int = const 0;
array: ptr<int> = alloc size;
# Pack data into array manually. Cannot use loop because of the different var name.
loc: ptr<int> = ptradd array i;
store loc n1;
i: int = add i one;
loc: ptr<int> = ptradd array i;
store loc n2;
i: int = add i one;
loc: ptr<int> = ptradd array i;
store loc n3;
i: int = add i one;
loc: ptr<int> = ptradd array i;
store loc n4;
i: int = add i one;
loc: ptr<int> = ptradd array i;
store loc n5;
i: int = add i one;
loc: ptr<int> = ptradd array i;
store loc n6;

ret array;
}

@print_array(array: ptr<int>, size: int) {
i: int = const 0;
one: int = const 1;
.loop:
cond: bool = lt i size;
br cond .body .done;
.body:
loc: ptr<int> = ptradd array i;
val: int = load loc;
print val;
.loop_end:
i: int = add i one;
jmp .loop;
.done:
ret;
}
Loading
Loading