Skip to content
Snippets Groups Projects
Commit 2a2c7fac authored by Yaman Umuroglu's avatar Yaman Umuroglu
Browse files

[Driver, Util] change endianness reversal method for out unpack

parent 3dcf1ac4
No related branches found
No related tags found
No related merge requests found
......@@ -86,7 +86,9 @@ assert ibuf_normal.shape == ishape_normal
ibuf_folded = ibuf_normal.reshape(ishape_folded)
# pack the input buffer, reversing both SIMD dim and endianness
ibuf_packed = finnpy_to_packed_bytearray(ibuf_folded, idt, True, True)
ibuf_packed = finnpy_to_packed_bytearray(
ibuf_folded, idt, reverse_endian=True, reverse_inner=True
)
# allocate a PYNQ buffer for the packed input buffer
ibuf_packed_device = allocate(shape=ishape_packed, dtype=np.uint8)
# copy the packed data into the PYNQ buffer
......@@ -104,7 +106,7 @@ dma.recvchannel.wait()
# unpack the packed output buffer from accelerator
obuf_folded = packed_bytearray_to_finnpy(
obuf_packed, odt, oshape_folded, reverse_endian=True
obuf_packed, odt, oshape_folded, reverse_endian=True, reverse_inner=True
)
# convert to normal reshape and save
obuf_normal = obuf_folded.reshape(oshape_normal)
......
......@@ -258,7 +258,9 @@ def rtlsim_output_to_npy(
return out_array
def finnpy_to_packed_bytearray(ndarray, dtype, reverse_inner=False, reverse_endian=False):
def finnpy_to_packed_bytearray(
ndarray, dtype, reverse_inner=False, reverse_endian=False
):
"""Given a numpy ndarray with FINN DataType dtype, pack the innermost
dimension and return the packed representation as an ndarray of uint8.
The packed innermost dimension will be padded to the nearest multiple
......@@ -316,14 +318,16 @@ def packed_bytearray_to_finnpy(
assert packed_bits % target_bits == 0
n_target_elems = packed_bits // target_bits
output_shape = packed_bytearray.shape[:-1] + (n_target_elems,)
if reverse_endian and target_bits > 8:
# revse the endianness of each element
orig_shape = packed_bytearray.shape
assert target_bits % 8 == 0
target_bytes = target_bits // 8
new_shape = orig_shape[:-1] + (-1, target_bytes)
packed_bytearray = np.flip(packed_bytearray.reshape(new_shape), axis=-1)
packed_bytearray = packed_bytearray.reshape(orig_shape)
# if reverse_endian and target_bits > 8:
# # revse the endianness of each element
# orig_shape = packed_bytearray.shape
# assert target_bits % 8 == 0
# target_bytes = target_bits // 8
# new_shape = orig_shape[:-1] + (-1, target_bytes)
# packed_bytearray = np.flip(packed_bytearray.reshape(new_shape), axis=-1)
# packed_bytearray = packed_bytearray.reshape(orig_shape)
if reverse_endian:
packed_bytearray = np.flip(packed_bytearray, axis=-1)
# convert innermost dim of byte array to hex strings
packed_hexstring = np.apply_along_axis(
npbytearray2hexstring, packed_dim, packed_bytearray
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment