-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
cfebc86
commit c961822
Showing
3 changed files
with
102 additions
and
0 deletions.
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
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, | ||
{ | ||
|
||
} |
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,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() |
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,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}; | ||
|
||
} |