Skip to content

Commit

Permalink
sw: Uniformize data_utils import
Browse files Browse the repository at this point in the history
  • Loading branch information
colluca committed Aug 28, 2024
1 parent bdfa4be commit 8ce7b91
Show file tree
Hide file tree
Showing 8 changed files with 60 additions and 74 deletions.
18 changes: 8 additions & 10 deletions sw/apps/atax/scripts/datagen.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,14 @@
import numpy as np

import snitch.util.sim.data_utils as du
from snitch.util.sim.data_utils import format_scalar_definition, format_array_definition, \
format_array_declaration, format_ifdef_wrapper, DataGen


# AXI splits bursts crossing 4KB address boundaries. To minimize
# the occurrence of these splits the data should be aligned to 4KB
BURST_ALIGNMENT = 4096


class AtaxDataGen(DataGen):
class AtaxDataGen(du.DataGen):

def golden_model(self, A, x):
return np.matmul(A.transpose(), np.matmul(A, x))
Expand All @@ -38,13 +36,13 @@ def emit_header(self, **kwargs):
x = x.flatten()
y = y.flatten()

header += [format_scalar_definition('uint32_t', 'M', M)]
header += [format_scalar_definition('uint32_t', 'N', N)]
header += [format_array_definition('double', 'A', A, alignment=BURST_ALIGNMENT)]
header += [format_array_definition('double', 'x', x, alignment=BURST_ALIGNMENT)]
header += [format_array_declaration('double', 'y', y.shape, alignment=BURST_ALIGNMENT)]
result_def = format_array_definition('double', 'golden', y, alignment=BURST_ALIGNMENT)
header += [format_ifdef_wrapper('BIST', result_def)]
header += [du.format_scalar_definition('uint32_t', 'M', M)]
header += [du.format_scalar_definition('uint32_t', 'N', N)]
header += [du.format_array_definition('double', 'A', A, alignment=BURST_ALIGNMENT)]
header += [du.format_array_definition('double', 'x', x, alignment=BURST_ALIGNMENT)]
header += [du.format_array_declaration('double', 'y', y.shape, alignment=BURST_ALIGNMENT)]
result_def = du.format_array_definition('double', 'golden', y, alignment=BURST_ALIGNMENT)
header += [du.format_ifdef_wrapper('BIST', result_def)]
header = '\n\n'.join(header)

return header
Expand Down
19 changes: 9 additions & 10 deletions sw/apps/correlation/scripts/datagen.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,14 @@
import numpy as np

import snitch.util.sim.data_utils as du
from snitch.util.sim.data_utils import format_scalar_definition, format_array_definition, \
format_array_declaration, format_ifdef_wrapper, DataGen


# AXI splits bursts crossing 4KB address boundaries. To minimize
# the occurrence of these splits the data should be aligned to 4KB
BURST_ALIGNMENT = 4096


class CorrelationDataGen(DataGen):
class CorrelationDataGen(du.DataGen):

def golden_model(self, data):
return np.corrcoef(data, rowvar=False)
Expand All @@ -33,13 +31,14 @@ def emit_header(self, **kwargs):
data = data.flatten()
corr = corr.flatten()

header += [format_scalar_definition('uint32_t', 'M', M)]
header += [format_scalar_definition('uint32_t', 'N', N)]
header += [format_array_definition('double', 'data', data, alignment=BURST_ALIGNMENT)]
header += [format_array_declaration('double', 'corr', corr.shape,
alignment=BURST_ALIGNMENT)]
result_def = format_array_definition('double', 'golden', corr, alignment=BURST_ALIGNMENT)
header += [format_ifdef_wrapper('BIST', result_def)]
header += [du.format_scalar_definition('uint32_t', 'M', M)]
header += [du.format_scalar_definition('uint32_t', 'N', N)]
header += [du.format_array_definition('double', 'data', data, alignment=BURST_ALIGNMENT)]
header += [du.format_array_declaration('double', 'corr', corr.shape,
alignment=BURST_ALIGNMENT)]
result_def = du.format_array_definition('double', 'golden', corr,
alignment=BURST_ALIGNMENT)
header += [du.format_ifdef_wrapper('BIST', result_def)]
header = '\n\n'.join(header)

return header
Expand Down
10 changes: 4 additions & 6 deletions sw/apps/covariance/scripts/datagen.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,13 @@
import numpy as np

import snitch.util.sim.data_utils as du
from snitch.util.sim.data_utils import format_array_definition, \
format_array_declaration, format_struct_definition, DataGen

np.random.seed(42)

DOUBLE_BUFFER = True


class CovarianceDataGen(DataGen):
class CovarianceDataGen(du.DataGen):

# Function pointers to alternative implementations
FUNCPTRS = ["covariance_naive", "covariance_baseline", "covariance_opt"]
Expand Down Expand Up @@ -69,9 +67,9 @@ def emit_header(self, **kwargs):
'funcptr': kwargs['funcptr']
}

header += [format_array_definition('double', data_uid, data)]
header += [format_array_declaration('double', cov_uid, cov.shape)]
header += [format_struct_definition('covariance_args_t', 'args', cfg)]
header += [du.format_array_definition('double', data_uid, data)]
header += [du.format_array_declaration('double', cov_uid, cov.shape)]
header += [du.format_struct_definition('covariance_args_t', 'args', cfg)]
header = '\n\n'.join(header)

return header
Expand Down
9 changes: 4 additions & 5 deletions sw/apps/doitgen/scripts/datagen.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,13 @@
import numpy as np

import snitch.util.sim.data_utils as du
from snitch.util.sim.data_utils import format_array_definition, format_struct_definition, DataGen

np.random.seed(42)

DOUBLE_BUFFER = True


class DoitgenDataGen(DataGen):
class DoitgenDataGen(du.DataGen):

# Function pointers to alternative implementations
FUNCPTRS = ["doitgen_naive", "doitgen_baseline", "doitgen_opt"]
Expand Down Expand Up @@ -78,9 +77,9 @@ def emit_header(self, **kwargs):
'funcptr': kwargs['funcptr']
}

header += [format_array_definition('double', A_uid, A)]
header += [format_array_definition('double', x_uid, x)]
header += [format_struct_definition('doitgen_args_t', 'args', cfg)]
header += [du.format_array_definition('double', A_uid, A)]
header += [du.format_array_definition('double', x_uid, x)]
header += [du.format_struct_definition('doitgen_args_t', 'args', cfg)]
header = '\n\n'.join(header)

return header
Expand Down
19 changes: 8 additions & 11 deletions sw/blas/axpy/scripts/datagen.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,12 @@
#
# Author: Luca Colagrande <[email protected]>

import numpy as np
import sys

import snitch.util.sim.data_utils as du
from snitch.util.sim.data_utils import format_scalar_definition, format_array_definition, \
format_array_declaration, format_ifdef_wrapper, format_struct_definition, DataGen


class AxpyDataGen(DataGen):
class AxpyDataGen(du.DataGen):

# AXI splits bursts crossing 4KB address boundaries. To minimize
# the occurrence of these splits the data should be aligned to 4KB
Expand Down Expand Up @@ -60,16 +57,16 @@ def emit_header(self, **kwargs):
'funcptr': kwargs['funcptr']
}

header += [format_scalar_definition('const double', 'a', a)]
header += [format_array_definition('double', x_uid, x,
header += [du.format_scalar_definition('const double', 'a', a)]
header += [du.format_array_definition('double', x_uid, x,
alignment=self.BURST_ALIGNMENT, section=kwargs['section'])]
header += [format_array_definition('double', y_uid, y,
header += [du.format_array_definition('double', y_uid, y,
alignment=self.BURST_ALIGNMENT, section=kwargs['section'])]
header += [format_array_declaration('double', z_uid, x.shape,
header += [du.format_array_declaration('double', z_uid, x.shape,
alignment=self.BURST_ALIGNMENT, section=kwargs['section'])]
header += [format_struct_definition('axpy_args_t', 'args', cfg)]
result_def = format_array_definition('double', 'g', g)
header += [format_ifdef_wrapper('BIST', result_def)]
header += [du.format_struct_definition('axpy_args_t', 'args', cfg)]
result_def = du.format_array_definition('double', 'g', g)
header += [du.format_ifdef_wrapper('BIST', result_def)]
header = '\n\n'.join(header)

return header
Expand Down
22 changes: 10 additions & 12 deletions sw/blas/dot/scripts/datagen.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,9 @@
import sys

import snitch.util.sim.data_utils as du
from snitch.util.sim.data_utils import format_scalar_definition, format_array_definition, \
format_scalar_declaration, format_ifdef_wrapper, DataGen


class DotDataGen(DataGen):
class DotDataGen(du.DataGen):

# AXI splits bursts crossing 4KB address boundaries. To minimize
# the occurrence of these splits the data should be aligned to 4KB
Expand All @@ -31,15 +29,15 @@ def emit_header(self, **kwargs):
assert (n % (8 * 4)) == 0, "n must be an integer multiple of the number of cores times " \
"the unrolling factor"

header += [format_scalar_definition('const uint32_t', 'n', n)]
header += [format_array_definition('double', 'x', x, alignment=self.BURST_ALIGNMENT,
section=kwargs['section'])]
header += [format_array_definition('double', 'y', y, alignment=self.BURST_ALIGNMENT,
section=kwargs['section'])]
header += [format_scalar_declaration('double', 'result', alignment=self.BURST_ALIGNMENT,
section=kwargs['section'])]
result_def = format_scalar_definition('double', 'g', g)
header += [format_ifdef_wrapper('BIST', result_def)]
header += [du.format_scalar_definition('const uint32_t', 'n', n)]
header += [du.format_array_definition('double', 'x', x, alignment=self.BURST_ALIGNMENT,
section=kwargs['section'])]
header += [du.format_array_definition('double', 'y', y, alignment=self.BURST_ALIGNMENT,
section=kwargs['section'])]
header += [du.format_scalar_declaration('double', 'result', alignment=self.BURST_ALIGNMENT,
section=kwargs['section'])]
result_def = du.format_scalar_definition('double', 'g', g)
header += [du.format_ifdef_wrapper('BIST', result_def)]
header = '\n\n'.join(header)

return header
Expand Down
28 changes: 13 additions & 15 deletions sw/blas/gemm/scripts/datagen.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,12 @@
import sys

import snitch.util.sim.data_utils as du
from snitch.util.sim.data_utils import DataGen, format_array_declaration, \
format_struct_definition, format_array_definition, format_ifdef_wrapper


np.random.seed(42)


class GemmDataGen(DataGen):
class GemmDataGen(du.DataGen):

# AXI splits bursts crossing 4KB address boundaries. To minimize
# the occurrence of these splits the data should be aligned to 4KB
Expand Down Expand Up @@ -125,18 +123,18 @@ def emit_header(self, **kwargs):
b = b.flatten()
c = c.flatten()

header += [format_array_declaration(ctype, a_uid, a.shape)]
header += [format_array_declaration(ctype, b_uid, b.shape)]
header += [format_array_declaration(ctype, c_uid, c.shape)]
header += [format_struct_definition('gemm_args_t', 'args', cfg)]
header += [format_array_definition(ctype, a_uid, a,
section=kwargs['section'])]
header += [format_array_definition(ctype, b_uid, b,
section=kwargs['section'])]
header += [format_array_definition(ctype, c_uid, c,
section=kwargs['section'])]
result_def = format_array_definition(ctype, 'result', result.flatten())
header += [format_ifdef_wrapper('BIST', result_def)]
header += [du.format_array_declaration(ctype, a_uid, a.shape)]
header += [du.format_array_declaration(ctype, b_uid, b.shape)]
header += [du.format_array_declaration(ctype, c_uid, c.shape)]
header += [du.format_struct_definition('gemm_args_t', 'args', cfg)]
header += [du.format_array_definition(ctype, a_uid, a,
section=kwargs['section'])]
header += [du.format_array_definition(ctype, b_uid, b,
section=kwargs['section'])]
header += [du.format_array_definition(ctype, c_uid, c,
section=kwargs['section'])]
result_def = du.format_array_definition(ctype, 'result', result.flatten())
header += [du.format_ifdef_wrapper('BIST', result_def)]
header = '\n\n'.join(header)

return header
Expand Down
9 changes: 4 additions & 5 deletions sw/blas/syrk/scripts/datagen.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,12 @@
import numpy as np

import snitch.util.sim.data_utils as du
from snitch.util.sim.data_utils import format_array_definition, format_struct_definition, DataGen


DOUBLE_BUFFER = True


class SyrkDataGen(DataGen):
class SyrkDataGen(du.DataGen):

# Function pointers to alternative implementations
FUNCPTRS = ["syrk_naive", "syrk_baseline", "syrk_opt"]
Expand Down Expand Up @@ -73,9 +72,9 @@ def emit_header(self, **kwargs):
'funcptr': kwargs['funcptr']
}

header += [format_array_definition('double', A_uid, A)]
header += [format_array_definition('double', C_uid, C_in)]
header += [format_struct_definition('syrk_args_t', 'args', cfg)]
header += [du.format_array_definition('double', A_uid, A)]
header += [du.format_array_definition('double', C_uid, C_in)]
header += [du.format_struct_definition('syrk_args_t', 'args', cfg)]
header = '\n\n'.join(header)

return header
Expand Down

0 comments on commit 8ce7b91

Please sign in to comment.