aboutsummaryrefslogtreecommitdiff
path: root/src/TosaSerialize.cpp
diff options
context:
space:
mode:
authorTai Ly <tai.ly@arm.com>2023-08-21 23:00:40 +0000
committerTai Ly <tai.ly@arm.com>2023-08-28 21:09:07 +0000
commit7566d1235cb646e46531c2eb34757cb4b3efa933 (patch)
tree670dc54644ab8e3c38ab9359604efc4ec171ad17 /src/TosaSerialize.cpp
parentea49f62f7ab81750f19bef011683164fe9bd4080 (diff)
downloadtosa_mlir_translator-7566d1235cb646e46531c2eb34757cb4b3efa933.tar.gz
[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 <tai.ly@arm.com> Change-Id: Ib2943333d8e3a199cf8a909b6db7197150666700
Diffstat (limited to 'src/TosaSerialize.cpp')
-rw-r--r--src/TosaSerialize.cpp24
1 files changed, 18 insertions, 6 deletions
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<mlir::RankedTensorType>();
- std::vector<int32_t> shape =
- ttype.hasRank() ? std::vector<int32_t>(ranked.getShape().begin(),
- ranked.getShape().end())
- : std::vector<int32_t>();
+ const bool is_unranked = !ttype.hasRank();
+ std::vector<int32_t> shape;
+ if (!is_unranked) {
+ auto shaped = val.getType().dyn_cast<mlir::ShapedType>();
+ 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<uint8_t>());
+ ts = new TosaSerializationTensor(name, shape, type, std::vector<uint8_t>(),
+ /* variable = */ false, is_unranked);
return ts;
}