Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
#!/usr/bin/env python
from __future__ import print_function
import gc
import argparse
import dace
import numpy as np
import dace.frontend.common as np_frontend
import os
from timeit import default_timer as timer
SDFG = dace.sdfg.SDFG
M = dace.symbol('M')
N = dace.symbol('N')
K = dace.symbol('K')
A = dace.ndarray([3, 7, 9, M, N], dtype=dace.float64)
B = dace.ndarray([2, 5, 8, 4, N, K], dtype=dace.float64)
C = dace.ndarray([3, 3, M, K], dtype=dace.float64)
if __name__ == "__main__":
print("==== Program start ====")
parser = argparse.ArgumentParser()
parser.add_argument("M", type=int, nargs="?", default=128)
parser.add_argument("N", type=int, nargs="?", default=128)
parser.add_argument("K", type=int, nargs="?", default=128)
args = vars(parser.parse_args())
M.set(args["M"])
#!/usr/bin/env python
from __future__ import print_function
import argparse
import dace
import numpy as np
M = dace.symbol('M')
K = dace.symbol('K')
N = dace.symbol('N')
@dace.program(dace.float64[M, K], dace.float64[K, N], dace.float64[M, N])
def gemm(A, B, C):
# Transient variable
tmp = dace.define_local([M, N, K], dtype=A.dtype)
@dace.map(_[0:M, 0:N, 0:K])
def multiplication(i, j, k):
in_A << A[i, k]
in_B << B[k, j]
out >> tmp[i, j, k]
out = in_A * in_B
#!/usr/bin/env python
import argparse
import dace
import numpy as np
import scipy as sp
N = dace.symbol('N')
@dace.program(dace.float64, dace.float64[N], dace.float64[N])
def axpy(A, X, Y):
@dace.map(_[0:N])
def multiplication(i):
in_A << A
in_X << X[i]
in_Y << Y[i]
out >> Y[i]
out = in_A * in_X + in_Y
if __name__ == "__main__":
print("==== Program start ====")
import argparse
import dace
import numpy as np
import pdb
import select
import sys
N = dace.symbol('N')
M = dace.symbol('M')
K = dace.symbol('K')
def make_copy_to_fpga_state(sdfg):
###########################################################################
# Copy data to FPGA
state = sdfg.add_state("copy_to_device")
A_host = state.add_array("A", [N, K], dtype=dace.float32)
B_host = state.add_array("B", [K, M], dtype=dace.float32)
C_host = state.add_array("C", [N, M], dtype=dace.float32)
A_device = state.add_array("A_device", [N, K],
#!/usr/bin/env python
from __future__ import print_function
import argparse
import dace
import math
import numpy as np
from dace import SDFG, Memlet, EmptyMemlet
from dace.dtypes import StorageType, ScheduleType
from dace.subsets import Indices
W = dace.symbol("W")
H = dace.symbol("H")
P = dace.symbol("P")
num_bins = dace.symbol("num_bins")
num_bins.set(256)
dtype = dace.float32
itype = dace.uint32
def make_copy_to_fpga_state(sdfg):
state = sdfg.add_state("copy_to_fpga")
a_host = state.add_array("A", (H, W), dtype)
a_device = state.add_array(
"A_device", (H, W),
dtype,
transient=True,
storage=dace.dtypes.StorageType.FPGA_Global)
import math
import dace
import polybench
M = dace.symbol('M')
N = dace.symbol('N')
#datatypes = [dace.float64, dace.int32, dace.float32]
datatype = dace.float64
# Dataset sizes
sizes = [{
M: 28,
N: 32
}, {
M: 80,
N: 100
}, {
M: 240,
N: 260
}, {
#!/usr/bin/env python
from __future__ import print_function
import argparse
import dace
import numpy as np
import select
import sys
from scipy import ndimage
W = dace.symbol("W")
H = dace.symbol("H")
T = dace.symbol("T")
P = dace.symbol("P") # Number of processing elements
dtype = dace.float32
def add_tmp(state):
return state.add_array("tmp", (2, H, W),
dtype,
transient=True,
storage=dace.dtypes.StorageType.FPGA_Global)
def make_init_state(sdfg):
state = sdfg.add_state("init")
#!/usr/bin/env python
from __future__ import print_function
import argparse
import dace
import math
import numpy as np
import scipy
W = dace.symbol('W')
H = dace.symbol('H')
nnz = dace.symbol('nnz')
@dace.program(dace.uint32[H + 1], dace.uint32[nnz], dace.float32[nnz],
dace.float32[W], dace.float32[H])
def spmv(A_row, A_col, A_val, x, b):
@dace.mapscope(_[0:H])
def compute_row(i):
@dace.map(_[A_row[i]:A_row[i + 1]])
def compute(j):
a << A_val[j]
in_x << x[A_col[j]]
out >> b(1, lambda x, y: x + y)[i]
out = a * in_x
#!/usr/bin/env python
from __future__ import print_function
import argparse
import dace
import numpy as np
from scipy import ndimage
W = dace.symbol('W')
H = dace.symbol('H')
MAXITER = dace.symbol('MAXITER')
@dace.program(dace.float32[H, W], dace.int32)
def jacobi(A, iterations):
# Transient variable
tmp = dace.define_local([H, W], dtype=A.dtype)
@dace.map(_[0:H, 0:W])
def reset_tmp(y, x):
out >> tmp[y, x]
out = dace.float32(0.0)
for t in range(iterations):
#!/usr/bin/env python
from __future__ import print_function
import argparse
import dace
import math
import numpy as np
W = dace.symbol('W')
H = dace.symbol('H')
BINS = 256 # dace.symbol('BINS')
@dace.program(dace.uint8[H, W], dace.uint32[BINS])
def histogram(A, hist):
# Declarative version
tmp = dace.define_local([BINS, H, W], dace.uint32)
@dace.map(_[0:BINS, 0:H, 0:W])
def zero_tmp(b, i, j):
t >> tmp[b, i, j]
t = 0
@dace.map(_[0:H, 0:W])
def compute_declarative(i, j):
a << A[i, j]