aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWon Jeon <won.jeon@arm.com>2024-01-23 07:46:08 +0000
committerWon Jeon <won.jeon@arm.com>2024-01-23 07:49:20 +0000
commit7c22d77a71eb59885dab1cbc3b957384c10a2af7 (patch)
tree94b7783b21d950dfd04d035784be55da5afffcd3
parent5d580faec02bcef56164587accb5fd88a3e80d86 (diff)
downloadserialization_lib-7c22d77a71eb59885dab1cbc3b957384c10a2af7.tar.gz
Fix serialize() for SHAPE data type and add CONST_SHAPE support for addConst()
Signed-off-by: Won Jeon <won.jeon@arm.com> Change-Id: I1ffa49f3e5437be6757a6a2788e9de1a2e99a92c
-rw-r--r--python/serializer/tosa_serializer.py19
1 files changed, 17 insertions, 2 deletions
diff --git a/python/serializer/tosa_serializer.py b/python/serializer/tosa_serializer.py
index 1b40723..1449c0e 100644
--- a/python/serializer/tosa_serializer.py
+++ b/python/serializer/tosa_serializer.py
@@ -500,7 +500,7 @@ class TosaSerializerTensor:
b2 = (val_u32 >> np.uint32(16)) & ByteMask
b3 = (val_u32 >> np.uint32(24)) & ByteMask
u8_data.extend([b0, b1, b2, b3])
- elif self.dtype == DType.INT48 or self.dtype == DType.SHAPE:
+ elif self.dtype == DType.INT48:
for val in self.data:
val_u64 = np.uint64(val)
b0 = val_u64 & ByteMask
@@ -510,6 +510,18 @@ class TosaSerializerTensor:
b4 = (val_u64 >> np.uint64(32)) & ByteMask
b5 = (val_u64 >> np.uint64(40)) & ByteMask
u8_data.extend([b0, b1, b2, b3, b4, b5])
+ elif self.dtype == DType.SHAPE:
+ for val in self.data:
+ val_u64 = np.uint64(val)
+ b0 = val_u64 & ByteMask
+ b1 = (val_u64 >> np.uint64(8)) & ByteMask
+ b2 = (val_u64 >> np.uint64(16)) & ByteMask
+ b3 = (val_u64 >> np.uint64(24)) & ByteMask
+ b4 = (val_u64 >> np.uint64(32)) & ByteMask
+ b5 = (val_u64 >> np.uint64(40)) & ByteMask
+ b6 = (val_u64 >> np.uint64(48)) & ByteMask
+ b7 = (val_u64 >> np.uint64(56)) & ByteMask
+ u8_data.extend([b0, b1, b2, b3, b4, b5, b6, b7])
elif self.dtype == DType.FP16:
np_arr = np.array(self.data, dtype=np.float16)
u8_data.extend(np_arr.view(np.uint8))
@@ -711,7 +723,10 @@ class TosaSerializerRegion:
tens = self.currBasicBlock.addTensor(name, shape, dtype, tensor_vals, filename)
# Add the operator now
- self.currBasicBlock.addOperator(TosaOp.Op().CONST, [], name)
+ if dtype == DType.SHAPE:
+ self.currBasicBlock.addOperator(TosaOp.Op().CONST_SHAPE, [], name)
+ else:
+ self.currBasicBlock.addOperator(TosaOp.Op().CONST, [], name)
# Save the const data to file for debug or as input files
if vals is not None and self.constMode in [