Skip to content

Commit

Permalink
Merge pull request #272 from kevinnegy/main
Browse files Browse the repository at this point in the history
Added dot-product microbenchmark
  • Loading branch information
sampsyo committed Aug 31, 2023
2 parents 2627b76 + 2b42e58 commit d1b8729
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 0 deletions.
65 changes: 65 additions & 0 deletions benchmarks/core/dot-product.bril
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
@dot_product(vectorA: ptr<int>, vectorB: ptr<int>, size: int): int {
one: int = const 1;
index: int = const 0;
answer: int = const 0;
.loop:
ptrA: ptr<int> = ptradd vectorA index;
ptrB: ptr<int> = ptradd vectorB index;
valA: int = load ptrA;
valB: int = load ptrB;
tmp: int = mul valA valB;
answer: int = add answer tmp;
index: int = add index one;
cond: bool = lt index size;
br cond .loop .done;
.done:
ret answer;
}

@main {
a: int = const 25;
b: int = const 50;
c: int = const 100;
d: int = const 150;
e: int = const 250;
f: int = const 2;
g: int = const 10;
h: int = const 20;
i: int = const 30;
j: int = const 40;
one: int = const 1;
zero: int = const 0;
size: int = const 5;

# Create and fill vectorA
vectorA: ptr<int> = alloc size;
indexPtr: ptr<int> = ptradd vectorA zero;
store indexPtr a;
indexPtr: ptr<int> = ptradd indexPtr one;
store indexPtr b;
indexPtr: ptr<int> = ptradd indexPtr one;
store indexPtr c;
indexPtr: ptr<int> = ptradd indexPtr one;
store indexPtr d;
indexPtr: ptr<int> = ptradd indexPtr one;
store indexPtr e;

# Create and fill vectorB
vectorB: ptr<int> = alloc size;
indexPtr: ptr<int> = ptradd vectorB zero;
store indexPtr f;
indexPtr: ptr<int> = ptradd indexPtr one;
store indexPtr g;
indexPtr: ptr<int> = ptradd indexPtr one;
store indexPtr h;
indexPtr: ptr<int> = ptradd indexPtr one;
store indexPtr i;
indexPtr: ptr<int> = ptradd indexPtr one;
store indexPtr j;

val: int = call @dot_product vectorA vectorB size;
print val;

free vectorA;
free vectorB;
}
1 change: 1 addition & 0 deletions benchmarks/core/dot-product.out
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
17050
1 change: 1 addition & 0 deletions benchmarks/core/dot-product.prof
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
total_dyn_inst: 88
1 change: 1 addition & 0 deletions docs/tools/bench.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ The current benchmarks are:
* `conjugate-gradient`: Uses conjugate gradients to solve `Ax=b` for any arbitrary positive semidefinite `A`.
* `cordic`: Print an approximation of sine(radians) using 8 iterations of the [CORDIC algorithm](https://en.wikipedia.org/wiki/CORDIC).
* `digial-root`: Computes the digital root of the input number.
* `dot-product`: Computes the dot product of two vectors.
* `eight-queens`: Counts the number of solutions for *n* queens problem, a generalization of [Eight queens puzzle][eight_queens].
* `euclid`: Calculates the greatest common divisor between two large numbers using the [Euclidean Algorithm][euclid] with a helper function for the modulo operator.
* `euler`: Approximates [Euler's number][euler] using the Taylor series.
Expand Down

0 comments on commit d1b8729

Please sign in to comment.