Skip to content

Commit

Permalink
begin
Browse files Browse the repository at this point in the history
  • Loading branch information
gabizon103 committed May 29, 2024
1 parent cfebc86 commit c961822
Show file tree
Hide file tree
Showing 3 changed files with 102 additions and 0 deletions.
21 changes: 21 additions & 0 deletions apps/blas/gemv/gemv.fil
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import "apps/blas/util.fil";

comp Gemv[W, M, N, MultsN, AddsN]<'G:II>(
go: interface['G],
alpha: ['G, 'G+1] W,
beta: ['G, 'G+1] W,
A[M][N]: ['G, 'G+1] W
x[N]: ['G, 'G+1] W,
y[M]: ['G, 'G+1] W
) -> (
y_out[M]: ['G+L, 'G+L+1] W
) with {
some L where L > 0;
some II where II > 0;
} where W > 0,
N > 0,
M > 0,
MultsN > 0,
{

}
23 changes: 23 additions & 0 deletions apps/blas/gemv/gemv.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
from functools import reduce
from itertools import chain

"""
For interop with fud, we represent matrices as integers.
The matrix [[1 2],[3 4]] gets flattened to [1,2,3,4]. Each int gets
converted to binary and concatenated, which is then interpreted as a
single integer.
matrix: the matrix to convert to an integer
width: desired bitwidth of each integer in the matrix
"""
def matrix_to_int_repr(matrix, width):
flattened = list(chain.from_iterable(matrix))
bin_str = reduce(lambda acc, i: acc + bin(i)[2:].zfill(width), flattened, "")
print(int(bin_str, 2))


def main():
matrix_to_int_repr([[1,2],[3,4]], 4)

if __name__ == "__main__":
main()
58 changes: 58 additions & 0 deletions apps/blas/gemv/gemv_comb.fil
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import "apps/blas/util.fil";

// Combinational gemv kernel that uses M*N multipliers
comp Gemv_Comb[W, M, N]<'G:II>(
go: interface['G],
alpha: ['G, 'G+1] W,
beta: ['G, 'G+1] W,
A[M][N]: ['G, 'G+1] W
x[N]: ['G, 'G+1] W,
y[M]: ['G, 'G+1] W
) -> (
y_out[M]: ['G, 'G+1] W
) with {
some L;
some II;
} where W > 0,
N > 0,
M > 0,
MultsN > 0,
{
II := 1;
L := 0;

bundle alpha_bundle[N]: ['G, 'G+1] W;
bundle alpha_A[M][N]: ['G, 'G+1] W;

for i in 0..N {
alpha_bundle{i} = alpha;
}

// do alpha * A
for i in 0..M {
Mults1 := new MultipliersComb[W, N]<'G>(alpha_bundle{0..N}, A{i}{0..N})
alpha_A{i}{0..N} = Mults1.out{0..N};
}

bundle mv_prod[M][N]: ['G, 'G+1] W;

// do alpha*A * x
for i in 0..M {
Mults2 := new MultipliersComb[W, N]<'G>(alpha_A{i}{0..N}, x{0..N})
mv_prod{i}{0..N} = Mults2.out;
}

// do adds for dot prods

// do beta*y
bundle beta_bundle[M]: ['G, 'G+1] W;
bundle beta_y[M]: ['G, 'G+1] W:

for i in 0..M {
beta_bundle{i} = beta;
}

Mults3 := new MultipliersComb[W, M]<'G>(beta_bundle{0..M}, y{0..M});
beta_y{0..M} = Mults3.out{0..M};

}

0 comments on commit c961822

Please sign in to comment.