[Mlir-commits] [mlir] [mlir][tosa] Add several level checks (PR #128074)

Luke Hutton llvmlistbot at llvm.org
Tue Feb 25 03:59:29 PST 2025


================
@@ -147,107 +152,149 @@ struct TosaValidation : public tosa::impl::TosaValidationBase<TosaValidation> {
     return true;
   }
 
-  bool levelCheckRank(Operation *op, const Value &v,
-                      const std::string &checkDesc) {
+  bool levelCheckListSize(Operation *op, int32_t v,
+                          const std::string &checkDesc) {
+    if (v > tosaLevel.MAX_TENSOR_LIST_SIZE) {
+      op->emitOpError() << "failed level check for MAX_TENSOR_LIST_SIZE: "
+                        << checkDesc;
+      return false;
+    }
+    return true;
+  }
+
+  bool levelCheckRankAndSizes(Operation *op, const Value &v,
+                              const std::string &operandOrResult) {
     if (ShapedType type = dyn_cast<ShapedType>(v.getType())) {
       if (!type.hasRank()) {
         op->emitOpError() << "failed level check: unranked tensor";
         return false;
       }
       if (type.getRank() > tosaLevel.MAX_RANK) {
-        op->emitOpError() << "failed level check: " << checkDesc;
+        op->emitOpError() << "failed level check: " << operandOrResult
+                          << " rank(shape) <= MAX_RANK";
+        return false;
+      }
+
+      const int64_t max_dim = (INT64_C(1) << tosaLevel.MAX_LOG2_SIZE) - 1;
+      const int64_t max_size =
+          (INT64_C(1) << (tosaLevel.MAX_LOG2_SIZE + 1)) - 1;
----------------
lhutton1 wrote:

Curious why this is calculated differently to `max_dim`? If I'm reading the spec correctly (likely I'm missing something), should it be the same?
```
For each tensor, the number of tensor elements multiplied by the element size in bytes (which is taken to be 1 for elements smaller than a 8-bit) must be representable as a tensor_size_t.
```
where
```
tensor_size_t is a signed integer as it may be used for negative offsets. This type must be able to hold integers in the range [-(1 << MAX_LOG2_SIZE) .. (1 << MAX_LOG2_SIZE) - 1]
```

https://github.com/llvm/llvm-project/pull/128074


More information about the Mlir-commits mailing list