aboutsummaryrefslogtreecommitdiff
path: root/python/serializer/tosa_serializer.py
diff options
context:
space:
mode:
authorJames Ward <james.ward@arm.com>2022-10-18 17:27:40 +0100
committerJames Ward <james.ward@arm.com>2022-10-26 11:57:21 +0100
commit34a627959a61b4eccbeea4400cf9684debb331dc (patch)
tree7b6be68e49010f9a621c8e8f67f55163a534fe69 /python/serializer/tosa_serializer.py
parente1072a9ed871fd474e7b09b7a74ae7be5f0a6f78 (diff)
downloadserialization_lib-34a627959a61b4eccbeea4400cf9684debb331dc.tar.gz
BF16 support in TOSA serialization
Change-Id: I98072019e3dbbf1eab0bc95f74a4546ed82519db Signed-off-by: James Ward <james.ward@arm.com>
Diffstat (limited to 'python/serializer/tosa_serializer.py')
-rw-r--r--python/serializer/tosa_serializer.py5
1 files changed, 3 insertions, 2 deletions
diff --git a/python/serializer/tosa_serializer.py b/python/serializer/tosa_serializer.py
index f4e146c..861ea46 100644
--- a/python/serializer/tosa_serializer.py
+++ b/python/serializer/tosa_serializer.py
@@ -59,6 +59,7 @@ DTypeNames = [
"FP32",
"UINT16",
"FP16",
+ "BF16",
]
ByteMask = np.uint64(0xFF)
@@ -378,7 +379,7 @@ class TosaSerializerTensor:
self.shape = shape
self.dtype = dtype
- if dtype == DType.FP32:
+ if dtype == DType.FP32 or dtype == DType.BF16:
fntype = np.float32
elif dtype == DType.FP16:
fntype = np.float16
@@ -466,7 +467,7 @@ class TosaSerializerTensor:
elif self.dtype == DType.FP16:
np_arr = np.array(self.data, dtype=np.float16)
u8_data.extend(np_arr.view(np.uint8))
- elif self.dtype == DType.FP32:
+ elif self.dtype == DType.FP32 or self.dtype == DType.BF16:
for val in self.data:
b = struct.pack("!f", val)
u8_data.extend([b[3], b[2], b[1], b[0]])