From 7c22d77a71eb59885dab1cbc3b957384c10a2af7 Mon Sep 17 00:00:00 2001 From: Won Jeon Date: Tue, 23 Jan 2024 07:46:08 +0000 Subject: Fix serialize() for SHAPE data type and add CONST_SHAPE support for addConst() Signed-off-by: Won Jeon Change-Id: I1ffa49f3e5437be6757a6a2788e9de1a2e99a92c --- python/serializer/tosa_serializer.py | 19 +++++++++++++++++-- 1 file 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 [ -- cgit v1.2.1