diff --git a/src/finn/backend/fpgadataflow/utils.py b/src/finn/backend/fpgadataflow/utils.py index c466bed944591750cbbd83d6f453a56c921b3dd1..110ed7b0de674b8a7b243bca2cc9e0bc04d3acb0 100644 --- a/src/finn/backend/fpgadataflow/utils.py +++ b/src/finn/backend/fpgadataflow/utils.py @@ -6,7 +6,7 @@ import numpy as np from finn.core.datatype import DataType from finn.core.utils import ( pack_innermost_dim_as_hex_string, - unpack_innermost_dim_from_hex_string + unpack_innermost_dim_from_hex_string, ) @@ -63,6 +63,12 @@ def numpy_to_hls_code( def npy_to_rtlsim_input(input_file, input_dtype, pad_to_nbits): + """Convert the multidimensional NumPy array of integers (stored as floats) + from input_file into a flattened sequence of Python arbitrary-precision + integers, packing the innermost dimension. See + finn.core.utils.pack_innermost_dim_as_hex_string() for more info on how the + packing works.""" + inp = np.load(input_file) ishape = inp.shape inp = inp.flatten() @@ -79,6 +85,11 @@ def npy_to_rtlsim_input(input_file, input_dtype, pad_to_nbits): def rtlsim_output_to_npy(output, path, dtype, shape, packedBits, targetBits): + """Convert a flattened sequence of Python arbitrary-precision integers + output into a NumPy array. Each arbitrary-precision integer is assumed to + be a packed array of targetBits-bit elements, which will be unpacked + as the innermost dimension of the NumPy array.""" + output = [hex(int(x)) for x in output] out_array = unpack_innermost_dim_from_hex_string( output, dtype, shape, packedBits, targetBits, True