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 01a6581
Show file tree
Hide file tree
Showing 10 changed files with 114 additions and 95 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
4 changes: 2 additions & 2 deletions software/runtime/data/data_cholesky_f16.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@
import numpy as np
import argparse
import pathlib
from scipy.linalg import solve_triangular
from mako.template import Template


##################
# 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
10 changes: 6 additions & 4 deletions software/runtime/data/data_cholesky_q16.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import numpy as np
import argparse
import pathlib
from scipy.linalg import solve_triangular
from mako.template import Template


Expand All @@ -19,7 +18,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 +81,10 @@ 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)
H = H.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
35 changes: 18 additions & 17 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[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)

kwargs = {'name': 'data_mimo_mmse_f16',
'H': H_RI,
Expand Down
33 changes: 17 additions & 16 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[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))

kwargs = {'name': 'data_mimo_mmse_f32',
'H': H_RI,
Expand Down
48 changes: 26 additions & 22 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 All @@ -32,12 +33,13 @@ def gen_data_header_file(outdir: pathlib.Path.cwd(), tpl: pathlib.Path.cwd(), **
def gen_input_data(N_rx, N_tx):

# Create channel matrix
H = np.random.randint(-2**(15), 2**(15) - 1, N_rx * N_tx, dtype=np.int16) + 1.j * \
np.random.randint(-2**(15), 2**(15) - 1, N_rx * N_tx, dtype=np.int16)
H = np.random.randint(-2**(15), 2**(15) - 1, N_rx * N_tx, dtype=np.int16) + \
1.j * np.random.randint(-2**(15), 2**(15) - 1,
N_rx * N_tx, dtype=np.int16)
H = H.reshape(N_rx, N_tx)
# Create input vector
y = np.random.randint(-2**(15), 2**(15) - 1, N_rx, dtype=np.int16) + 1.j * \
np.random.randint(-2**(15), 2**(15) - 1, N_rx, dtype=np.int16)
y = np.random.randint(-2**(15), 2**(15) - 1, N_rx, dtype=np.int16) + \
1.j * np.random.randint(-2**(15), 2**(15) - 1, N_rx, dtype=np.int16)
# Generate noise variance
sigma = np.random.randint(-2**(15), 2**(15) - 1, N_tx, dtype=np.int16)

Expand All @@ -50,17 +52,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 +130,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
Loading

0 comments on commit 01a6581

Please sign in to comment.