Skip to content

Commit

Permalink
[software] Format the data generation scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
mbertuletti committed Jan 8, 2024
1 parent 01d9fd2 commit 763369e
Show file tree
Hide file tree
Showing 10 changed files with 99 additions and 80 deletions.
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ toolchain/riscv-opcodes/*:

format:
$(ROOT_DIR)/scripts/run_clang_format.py --clang-format-executable=$(LLVM_INSTALL_DIR)/bin/clang-format -i -r $(ROOT_DIR)
find ./software/runtime/data -name '*.py' -exec autopep8 --in-place --aggressive {} +

clean: clean_test
rm -rf $(INSTALL_DIR)
1 change: 0 additions & 1 deletion software/runtime/data/data_chest_f16.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,6 @@ def main():
vector_pilot_rx = np.concatenate(vector_pilot_rx, axis=0)
vector_pilot_tx = np.concatenate(vector_pilot_tx, axis=0)
vector_Hest = np.concatenate(vector_Hest, axis=0)
print(vector_Hest)

kwargs = {'name': 'data_chest_f16',
'pilot_rx': vector_pilot_rx,
Expand Down
3 changes: 2 additions & 1 deletion software/runtime/data/data_cholesky_f16.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
# compute_result #
##################

def gen_data_header_file(outdir: pathlib.Path.cwd(), tpl: pathlib.Path.cwd(), **kwargs):
def gen_data_header_file(outdir: pathlib.Path.cwd(),
tpl: pathlib.Path.cwd(), **kwargs):

file = outdir / f"{kwargs['name']}.h"

Expand Down
7 changes: 4 additions & 3 deletions software/runtime/data/data_cholesky_q16.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
##################


def gen_data_header_file(outdir: pathlib.Path.cwd(), tpl: pathlib.Path.cwd(), **kwargs):
def gen_data_header_file(outdir: pathlib.Path.cwd(),
tpl: pathlib.Path.cwd(), **kwargs):

file = outdir / f"{kwargs['name']}.h"

Expand Down Expand Up @@ -81,8 +82,8 @@ def main():
vector_L = []
for k in range(n_samples):
# Create hermitian matrix
H = (np.random.randint(-2**(15), 2**(15) - 1, n_matrix * n_matrix, dtype=np.int16) + 1.j * \
np.random.randint(-2**(15), 2**(15) - 1, n_matrix * n_matrix, dtype=np.int16)).reshape(n_matrix, n_matrix)
H = (np.random.randint(-2**(15), 2**(15) - 1, n_matrix * n_matrix, dtype=np.int16) + 1.j *
np.random.randint(-2**(15), 2**(15) - 1, n_matrix * n_matrix, dtype=np.int16)).reshape(n_matrix, n_matrix)
# Matrix to be inverted
H_h = (np.asmatrix(H).H)
# H_H = np.asmatrix(H).H
Expand Down
30 changes: 19 additions & 11 deletions software/runtime/data/data_cholesky_q32.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
# compute_result #
##################

def gen_data_header_file(outdir: pathlib.Path.cwd(), tpl: pathlib.Path.cwd(), **kwargs):
def gen_data_header_file(outdir: pathlib.Path.cwd(),
tpl: pathlib.Path.cwd(), **kwargs):

file = outdir / f"{kwargs['name']}.h"

Expand Down Expand Up @@ -68,24 +69,30 @@ def main():
n_matrix = args.dimension

# Create hermitian matrix
H = np.random.randint(-2**(15), 2**(15) - 1, n_matrix * n_matrix, dtype=np.int32)
y = np.random.randint(-2**(15), 2**(15) - 1, n_matrix, dtype=np.int32)
L = np.random.randint(-2**(15), 2**(15) - 1,
size=(n_matrix, n_matrix), dtype=np.int32)
L = np.tril(L).astype(np.int32)
G = np.dot(np.asmatrix(L), np.asmatrix(L).transpose())

H = H.reshape(n_matrix, n_matrix)
G = H * np.asmatrix(H).T
# Cholesky decomposition
L = np.linalg.cholesky(G)
y = np.random.randint(-2**(15), 2**(15) - 1, n_matrix, dtype=np.int32)

# Linear system solution
y = solve_triangular(L, y, lower=True)
x = solve_triangular(np.asmatrix(L).H, y)
x = solve_triangular(np.asmatrix(L).T, y)

# Reshape
G = np.reshape(np.asarray(G), (n_matrix * n_matrix), order='C').astype(np.int32)
L = np.reshape(np.asarray(L), (n_matrix * n_matrix), order='C').astype(np.int32)
G = np.reshape(
np.asarray(G),
(n_matrix * n_matrix),
order='C').astype(
np.int32)
L = np.reshape(
np.asarray(L),
(n_matrix * n_matrix),
order='C').astype(
np.int32)
y = np.reshape(np.asarray(y), (n_matrix), order='C').astype(np.int32)


kwargs = {'name': 'data_cholesky_q32',
'G': G,
'L': L,
Expand All @@ -94,5 +101,6 @@ def main():

gen_data_header_file(args.outdir, args.tpl, **kwargs)


if __name__ == "__main__":
main()
1 change: 0 additions & 1 deletion software/runtime/data/data_cmatmul_f16.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,6 @@ def main():
A = np.reshape(A, (matrix_M * matrix_N), order='C')
B = np.reshape(B, (matrix_N * matrix_P), order='C')
C = np.reshape(C, (matrix_M * matrix_P), order='C')
print(A)

A = np.column_stack((A.real, A.imag)).astype(np.float16).flatten()
B = np.column_stack((B.real, B.imag)).astype(np.float16).flatten()
Expand Down
29 changes: 15 additions & 14 deletions software/runtime/data/data_mimo_mmse_f16.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
# compute_result #
##################

def gen_data_header_file(outdir: pathlib.Path.cwd(), tpl: pathlib.Path.cwd(), **kwargs):
def gen_data_header_file(outdir: pathlib.Path.cwd(),
tpl: pathlib.Path.cwd(), **kwargs):

file = outdir / f"{kwargs['name']}.h"

Expand Down Expand Up @@ -52,9 +53,9 @@ def gen_input_data(N_rx, N_tx):
x = solve_triangular(np.asmatrix(L).H, y2)

sigma = sigma + 0j
H = np.reshape(np.asarray(H), (N_tx*N_rx), order='C')
G = np.reshape(np.asarray(G), (N_tx*N_tx), order='C')
L = np.reshape(np.asarray(L), (N_tx*N_tx), order='C')
H = np.reshape(np.asarray(H), (N_tx * N_rx), order='C')
G = np.reshape(np.asarray(G), (N_tx * N_tx), order='C')
L = np.reshape(np.asarray(L), (N_tx * N_tx), order='C')
sigma = np.column_stack((sigma.real, sigma.imag)
).astype(np.float16).flatten()
H = np.column_stack((H.real, H.imag)).astype(np.float16).flatten()
Expand Down Expand Up @@ -123,20 +124,20 @@ def main():
N_rx = args.receivers
itr = args.iterations

sigma = np.zeros([itr, 2*N_tx])
H_RI = np.zeros([itr, 2*N_tx*N_rx])
G_RI = np.zeros([itr, 2*N_tx*N_tx])
y_RI = np.zeros([itr, 2*N_rx])
x_RI = np.zeros([itr, 2*N_tx])
sigma = np.zeros([itr, 2 * N_tx])
H_RI = np.zeros([itr, 2 * N_tx * N_rx])
G_RI = np.zeros([itr, 2 * N_tx * N_tx])
y_RI = np.zeros([itr, 2 * N_rx])
x_RI = np.zeros([itr, 2 * N_tx])
for k in range(itr):
sigma[k, :], H_RI[k, :], G_RI[k, :], y_RI[k,
:], x_RI[k, :] = gen_input_data(N_rx, N_tx)

sigma = np.reshape(sigma, (2*N_tx*itr)).astype(np.float16)
H_RI = np.reshape(H_RI, (2*N_rx*N_tx*itr)).astype(np.float16)
G_RI = np.reshape(G_RI, (2*N_tx*N_tx*itr)).astype(np.float16)
y_RI = np.reshape(y_RI, (2*N_rx*itr)).astype(np.float16)
x_RI = np.reshape(x_RI, (2*N_tx*itr)).astype(np.float16)
sigma = np.reshape(sigma, (2 * N_tx * itr)).astype(np.float16)
H_RI = np.reshape(H_RI, (2 * N_rx * N_tx * itr)).astype(np.float16)
G_RI = np.reshape(G_RI, (2 * N_tx * N_tx * itr)).astype(np.float16)
y_RI = np.reshape(y_RI, (2 * N_rx * itr)).astype(np.float16)
x_RI = np.reshape(x_RI, (2 * N_tx * itr)).astype(np.float16)

kwargs = {'name': 'data_mimo_mmse_f16',
'H': H_RI,
Expand Down
27 changes: 14 additions & 13 deletions software/runtime/data/data_mimo_mmse_f32.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
# compute_result #
##################

def gen_data_header_file(outdir: pathlib.Path.cwd(), tpl: pathlib.Path.cwd(), **kwargs):
def gen_data_header_file(outdir: pathlib.Path.cwd(),
tpl: pathlib.Path.cwd(), **kwargs):

file = outdir / f"{kwargs['name']}.h"

Expand Down Expand Up @@ -52,9 +53,9 @@ def gen_input_data(N_rx, N_tx):
y2 = solve_triangular(L, y1, lower=True)
x = solve_triangular(np.asmatrix(L).H, y2)

H = np.reshape(np.asarray(H), (N_tx*N_rx), order='C')
G = np.reshape(np.asarray(G), (N_tx*N_tx), order='C')
L = np.reshape(np.asarray(L), (N_tx*N_tx), order='C')
H = np.reshape(np.asarray(H), (N_tx * N_rx), order='C')
G = np.reshape(np.asarray(G), (N_tx * N_tx), order='C')
L = np.reshape(np.asarray(L), (N_tx * N_tx), order='C')
H = np.column_stack((H.real, H.imag)).astype(np.float32).flatten()
G = np.column_stack((G.real, G.imag)).astype(np.float32).flatten()
L = np.column_stack((L.real, L.imag)).astype(np.float32).flatten()
Expand Down Expand Up @@ -122,19 +123,19 @@ def main():
itr = args.iterations

sigma = np.zeros([itr, N_tx])
H_RI = np.zeros([itr, 2*N_tx*N_rx])
G_RI = np.zeros([itr, 2*N_tx*N_tx])
y_RI = np.zeros([itr, 2*N_rx])
x_RI = np.zeros([itr, 2*N_tx])
H_RI = np.zeros([itr, 2 * N_tx * N_rx])
G_RI = np.zeros([itr, 2 * N_tx * N_tx])
y_RI = np.zeros([itr, 2 * N_rx])
x_RI = np.zeros([itr, 2 * N_tx])
for k in range(itr):
sigma[k, :], H_RI[k, :], G_RI[k, :], y_RI[k,
:], x_RI[k, :] = gen_input_data(N_rx, N_tx)

sigma = np.reshape(sigma, (N_tx*itr))
H_RI = np.reshape(H_RI, (2*N_rx*N_tx*itr))
G_RI = np.reshape(G_RI, (2*N_tx*N_tx*itr))
y_RI = np.reshape(y_RI, (2*N_rx*itr))
x_RI = np.reshape(x_RI, (2*N_tx*itr))
sigma = np.reshape(sigma, (N_tx * itr))
H_RI = np.reshape(H_RI, (2 * N_rx * N_tx * itr))
G_RI = np.reshape(G_RI, (2 * N_tx * N_tx * itr))
y_RI = np.reshape(y_RI, (2 * N_rx * itr))
x_RI = np.reshape(x_RI, (2 * N_tx * itr))

kwargs = {'name': 'data_mimo_mmse_f32',
'H': H_RI,
Expand Down
39 changes: 21 additions & 18 deletions software/runtime/data/data_mimo_mmse_q16.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
# compute_result #
##################

def gen_data_header_file(outdir: pathlib.Path.cwd(), tpl: pathlib.Path.cwd(), **kwargs):
def gen_data_header_file(outdir: pathlib.Path.cwd(),
tpl: pathlib.Path.cwd(), **kwargs):

file = outdir / f"{kwargs['name']}.h"

Expand Down Expand Up @@ -50,17 +51,19 @@ def gen_input_data(N_rx, N_tx):
y1 = np.transpose(np.dot(H_h, y))

# Cholesky decomposition
#L = np.linalg.cholesky(G)
# L = np.linalg.cholesky(G)
L = G
# Linear system solution
y2 = solve_triangular(L, y1, lower=True)
x = solve_triangular(np.asmatrix(L).H, y2)

sigma = sigma + 0j
H = np.reshape(np.asarray(H), (N_rx*N_tx), order='C')
G = np.reshape(np.asarray(G), (N_tx*N_tx), order='C')
L = np.reshape(np.asarray(L), (N_tx*N_tx), order='C')
sigma = np.column_stack((sigma.real, sigma.imag)).astype(np.int16).flatten()
H = np.reshape(np.asarray(H), (N_rx * N_tx), order='C')
G = np.reshape(np.asarray(G), (N_tx * N_tx), order='C')
L = np.reshape(np.asarray(L), (N_tx * N_tx), order='C')
sigma = np.column_stack(
(sigma.real, sigma.imag)).astype(
np.int16).flatten()
H = np.column_stack((H.real, H.imag)).astype(np.int16).flatten()
G = np.column_stack((G.real, G.imag)).astype(np.int16).flatten()
L = np.column_stack((L.real, L.imag)).astype(np.int16).flatten()
Expand Down Expand Up @@ -126,23 +129,23 @@ def main():
N_rx = args.receivers
itr = args.iterations

sigma = np.zeros([itr, 2*N_tx], dtype=np.int16)
H_RI = np.zeros([itr, 2*N_tx*N_rx], dtype=np.int16)
G_RI = np.zeros([itr, 2*N_tx*N_tx], dtype=np.int16)
y_RI = np.zeros([itr, 2*N_rx], dtype=np.int16)
x_RI = np.zeros([itr, 2*N_tx], dtype=np.int16)
sigma = np.zeros([itr, 2 * N_tx], dtype=np.int16)
H_RI = np.zeros([itr, 2 * N_tx * N_rx], dtype=np.int16)
G_RI = np.zeros([itr, 2 * N_tx * N_tx], dtype=np.int16)
y_RI = np.zeros([itr, 2 * N_rx], dtype=np.int16)
x_RI = np.zeros([itr, 2 * N_tx], dtype=np.int16)
for k in range(itr):
[ sigma[k, :],
[sigma[k, :],
H_RI[k, :],
G_RI[k, :],
y_RI[k, :],
x_RI[k, :] ] = gen_input_data(N_rx, N_tx)
x_RI[k, :]] = gen_input_data(N_rx, N_tx)

sigma = np.reshape(sigma, (2*N_tx*itr)).astype(np.int16)
H_RI = np.reshape(H_RI, (2*N_rx*N_tx*itr)).astype(np.int16)
G_RI = np.reshape(G_RI, (2*N_tx*N_tx*itr)).astype(np.int16)
y_RI = np.reshape(y_RI, (2*N_rx*itr)).astype(np.int16)
x_RI = np.reshape(x_RI, (2*N_tx*itr)).astype(np.int16)
sigma = np.reshape(sigma, (2 * N_tx * itr)).astype(np.int16)
H_RI = np.reshape(H_RI, (2 * N_rx * N_tx * itr)).astype(np.int16)
G_RI = np.reshape(G_RI, (2 * N_tx * N_tx * itr)).astype(np.int16)
y_RI = np.reshape(y_RI, (2 * N_rx * itr)).astype(np.int16)
x_RI = np.reshape(x_RI, (2 * N_tx * itr)).astype(np.int16)

kwargs = {'name': 'data_mimo_mmse_q16',
'H': H_RI,
Expand Down
41 changes: 23 additions & 18 deletions software/runtime/data/data_ofdm.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
# compute_result #
##################


def compute_bitreversal(N, R):
# Decompose
logR2 = []
Expand All @@ -44,7 +45,9 @@ def compute_bitreversal(N, R):
tps.append([c[i] * 8, c[-1] * 8])
return tps

def gen_data_header_file(outdir: pathlib.Path.cwd(), tpl: pathlib.Path.cwd(), **kwargs):

def gen_data_header_file(outdir: pathlib.Path.cwd(),
tpl: pathlib.Path.cwd(), **kwargs):

file = outdir / f"data_{kwargs['name']}.h"

Expand All @@ -54,6 +57,7 @@ def gen_data_header_file(outdir: pathlib.Path.cwd(), tpl: pathlib.Path.cwd(), **
with file.open('w') as f:
f.write(template.render(**kwargs))


def main():

parser = argparse.ArgumentParser(description='Generate data for kernels')
Expand Down Expand Up @@ -105,29 +109,30 @@ def main():
)

args = parser.parse_args()
N_rx=args.receivers
N_bs=args.beams
N_sc=args.subcarriers
N_rx = args.receivers
N_bs = args.beams
N_sc = args.subcarriers

pFFT_src = ( np.random.rand(2 * N_rx * N_sc) ).astype(np.float16)
pTw_coef = ( np.random.rand(int(3 * N_sc / 4)) ).astype(np.float16)
pBF_coef = ( np.random.rand(2 * N_rx * N_bs) ).astype(np.float16)
pBF_dst = ( np.random.rand(2 * N_bs * N_sc) ).astype(np.float16)
pFFT_src = (np.random.rand(2 * N_rx * N_sc)).astype(np.float16)
pTw_coef = (np.random.rand(int(3 * N_sc / 4))).astype(np.float16)
pBF_coef = (np.random.rand(2 * N_rx * N_bs)).astype(np.float16)
pBF_dst = (np.random.rand(2 * N_bs * N_sc)).astype(np.float16)

Bitreversal = np.ndarray.flatten(np.array(compute_bitreversal(N_sc, 2)))

kwargs = {'name': 'ofdm',
'pFFT_src': pFFT_src,
'pTw_coef': pTw_coef,
'pBF_coef': pBF_coef,
'pBF_dst': pBF_dst,
'bitrev': Bitreversal,
'N_rx' : N_rx,
'N_bs' : N_bs,
'N_sc' : N_sc,
'Log2Len': int(np.log2(N_sc)),
'BitrevLen': len(Bitreversal)}
'pFFT_src': pFFT_src,
'pTw_coef': pTw_coef,
'pBF_coef': pBF_coef,
'pBF_dst': pBF_dst,
'bitrev': Bitreversal,
'N_rx': N_rx,
'N_bs': N_bs,
'N_sc': N_sc,
'Log2Len': int(np.log2(N_sc)),
'BitrevLen': len(Bitreversal)}
gen_data_header_file(args.outdir, args.tpl, **kwargs)


if __name__ == "__main__":
main()

0 comments on commit 763369e

Please sign in to comment.