From 7566d1235cb646e46531c2eb34757cb4b3efa933 Mon Sep 17 00:00:00 2001 From: Tai Ly Date: Mon, 21 Aug 2023 23:00:40 +0000 Subject: [tosa_mlir_translator] Support dynamic tensors This adds serialization and deserialization support for: - unranked tensors (eg, *xi32) and - tensors with dynamic shapes (eg, ?x?xi32) Signed-off-by: Tai Ly Change-Id: Ib2943333d8e3a199cf8a909b6db7197150666700 --- src/TosaSerialize.cpp | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) (limited to 'src/TosaSerialize.cpp') diff --git a/src/TosaSerialize.cpp b/src/TosaSerialize.cpp index 741597b..f74df1d 100644 --- a/src/TosaSerialize.cpp +++ b/src/TosaSerialize.cpp @@ -1650,13 +1650,25 @@ TosaSerializationBlockBuilder::BuildTosaSerializationTensor( return nullptr; } - auto ranked = val.getType().dyn_cast(); - std::vector shape = - ttype.hasRank() ? std::vector(ranked.getShape().begin(), - ranked.getShape().end()) - : std::vector(); + const bool is_unranked = !ttype.hasRank(); + std::vector shape; + if (!is_unranked) { + auto shaped = val.getType().dyn_cast(); + assert(shaped); + for (int idx = 0; idx < ttype.getRank(); idx++) { + if (shaped.isDynamicDim(idx)) { + shape.push_back(0); // size of 0 represents dynamic dimension + } else { + auto dim = shaped.getDimSize(idx); + assert(dim > 0); + shape.push_back(dim); + } + } + } + DType type = Type2DType(ttype.getElementType()); - ts = new TosaSerializationTensor(name, shape, type, std::vector()); + ts = new TosaSerializationTensor(name, shape, type, std::vector(), + /* variable = */ false, is_unranked); return ts; } -- cgit v1.2.1