[Mlir-commits] [mlir] 052e6ff - [mlir][tosa] Add input_unsigned attribute to CAST (#215838)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Mon Aug 17 09:36:24 PDT 2026
Author: Maddy Dunn
Date: 2026-08-17T17:36:20+01:00
New Revision: 052e6ffdbf68cab9f14ed6369b916127f89d0ae1
URL: https://github.com/llvm/llvm-project/commit/052e6ffdbf68cab9f14ed6369b916127f89d0ae1
DIFF: https://github.com/llvm/llvm-project/commit/052e6ffdbf68cab9f14ed6369b916127f89d0ae1.diff
LOG: [mlir][tosa] Add input_unsigned attribute to CAST (#215838)
- Add optional attribute input_unsigned
- Add attributeCheckCast
- Update verification for CAST to reflect new attribute rules
Signed-off-by: Madeleine Dunn <madeleine.dunn at arm.com>
Added:
Modified:
mlir/include/mlir/Dialect/Tosa/IR/TosaOps.td
mlir/lib/Dialect/Tosa/IR/TosaCanonicalizations.cpp
mlir/lib/Dialect/Tosa/IR/TosaOps.cpp
mlir/lib/Dialect/Tosa/Transforms/TosaDecomposeDepthwise.cpp
mlir/lib/Dialect/Tosa/Transforms/TosaDowngrade1p1To1p0.cpp
mlir/lib/Dialect/Tosa/Transforms/TosaNarrowTypes.cpp
mlir/lib/Dialect/Tosa/Transforms/TosaValidation.cpp
mlir/test/Dialect/Tosa/canonicalize.mlir
mlir/test/Dialect/Tosa/constant_folding.mlir
mlir/test/Dialect/Tosa/invalid.mlir
mlir/test/Dialect/Tosa/invalid_extension.mlir
mlir/test/Dialect/Tosa/ops.mlir
mlir/test/Dialect/Tosa/profile_all_unsupported.mlir
mlir/test/Dialect/Tosa/profile_pro_fp_unsupported.mlir
mlir/test/Dialect/Tosa/profile_pro_int_unsupported.mlir
mlir/test/Dialect/Tosa/tosa-downgrade-1-1-to-1-0.mlir
mlir/test/Dialect/Tosa/tosa-infer-shapes.mlir
mlir/test/Dialect/Tosa/tosa-narrow-f64-to-f32-aggressive.mlir
mlir/test/Dialect/Tosa/tosa-narrow-i64-to-i32-aggressive.mlir
mlir/test/Dialect/Tosa/tosa-narrow-i64-to-i32.mlir
mlir/test/Dialect/Tosa/tosa-validation-valid.mlir
mlir/test/Dialect/Tosa/tosa-validation-version-1p0-invalid.mlir
mlir/test/Dialect/Tosa/tosa-validation-version-1p1-valid.mlir
mlir/test/Dialect/Tosa/verifier.mlir
Removed:
################################################################################
diff --git a/mlir/include/mlir/Dialect/Tosa/IR/TosaOps.td b/mlir/include/mlir/Dialect/Tosa/IR/TosaOps.td
index 2d5ab85f6bfc9..2edacfa02b576 100644
--- a/mlir/include/mlir/Dialect/Tosa/IR/TosaOps.td
+++ b/mlir/include/mlir/Dialect/Tosa/IR/TosaOps.td
@@ -2415,7 +2415,8 @@ def Tosa_CastOp: Tosa_Op<"cast", [Pure, SameOperandsAndResultShape,
}];
let arguments = (ins
- Tosa_Tensor:$input
+ Tosa_Tensor:$input,
+ DefaultValuedOptionalAttr<BoolAttr, "false">:$input_unsigned
);
let results = (outs
diff --git a/mlir/lib/Dialect/Tosa/IR/TosaCanonicalizations.cpp b/mlir/lib/Dialect/Tosa/IR/TosaCanonicalizations.cpp
index d4ae8e920f489..f91ef25633298 100644
--- a/mlir/lib/Dialect/Tosa/IR/TosaCanonicalizations.cpp
+++ b/mlir/lib/Dialect/Tosa/IR/TosaCanonicalizations.cpp
@@ -1170,8 +1170,17 @@ struct NonNarrowingCastsOptimization : public OpRewritePattern<tosa::CastOp> {
return rewriter.notifyMatchFailure(castOp,
"inner cast operation is narrowing");
+ // Bail out of the canonicalization if (inner) cast(input_unsigned=false) ->
+ // (outer) cast(input_unsigned=true)
+ if (!innerCastOp.getInputUnsigned() && castOp.getInputUnsigned()) {
+ return rewriter.notifyMatchFailure(
+ castOp, "avoid rewriting cast(input_unsigned=false) -> "
+ "cast(input_unsigned=true)");
+ }
+
rewriter.replaceOpWithNewOp<tosa::CastOp>(castOp, outerOutputType,
- innerCastInput);
+ innerCastInput,
+ innerCastOp.getInputUnsigned());
return success();
}
@@ -2025,7 +2034,8 @@ OpFoldResult CastOp::fold(FoldAdaptor adaptor) {
}
if (llvm::isa<IntegerType>(inETy) && llvm::isa<FloatType>(outETy)) {
- auto unsign = llvm::cast<IntegerType>(inETy).isUnsignedInteger();
+ const bool unsign = llvm::cast<IntegerType>(inETy).isUnsignedInteger() ||
+ adaptor.getInputUnsigned();
APFloat splatVal(llvm::cast<FloatType>(outETy).getFloatSemantics());
splatVal.convertFromAPInt(operand.getSplatValue<APInt>(), !unsign,
llvm::RoundingMode::NearestTiesToEven);
@@ -2045,7 +2055,8 @@ OpFoldResult CastOp::fold(FoldAdaptor adaptor) {
if (llvm::isa<IntegerType>(inETy) && llvm::isa<IntegerType>(outETy)) {
const auto inIntType = llvm::cast<IntegerType>(inETy);
- auto unsignIn = inIntType.isUnsignedInteger();
+ const bool unsignIn =
+ inIntType.isUnsignedInteger() || adaptor.getInputUnsigned();
bool trunc =
inETy.getIntOrFloatBitWidth() > outETy.getIntOrFloatBitWidth();
auto intVal = operand.getSplatValue<APInt>();
diff --git a/mlir/lib/Dialect/Tosa/IR/TosaOps.cpp b/mlir/lib/Dialect/Tosa/IR/TosaOps.cpp
index 6b76acb2752da..46f84940d4718 100644
--- a/mlir/lib/Dialect/Tosa/IR/TosaOps.cpp
+++ b/mlir/lib/Dialect/Tosa/IR/TosaOps.cpp
@@ -5375,6 +5375,16 @@ LogicalResult CastOp::verify() {
const bool inputIsBlockScaled = llvm::isa<BlockScaledType>(inputElementType);
const bool outputIsBlockScaled =
llvm::isa<BlockScaledType>(outputElementType);
+
+ const bool isUnsigned = this->getInputUnsigned();
+ const Type inputDataType = getStorageElementTypeOrSelf(inputType);
+
+ if (isUnsigned)
+ if (!inputDataType.isInteger() || inputDataType.isInteger(1))
+ return emitOpError()
+ << "attribute input_unsigned requires integer type inputs. Got: "
+ << inputDataType;
+
if (!inputIsBlockScaled && !outputIsBlockScaled)
return success();
diff --git a/mlir/lib/Dialect/Tosa/Transforms/TosaDecomposeDepthwise.cpp b/mlir/lib/Dialect/Tosa/Transforms/TosaDecomposeDepthwise.cpp
index 022476a2f44cf..8044671e1bd20 100644
--- a/mlir/lib/Dialect/Tosa/Transforms/TosaDecomposeDepthwise.cpp
+++ b/mlir/lib/Dialect/Tosa/Transforms/TosaDecomposeDepthwise.cpp
@@ -91,15 +91,16 @@ struct DepthwiseConv2DIsMul : public OpRewritePattern<tosa::DepthwiseConv2DOp> {
.getResult();
Type resultETy = resultType.getElementType();
-
if (inputETy != resultETy) {
inputType = inputType.clone(resultETy);
- input = tosa::CastOp::create(rewriter, op.getLoc(), inputType, input);
+ input = tosa::CastOp::create(rewriter, op.getLoc(), inputType, input,
+ /*input_unsigned*/ false);
}
if (weightETy != resultETy) {
weightType = weightType.clone(resultETy);
- weight = tosa::CastOp::create(rewriter, op.getLoc(), weightType, weight);
+ weight = tosa::CastOp::create(rewriter, op.getLoc(), weightType, weight,
+ /*input_unsigned*/ false);
}
if (iZp != 0 || wZp != 0) {
diff --git a/mlir/lib/Dialect/Tosa/Transforms/TosaDowngrade1p1To1p0.cpp b/mlir/lib/Dialect/Tosa/Transforms/TosaDowngrade1p1To1p0.cpp
index 2bc99d7fab8a4..1d3d7a344341e 100644
--- a/mlir/lib/Dialect/Tosa/Transforms/TosaDowngrade1p1To1p0.cpp
+++ b/mlir/lib/Dialect/Tosa/Transforms/TosaDowngrade1p1To1p0.cpp
@@ -59,10 +59,11 @@ class BoolFp32CastRewrite : public OpRewritePattern<tosa::CastOp> {
const Type i8Type = rewriter.getI8Type();
const Type intermediateType = cast<TensorType>(outputType).clone(i8Type);
- auto inner =
- tosa::CastOp::create(rewriter, op.getLoc(), intermediateType, input);
- auto outer = tosa::CastOp::create(rewriter, op.getLoc(), outputType,
- inner.getOutput());
+ auto inner = tosa::CastOp::create(rewriter, op.getLoc(), intermediateType,
+ input, /*input_unsigned*/ false);
+ auto outer =
+ tosa::CastOp::create(rewriter, op.getLoc(), outputType,
+ inner.getOutput(), /*input_unsigned*/ false);
rewriter.replaceOp(op, outer.getOutput());
return success();
}
@@ -91,12 +92,13 @@ class BoolGatherRewrite : public OpRewritePattern<tosa::GatherOp> {
const Type valuesI8Type = cast<TensorType>(valuesType).clone(i8Type);
const Type resultI8Type = cast<TensorType>(resultType).clone(i8Type);
- auto valuesToI8 =
- tosa::CastOp::create(rewriter, op.getLoc(), valuesI8Type, values);
+ auto valuesToI8 = tosa::CastOp::create(rewriter, op.getLoc(), valuesI8Type,
+ values, /*input_unsigned*/ false);
auto gatherI8 = tosa::GatherOp::create(rewriter, op.getLoc(), resultI8Type,
valuesToI8.getOutput(), indices);
- auto i8ToBool = tosa::CastOp::create(rewriter, op.getLoc(), resultType,
- gatherI8.getOutput());
+ auto i8ToBool =
+ tosa::CastOp::create(rewriter, op.getLoc(), resultType,
+ gatherI8.getOutput(), /*input_unsigned*/ false);
rewriter.replaceOp(op, i8ToBool.getOutput());
return success();
}
@@ -129,14 +131,16 @@ class BoolScatterRewrite : public OpRewritePattern<tosa::ScatterOp> {
const Type resultI8Type = cast<TensorType>(resultType).clone(i8Type);
auto valuesInToI8 =
- tosa::CastOp::create(rewriter, op.getLoc(), valuesInI8Type, valuesIn);
- auto inputToI8 =
- tosa::CastOp::create(rewriter, op.getLoc(), inputI8Type, input);
+ tosa::CastOp::create(rewriter, op.getLoc(), valuesInI8Type, valuesIn,
+ /*input_unsigned*/ false);
+ auto inputToI8 = tosa::CastOp::create(rewriter, op.getLoc(), inputI8Type,
+ input, /*input_unsigned*/ false);
auto scatterI8 = tosa::ScatterOp::create(
rewriter, op.getLoc(), resultI8Type, valuesInToI8.getOutput(), indices,
inputToI8.getOutput());
auto i8ToBool = tosa::CastOp::create(rewriter, op.getLoc(), resultType,
- scatterI8.getValuesOut());
+ scatterI8.getValuesOut(),
+ /*input_unsigned*/ false);
rewriter.replaceOp(op, i8ToBool.getOutput());
return success();
}
diff --git a/mlir/lib/Dialect/Tosa/Transforms/TosaNarrowTypes.cpp b/mlir/lib/Dialect/Tosa/Transforms/TosaNarrowTypes.cpp
index d441f90c2a074..fa58bf3c8c589 100644
--- a/mlir/lib/Dialect/Tosa/Transforms/TosaNarrowTypes.cpp
+++ b/mlir/lib/Dialect/Tosa/Transforms/TosaNarrowTypes.cpp
@@ -500,7 +500,8 @@ class ConvertCastOpWithBoundsChecking
return failure();
rewriter.replaceOpWithNewOp<tosa::CastOp>(
- op, typeConverter->convertType(resultType), adaptor.getInput());
+ op, typeConverter->convertType(resultType), adaptor.getInput(),
+ op->getAttrs());
return success();
}
};
@@ -616,7 +617,10 @@ LogicalResult runTosaNarrowing(Operation *op, bool aggressiveRewrite,
ValueRange inputs, Location loc) -> Value {
if (inputs.size() != 1)
return Value();
- return tosa::CastOp::create(builder, loc, resultType, inputs.front());
+ return tosa::CastOp::create(
+ builder, loc, resultType, inputs.front(),
+ getStorageElementTypeOrSelf(inputs.front().getType())
+ .isUnsignedInteger());
};
typeConverter.addSourceMaterialization(materializeCast);
typeConverter.addTargetMaterialization(materializeCast);
diff --git a/mlir/lib/Dialect/Tosa/Transforms/TosaValidation.cpp b/mlir/lib/Dialect/Tosa/Transforms/TosaValidation.cpp
index 2008a4aa92c4a..e4985b8e0c7f0 100644
--- a/mlir/lib/Dialect/Tosa/Transforms/TosaValidation.cpp
+++ b/mlir/lib/Dialect/Tosa/Transforms/TosaValidation.cpp
@@ -668,6 +668,20 @@ struct TosaValidation : public tosa::impl::TosaValidationBase<TosaValidation> {
return success();
}
+ LogicalResult attributeCheckCast(Operation *op) {
+ if (auto cast = dyn_cast<tosa::CastOp>(op)) {
+ const TosaSpecificationVersion targetVersion = targetEnv.getSpecVersion();
+ const TosaSpecificationVersion minRequiredVersion(1, 1, true);
+ if (cast.getInputUnsigned() &&
+ !(targetVersion.isBackwardsCompatibleWith(minRequiredVersion)))
+ return op->emitOpError()
+ << "failed attribute check: CAST attribute input_unsigned "
+ << "requires version 1.1.draft"
+ << " (got " << stringifyVersion(targetVersion) << ") ";
+ }
+ return success();
+ }
+
LogicalResult CheckVariable(Operation *op);
LogicalResult CheckVariableReadOrWrite(Operation *op);
LogicalResult validateValidElementType(Operation *op, Type type,
@@ -975,6 +989,8 @@ LogicalResult TosaValidation::applyLevelCheck(Operation *op) {
LogicalResult TosaValidation::applyAttributeCheck(Operation *op) {
if (failed(attributeCheckRescale(op)))
return failure();
+ if (failed(attributeCheckCast(op)))
+ return failure();
return success();
}
diff --git a/mlir/test/Dialect/Tosa/canonicalize.mlir b/mlir/test/Dialect/Tosa/canonicalize.mlir
index 0807e145b55ab..cda5630b2f84a 100644
--- a/mlir/test/Dialect/Tosa/canonicalize.mlir
+++ b/mlir/test/Dialect/Tosa/canonicalize.mlir
@@ -225,7 +225,7 @@ func.func @add_zero_int(%arg0: tensor<2x3xi32>) -> tensor<2x3xi32> {
// CHECK-LABEL: @cast_fold
func.func @cast_fold(%arg0: tensor<?x1xf32>) -> tensor<?x1xf32> {
// CHECK: return %arg0
- %0 = tosa.cast %arg0 : (tensor<?x1xf32>) -> tensor<?x1xf32>
+ %0 = tosa.cast %arg0 {input_unsigned = false} : (tensor<?x1xf32>) -> tensor<?x1xf32>
return %0 : tensor<?x1xf32>
}
@@ -234,7 +234,7 @@ func.func @cast_fold(%arg0: tensor<?x1xf32>) -> tensor<?x1xf32> {
// CHECK-LABEL: @cast_nofold
func.func @cast_nofold(%arg0: tensor<?x1xf32>) -> tensor<?x1xi32> {
// CHECK: tosa.cast
- %0 = tosa.cast %arg0 : (tensor<?x1xf32>) -> tensor<?x1xi32>
+ %0 = tosa.cast %arg0 {input_unsigned = false} : (tensor<?x1xf32>) -> tensor<?x1xi32>
return %0 : tensor<?x1xi32>
}
@@ -1280,7 +1280,7 @@ func.func @equal_quant_fold() -> tensor<i1> {
func.func @cast_quant_nofold() -> tensor<!quant.uniform<i8:f32, 3.0757404601899907E-5:3>> {
// CHECK: tosa.cast
%0 = "tosa.const"() {values = dense<0> : tensor<i8>} : () -> tensor<!quant.uniform<i8:f32, 3.0757404601899907E-5:-128>>
- %1 = "tosa.cast"(%0) : (tensor<!quant.uniform<i8:f32, 3.0757404601899907E-5:-128>>) -> tensor<!quant.uniform<i8:f32, 3.0757404601899907E-5:3>>
+ %1 = "tosa.cast"(%0) {input_unsigned = false} : (tensor<!quant.uniform<i8:f32, 3.0757404601899907E-5:-128>>) -> tensor<!quant.uniform<i8:f32, 3.0757404601899907E-5:3>>
return %1 : tensor<!quant.uniform<i8:f32, 3.0757404601899907E-5:3>>
}
@@ -1471,7 +1471,7 @@ func.func @no_fold_intdiv_dynamic_result() -> tensor<?xi32> {
// CHECK: return %[[OUT]] : tensor<i32>
func.func @test_fold_i1_to_i32_cast() -> tensor<i32> {
%0 = "tosa.const"() <{values = dense<1> : tensor<i1>}> : () -> tensor<i1>
- %1 = "tosa.cast"(%0) : (tensor<i1>) -> tensor<i32>
+ %1 = "tosa.cast"(%0) {input_unsigned = false} : (tensor<i1>) -> tensor<i32>
return %1 : tensor<i32>
}
@@ -1482,18 +1482,41 @@ func.func @test_fold_i1_to_i32_cast() -> tensor<i32> {
// CHECK: return %[[OUT]] : tensor<i1>
func.func @test_fold_i32_to_i1_cast() -> tensor<i1> {
%0 = "tosa.const"() <{values = dense<10> : tensor<i32>}> : () -> tensor<i32>
- %1 = "tosa.cast"(%0) : (tensor<i32>) -> tensor<i1>
+ %1 = "tosa.cast"(%0) {input_unsigned = false} : (tensor<i32>) -> tensor<i1>
return %1 : tensor<i1>
}
// -----
// CHECK-LABEL: @test_canonicalize_non_narrowing_cast_i8_to_i32
-// CHECK: %[[OUT:.*]] = tosa.cast %arg0 : (tensor<13x21x3xi8>) -> tensor<13x21x3xi32>
+// CHECK: %[[OUT:.*]] = tosa.cast %arg0 : (tensor<13x21x3xi8>) -> tensor<13x21x3xi32>
// CHECK: return %[[OUT]] : tensor<13x21x3xi32>
func.func @test_canonicalize_non_narrowing_cast_i8_to_i32(%arg0: tensor<13x21x3xi8>) -> tensor<13x21x3xi32> {
- %0 = tosa.cast %arg0 : (tensor<13x21x3xi8>) -> tensor<13x21x3xi16>
- %1 = tosa.cast %0 : (tensor<13x21x3xi16>) -> tensor<13x21x3xi32>
+ %0 = tosa.cast %arg0 {input_unsigned = false} : (tensor<13x21x3xi8>) -> tensor<13x21x3xi16>
+ %1 = tosa.cast %0 {input_unsigned = false} : (tensor<13x21x3xi16>) -> tensor<13x21x3xi32>
+ return %1 : tensor<13x21x3xi32>
+}
+
+// -----
+
+// CHECK-LABEL: @test_canonicalize_non_narrowing_non_folding_cast_i8_to_i32_input_unsigned
+// CHECK %arg0 : (tensor<13x21x3xi8>) -> tensor<13x21x3xi16>
+// CHECK %1 {input_unsigned = true} : (tensor<13x21x3xi16>) -> tensor<13x21x3xi32>
+// CHECK: return %1 : tensor<13x21x3xi32>
+func.func @test_canonicalize_non_narrowing_non_folding_cast_i8_to_i32_input_unsigned(%arg0: tensor<13x21x3xi8>) -> tensor<13x21x3xi32> {
+ %0 = tosa.cast %arg0 {input_unsigned = false} : (tensor<13x21x3xi8>) -> tensor<13x21x3xi16>
+ %1 = tosa.cast %0 {input_unsigned = true} : (tensor<13x21x3xi16>) -> tensor<13x21x3xi32>
+ return %1 : tensor<13x21x3xi32>
+}
+
+// -----
+
+// CHECK-LABEL: @test_canonicalize_non_narrowing_cast_i8_to_i32_input_unsigned
+// CHECK: %[[OUT:.*]] = tosa.cast %arg0 {input_unsigned = true} : (tensor<13x21x3xi8>) -> tensor<13x21x3xi32>
+// CHECK: return %[[OUT]] : tensor<13x21x3xi32>
+func.func @test_canonicalize_non_narrowing_cast_i8_to_i32_input_unsigned(%arg0: tensor<13x21x3xi8>) -> tensor<13x21x3xi32> {
+ %0 = tosa.cast %arg0 {input_unsigned = true} : (tensor<13x21x3xi8>) -> tensor<13x21x3xi16>
+ %1 = tosa.cast %0 {input_unsigned = true} : (tensor<13x21x3xi16>) -> tensor<13x21x3xi32>
return %1 : tensor<13x21x3xi32>
}
@@ -1502,8 +1525,8 @@ func.func @test_canonicalize_non_narrowing_cast_i8_to_i32(%arg0: tensor<13x21x3x
// CHECK-LABEL: @test_canonicalize_non_narrowing_cast_i8_to_i8
// CHECK: return %arg0 : tensor<13x21x3xi8>
func.func @test_canonicalize_non_narrowing_cast_i8_to_i8(%arg0: tensor<13x21x3xi8>) -> tensor<13x21x3xi8> {
- %0 = tosa.cast %arg0 : (tensor<13x21x3xi8>) -> tensor<13x21x3xi16>
- %1 = tosa.cast %0 : (tensor<13x21x3xi16>) -> tensor<13x21x3xi8>
+ %0 = tosa.cast %arg0 {input_unsigned = false} : (tensor<13x21x3xi8>) -> tensor<13x21x3xi16>
+ %1 = tosa.cast %0 {input_unsigned = false} : (tensor<13x21x3xi16>) -> tensor<13x21x3xi8>
return %1 : tensor<13x21x3xi8>
}
@@ -1513,8 +1536,8 @@ func.func @test_canonicalize_non_narrowing_cast_i8_to_i8(%arg0: tensor<13x21x3xi
// CHECK: tosa.cast
// CHECK: tosa.cast
func.func @test_canonicalize_non_narrowing_cast_f32_to_f8(%arg0: tensor<13x21x3xf32>) -> tensor<13x21x3xf8E5M2> {
- %0 = tosa.cast %arg0 : (tensor<13x21x3xf32>) -> tensor<13x21x3xf16>
- %1 = tosa.cast %0 : (tensor<13x21x3xf16>) -> tensor<13x21x3xf8E5M2>
+ %0 = tosa.cast %arg0 {input_unsigned = false} : (tensor<13x21x3xf32>) -> tensor<13x21x3xf16>
+ %1 = tosa.cast %0 {input_unsigned = false} : (tensor<13x21x3xf16>) -> tensor<13x21x3xf8E5M2>
return %1 : tensor<13x21x3xf8E5M2>
}
@@ -1524,8 +1547,8 @@ func.func @test_canonicalize_non_narrowing_cast_f32_to_f8(%arg0: tensor<13x21x3x
// CHECK: tosa.cast
// CHECK: tosa.cast
func.func @test_canonicalize_narrowing_cast_i32_to_i8(%arg0: tensor<13x21x3xi32>) -> tensor<13x21x3xi8> {
- %0 = tosa.cast %arg0 : (tensor<13x21x3xi32>) -> tensor<13x21x3xi16>
- %1 = tosa.cast %0 : (tensor<13x21x3xi16>) -> tensor<13x21x3xi8>
+ %0 = tosa.cast %arg0 {input_unsigned = false} : (tensor<13x21x3xi32>) -> tensor<13x21x3xi16>
+ %1 = tosa.cast %0 {input_unsigned = false} : (tensor<13x21x3xi16>) -> tensor<13x21x3xi8>
return %1 : tensor<13x21x3xi8>
}
@@ -1535,8 +1558,8 @@ func.func @test_canonicalize_narrowing_cast_i32_to_i8(%arg0: tensor<13x21x3xi32>
// CHECK: tosa.cast
// CHECK: tosa.cast
func.func @test_canonicalize_narrowing_cast_i32_to_i8_to_i16(%arg0: tensor<13x21x3xi32>) -> tensor<13x21x3xi16> {
- %0 = tosa.cast %arg0 : (tensor<13x21x3xi32>) -> tensor<13x21x3xi8>
- %1 = tosa.cast %0 : (tensor<13x21x3xi8>) -> tensor<13x21x3xi16>
+ %0 = tosa.cast %arg0 {input_unsigned = false} : (tensor<13x21x3xi32>) -> tensor<13x21x3xi8>
+ %1 = tosa.cast %0 {input_unsigned = false} : (tensor<13x21x3xi8>) -> tensor<13x21x3xi16>
return %1 : tensor<13x21x3xi16>
}
@@ -1546,8 +1569,8 @@ func.func @test_canonicalize_narrowing_cast_i32_to_i8_to_i16(%arg0: tensor<13x21
// CHECK: tosa.cast
// CHECK: tosa.cast
func.func @test_canonicalize_narrowing_cast_i8_to_ui16_to_i8(%arg0: tensor<13x21x3xi8>) -> tensor<13x21x3xi8> {
- %0 = tosa.cast %arg0 : (tensor<13x21x3xi8>) -> tensor<13x21x3xui16>
- %1 = tosa.cast %0 : (tensor<13x21x3xui16>) -> tensor<13x21x3xi8>
+ %0 = tosa.cast %arg0 {input_unsigned = false} : (tensor<13x21x3xi8>) -> tensor<13x21x3xui16>
+ %1 = tosa.cast %0 {input_unsigned = true} : (tensor<13x21x3xui16>) -> tensor<13x21x3xi8>
return %1 : tensor<13x21x3xi8>
}
@@ -1556,8 +1579,8 @@ func.func @test_canonicalize_narrowing_cast_i8_to_ui16_to_i8(%arg0: tensor<13x21
// CHECK-LABEL: @test_canonicalize_non_narrowing_cast_f8_to_f16_to_f8
// CHECK: return %arg0
func.func @test_canonicalize_non_narrowing_cast_f8_to_f16_to_f8(%arg0: tensor<13x21x3xf8E4M3FN>) -> tensor<13x21x3xf8E4M3FN> {
- %0 = tosa.cast %arg0 : (tensor<13x21x3xf8E4M3FN>) -> tensor<13x21x3xf16>
- %1 = tosa.cast %0 : (tensor<13x21x3xf16>) -> tensor<13x21x3xf8E4M3FN>
+ %0 = tosa.cast %arg0 {input_unsigned = false} : (tensor<13x21x3xf8E4M3FN>) -> tensor<13x21x3xf16>
+ %1 = tosa.cast %0 {input_unsigned = false} : (tensor<13x21x3xf16>) -> tensor<13x21x3xf8E4M3FN>
return %1 : tensor<13x21x3xf8E4M3FN>
}
@@ -1567,8 +1590,8 @@ func.func @test_canonicalize_non_narrowing_cast_f8_to_f16_to_f8(%arg0: tensor<13
// CHECK: %[[OUT:.+]] = tosa.cast %arg0 : (tensor<13x21x3xf8E4M3FN>)
// CHECK: return %[[OUT]] : tensor<13x21x3xf16>
func.func @test_canonicalize_non_narrowing_cast_f8_to_f8E4M3FN_to_f16(%arg0: tensor<13x21x3xf8E4M3FN>) -> tensor<13x21x3xf16> {
- %0 = tosa.cast %arg0 : (tensor<13x21x3xf8E4M3FN>) -> tensor<13x21x3xf32>
- %1 = tosa.cast %0 : (tensor<13x21x3xf32>) -> tensor<13x21x3xf16>
+ %0 = tosa.cast %arg0 {input_unsigned = false} : (tensor<13x21x3xf8E4M3FN>) -> tensor<13x21x3xf32>
+ %1 = tosa.cast %0 {input_unsigned = false} : (tensor<13x21x3xf32>) -> tensor<13x21x3xf16>
return %1 : tensor<13x21x3xf16>
}
@@ -1578,8 +1601,8 @@ func.func @test_canonicalize_non_narrowing_cast_f8_to_f8E4M3FN_to_f16(%arg0: ten
// CHECK: %[[OUT:.+]] = tosa.cast %arg0 : (tensor<13x21x3xf8E5M2>) -> tensor<13x21x3xf16>
// CHECK: return %[[OUT]] : tensor<13x21x3xf16>
func.func @test_canonicalize_non_narrowing_cast_f8_to_f32_to_f16(%arg0: tensor<13x21x3xf8E5M2>) -> tensor<13x21x3xf16> {
- %0 = tosa.cast %arg0 : (tensor<13x21x3xf8E5M2>) -> tensor<13x21x3xf32>
- %1 = tosa.cast %0 : (tensor<13x21x3xf32>) -> tensor<13x21x3xf16>
+ %0 = tosa.cast %arg0 {input_unsigned = false} : (tensor<13x21x3xf8E5M2>) -> tensor<13x21x3xf32>
+ %1 = tosa.cast %0 {input_unsigned = false} : (tensor<13x21x3xf32>) -> tensor<13x21x3xf16>
return %1 : tensor<13x21x3xf16>
}
@@ -1589,8 +1612,8 @@ func.func @test_canonicalize_non_narrowing_cast_f8_to_f32_to_f16(%arg0: tensor<1
// CHECK: %[[OUT:.+]] = tosa.cast %arg0 : (tensor<13x21x3xf16>) -> tensor<13x21x3xf8E5M2>
// CHECK: return %[[OUT]] : tensor<13x21x3xf8E5M2>
func.func @test_canonicalize_non_narrowing_cast_f16_to_f32_to_f8(%arg0: tensor<13x21x3xf16>) -> tensor<13x21x3xf8E5M2> {
- %0 = tosa.cast %arg0 : (tensor<13x21x3xf16>) -> tensor<13x21x3xf32>
- %1 = tosa.cast %0 : (tensor<13x21x3xf32>) -> tensor<13x21x3xf8E5M2>
+ %0 = tosa.cast %arg0 {input_unsigned = false} : (tensor<13x21x3xf16>) -> tensor<13x21x3xf32>
+ %1 = tosa.cast %0 {input_unsigned = false} : (tensor<13x21x3xf32>) -> tensor<13x21x3xf8E5M2>
return %1 : tensor<13x21x3xf8E5M2>
}
@@ -1600,8 +1623,8 @@ func.func @test_canonicalize_non_narrowing_cast_f16_to_f32_to_f8(%arg0: tensor<1
// CHECK: %[[OUT:.+]] = tosa.cast %arg0 : (tensor<13x21x3xi8>) -> tensor<13x21x3xf16>
// CHECK: return %[[OUT]] : tensor<13x21x3xf16>
func.func @test_canonicalize_non_narrowing_cast_i8_to_i32_to_f16(%arg0: tensor<13x21x3xi8>) -> tensor<13x21x3xf16> {
- %0 = tosa.cast %arg0 : (tensor<13x21x3xi8>) -> tensor<13x21x3xi32>
- %1 = tosa.cast %0 : (tensor<13x21x3xi32>) -> tensor<13x21x3xf16>
+ %0 = tosa.cast %arg0 {input_unsigned = false} : (tensor<13x21x3xi8>) -> tensor<13x21x3xi32>
+ %1 = tosa.cast %0 {input_unsigned = false} : (tensor<13x21x3xi32>) -> tensor<13x21x3xf16>
return %1 : tensor<13x21x3xf16>
}
@@ -1611,8 +1634,8 @@ func.func @test_canonicalize_non_narrowing_cast_i8_to_i32_to_f16(%arg0: tensor<1
// CHECK: tosa.cast
// CHECK: tosa.cast
func.func @test_canonicalize_non_narrowing_cast_f8E4M3FN_to_f16_to_f8E5M2(%arg0: tensor<13x21x3xf8E4M3FN>) -> tensor<13x21x3xf8E5M2> {
- %0 = tosa.cast %arg0 : (tensor<13x21x3xf8E4M3FN>) -> tensor<13x21x3xf16>
- %1 = tosa.cast %0 : (tensor<13x21x3xf16>) -> tensor<13x21x3xf8E5M2>
+ %0 = tosa.cast %arg0 {input_unsigned = false} : (tensor<13x21x3xf8E4M3FN>) -> tensor<13x21x3xf16>
+ %1 = tosa.cast %0 {input_unsigned = false} : (tensor<13x21x3xf16>) -> tensor<13x21x3xf8E5M2>
return %1 : tensor<13x21x3xf8E5M2>
}
@@ -1622,8 +1645,8 @@ func.func @test_canonicalize_non_narrowing_cast_f8E4M3FN_to_f16_to_f8E5M2(%arg0:
// CHECK: tosa.cast
// CHECK: tosa.cast
func.func @test_canonicalize_non_narrowing_cast_f8E4M3FN_to_f16_to_f8E4M3(%arg0: tensor<13x21x3xf8E4M3FN>) -> tensor<13x21x3xf8E4M3> {
- %0 = tosa.cast %arg0 : (tensor<13x21x3xf8E4M3FN>) -> tensor<13x21x3xf16>
- %1 = tosa.cast %0 : (tensor<13x21x3xf16>) -> tensor<13x21x3xf8E4M3>
+ %0 = tosa.cast %arg0 {input_unsigned = false} : (tensor<13x21x3xf8E4M3FN>) -> tensor<13x21x3xf16>
+ %1 = tosa.cast %0 {input_unsigned = false} : (tensor<13x21x3xf16>) -> tensor<13x21x3xf8E4M3>
return %1 : tensor<13x21x3xf8E4M3>
}
@@ -1633,8 +1656,8 @@ func.func @test_canonicalize_non_narrowing_cast_f8E4M3FN_to_f16_to_f8E4M3(%arg0:
// CHECK: tosa.cast
// CHECK: tosa.cast
func.func @test_canonicalize_non_narrowing_cast_f8E4M3_to_f8E4M3FN_to_f16(%arg0: tensor<13x21x3xf8E4M3>) -> tensor<13x21x3xf16> {
- %0 = tosa.cast %arg0 : (tensor<13x21x3xf8E4M3>) -> tensor<13x21x3xf8E4M3FN>
- %1 = tosa.cast %0 : (tensor<13x21x3xf8E4M3FN>) -> tensor<13x21x3xf16>
+ %0 = tosa.cast %arg0 {input_unsigned = false} : (tensor<13x21x3xf8E4M3>) -> tensor<13x21x3xf8E4M3FN>
+ %1 = tosa.cast %0 {input_unsigned = false} : (tensor<13x21x3xf8E4M3FN>) -> tensor<13x21x3xf16>
return %1 : tensor<13x21x3xf16>
}
@@ -1644,8 +1667,8 @@ func.func @test_canonicalize_non_narrowing_cast_f8E4M3_to_f8E4M3FN_to_f16(%arg0:
// CHECK: tosa.cast
// CHECK: tosa.cast
func.func @test_canonicalize_non_narrowing_cast_f6E3M2FN_to_f8E4M3FNUZ_to_f16(%arg0: tensor<13x21x3xf6E3M2FN>) -> tensor<13x21x3xf16> {
- %0 = tosa.cast %arg0 : (tensor<13x21x3xf6E3M2FN>) -> tensor<13x21x3xf8E4M3FNUZ>
- %1 = tosa.cast %0 : (tensor<13x21x3xf8E4M3FNUZ>) -> tensor<13x21x3xf16>
+ %0 = tosa.cast %arg0 {input_unsigned = false} : (tensor<13x21x3xf6E3M2FN>) -> tensor<13x21x3xf8E4M3FNUZ>
+ %1 = tosa.cast %0 {input_unsigned = false} : (tensor<13x21x3xf8E4M3FNUZ>) -> tensor<13x21x3xf16>
return %1 : tensor<13x21x3xf16>
}
@@ -1655,8 +1678,8 @@ func.func @test_canonicalize_non_narrowing_cast_f6E3M2FN_to_f8E4M3FNUZ_to_f16(%a
// CHECK: tosa.cast
// CHECK: tosa.cast
func.func @test_canonicalize_non_narrowing_cast_f6E3M2FN_to_f8E4M3FN_to_f16_unsupported(%arg0: tensor<13x21x3xf6E3M2FN>) -> tensor<13x21x3xf16> {
- %0 = tosa.cast %arg0 : (tensor<13x21x3xf6E3M2FN>) -> tensor<13x21x3xf8E4M3FN>
- %1 = tosa.cast %0 : (tensor<13x21x3xf8E4M3FN>) -> tensor<13x21x3xf16>
+ %0 = tosa.cast %arg0 {input_unsigned = false} : (tensor<13x21x3xf6E3M2FN>) -> tensor<13x21x3xf8E4M3FN>
+ %1 = tosa.cast %0 {input_unsigned = false} : (tensor<13x21x3xf8E4M3FN>) -> tensor<13x21x3xf16>
return %1 : tensor<13x21x3xf16>
}
@@ -1666,8 +1689,8 @@ func.func @test_canonicalize_non_narrowing_cast_f6E3M2FN_to_f8E4M3FN_to_f16_unsu
// CHECK: tosa.cast
// CHECK: tosa.cast
func.func @test_canonicalize_non_narrowing_cast_i1_to_f32_unsupported(%arg0: tensor<13x21x3xi1>) -> tensor<13x21x3xf32> {
- %0 = tosa.cast %arg0 : (tensor<13x21x3xi1>) -> tensor<13x21x3xi8>
- %1 = tosa.cast %0 : (tensor<13x21x3xi8>) -> tensor<13x21x3xf32>
+ %0 = tosa.cast %arg0 {input_unsigned = false} : (tensor<13x21x3xi1>) -> tensor<13x21x3xi8>
+ %1 = tosa.cast %0 {input_unsigned = false} : (tensor<13x21x3xi8>) -> tensor<13x21x3xf32>
return %1 : tensor<13x21x3xf32>
}
@@ -1677,8 +1700,8 @@ func.func @test_canonicalize_non_narrowing_cast_i1_to_f32_unsupported(%arg0: ten
// CHECK: tosa.cast
// CHECK: tosa.cast
func.func @test_canonicalize_non_narrowing_cast_i8_to_i64_unsupported(%arg0: tensor<13x21x3xi8>) -> tensor<13x21x3xi64> {
- %0 = tosa.cast %arg0 : (tensor<13x21x3xi8>) -> tensor<13x21x3xi32>
- %1 = tosa.cast %0 : (tensor<13x21x3xi32>) -> tensor<13x21x3xi64>
+ %0 = tosa.cast %arg0 {input_unsigned = false} : (tensor<13x21x3xi8>) -> tensor<13x21x3xi32>
+ %1 = tosa.cast %0 {input_unsigned = false} : (tensor<13x21x3xi32>) -> tensor<13x21x3xi64>
return %1 : tensor<13x21x3xi64>
}
@@ -1688,8 +1711,8 @@ func.func @test_canonicalize_non_narrowing_cast_i8_to_i64_unsupported(%arg0: ten
// CHECK: tosa.cast
// CHECK: tosa.cast
func.func @test_canonicalize_non_narrowing_cast_f16_to_bf16_unsupported(%arg0: tensor<13x21x3xf16>) -> tensor<13x21x3xbf16> {
- %0 = tosa.cast %arg0 : (tensor<13x21x3xf16>) -> tensor<13x21x3xf32>
- %1 = tosa.cast %0 : (tensor<13x21x3xf32>) -> tensor<13x21x3xbf16>
+ %0 = tosa.cast %arg0 {input_unsigned = false} : (tensor<13x21x3xf16>) -> tensor<13x21x3xf32>
+ %1 = tosa.cast %0 {input_unsigned = false} : (tensor<13x21x3xf32>) -> tensor<13x21x3xbf16>
return %1 : tensor<13x21x3xbf16>
}
@@ -1699,8 +1722,8 @@ func.func @test_canonicalize_non_narrowing_cast_f16_to_bf16_unsupported(%arg0: t
// CHECK: tosa.cast
// CHECK: tosa.cast
func.func @test_canonicalize_non_narrowing_cast_i8_to_f8E4M3FN_unsupported(%arg0: tensor<13x21x3xi8>) -> tensor<13x21x3xf8E4M3FN> {
- %0 = tosa.cast %arg0 : (tensor<13x21x3xi8>) -> tensor<13x21x3xf32>
- %1 = tosa.cast %0 : (tensor<13x21x3xf32>) -> tensor<13x21x3xf8E4M3FN>
+ %0 = tosa.cast %arg0 {input_unsigned = false} : (tensor<13x21x3xi8>) -> tensor<13x21x3xf32>
+ %1 = tosa.cast %0 {input_unsigned = false} : (tensor<13x21x3xf32>) -> tensor<13x21x3xf8E4M3FN>
return %1 : tensor<13x21x3xf8E4M3FN>
}
@@ -1709,8 +1732,8 @@ func.func @test_canonicalize_non_narrowing_cast_i8_to_f8E4M3FN_unsupported(%arg0
// CHECK-LABEL: @test_canonicalize_cast_from_cast_to_block_scaled_type_f4E2M1_through_f32
// CHECK: return %arg0 : tensor<15x3x2x256x!tosa.block_scaled<BLOCK_SHAPE_32:f8E8M0FNU:f4E2M1FN>>
func.func @test_canonicalize_cast_from_cast_to_block_scaled_type_f4E2M1_through_f32(%arg0: tensor<15x3x2x256x!tosa.block_scaled<BLOCK_SHAPE_32:f8E8M0FNU:f4E2M1FN>>) -> tensor<15x3x2x256x!tosa.block_scaled<BLOCK_SHAPE_32:f8E8M0FNU:f4E2M1FN>> {
- %0 = tosa.cast %arg0 : (tensor<15x3x2x256x!tosa.block_scaled<BLOCK_SHAPE_32:f8E8M0FNU:f4E2M1FN>>) -> tensor<15x3x2x256xf32>
- %1 = tosa.cast %0 : (tensor<15x3x2x256xf32>) -> tensor<15x3x2x256x!tosa.block_scaled<BLOCK_SHAPE_32:f8E8M0FNU:f4E2M1FN>>
+ %0 = tosa.cast %arg0 {input_unsigned = false} : (tensor<15x3x2x256x!tosa.block_scaled<BLOCK_SHAPE_32:f8E8M0FNU:f4E2M1FN>>) -> tensor<15x3x2x256xf32>
+ %1 = tosa.cast %0 {input_unsigned = false} : (tensor<15x3x2x256xf32>) -> tensor<15x3x2x256x!tosa.block_scaled<BLOCK_SHAPE_32:f8E8M0FNU:f4E2M1FN>>
return %1 : tensor<15x3x2x256x!tosa.block_scaled<BLOCK_SHAPE_32:f8E8M0FNU:f4E2M1FN>>
}
@@ -1719,8 +1742,8 @@ func.func @test_canonicalize_cast_from_cast_to_block_scaled_type_f4E2M1_through_
// CHECK-LABEL: @test_canonicalize_cast_from_cast_to_block_scaled_type_f8E5M2_through_f32
// CHECK: return %arg0 : tensor<160x!tosa.block_scaled<BLOCK_SHAPE_32:f8E8M0FNU:f8E5M2>>
func.func @test_canonicalize_cast_from_cast_to_block_scaled_type_f8E5M2_through_f32(%arg0: tensor<160x!tosa.block_scaled<BLOCK_SHAPE_32:f8E8M0FNU:f8E5M2>>) -> tensor<160x!tosa.block_scaled<BLOCK_SHAPE_32:f8E8M0FNU:f8E5M2>> {
- %0 = tosa.cast %arg0 : (tensor<160x!tosa.block_scaled<BLOCK_SHAPE_32:f8E8M0FNU:f8E5M2>>) -> tensor<160xf32>
- %1 = tosa.cast %0 : (tensor<160xf32>) -> tensor<160x!tosa.block_scaled<BLOCK_SHAPE_32:f8E8M0FNU:f8E5M2>>
+ %0 = tosa.cast %arg0 {input_unsigned = false} : (tensor<160x!tosa.block_scaled<BLOCK_SHAPE_32:f8E8M0FNU:f8E5M2>>) -> tensor<160xf32>
+ %1 = tosa.cast %0 {input_unsigned = false} : (tensor<160xf32>) -> tensor<160x!tosa.block_scaled<BLOCK_SHAPE_32:f8E8M0FNU:f8E5M2>>
return %1 : tensor<160x!tosa.block_scaled<BLOCK_SHAPE_32:f8E8M0FNU:f8E5M2>>
}
@@ -1731,8 +1754,8 @@ func.func @test_canonicalize_cast_from_cast_to_block_scaled_type_f8E5M2_through_
// CHECK: %[[block_scaled:.+]] = tosa.cast %[[values]]
// CHECK: return %[[block_scaled]] : tensor<160x!tosa.block_scaled<BLOCK_SHAPE_32:f8E8M0FNU:f6E2M3FN>>
func.func @test_do_not_canonicalize_cast_from_cast_to_block_scaled_type_
diff erent_types_f8E5M2_f6E2M3_through_f32(%arg0: tensor<160x!tosa.block_scaled<BLOCK_SHAPE_32:f8E8M0FNU:f8E5M2>>) -> tensor<160x!tosa.block_scaled<BLOCK_SHAPE_32:f8E8M0FNU:f6E2M3FN>> {
- %0 = tosa.cast %arg0 : (tensor<160x!tosa.block_scaled<BLOCK_SHAPE_32:f8E8M0FNU:f8E5M2>>) -> tensor<160xf32>
- %1 = tosa.cast %0 : (tensor<160xf32>) -> tensor<160x!tosa.block_scaled<BLOCK_SHAPE_32:f8E8M0FNU:f6E2M3FN>>
+ %0 = tosa.cast %arg0 {input_unsigned = false} : (tensor<160x!tosa.block_scaled<BLOCK_SHAPE_32:f8E8M0FNU:f8E5M2>>) -> tensor<160xf32>
+ %1 = tosa.cast %0 {input_unsigned = false} : (tensor<160xf32>) -> tensor<160x!tosa.block_scaled<BLOCK_SHAPE_32:f8E8M0FNU:f6E2M3FN>>
return %1 : tensor<160x!tosa.block_scaled<BLOCK_SHAPE_32:f8E8M0FNU:f6E2M3FN>>
}
@@ -1743,8 +1766,8 @@ func.func @test_do_not_canonicalize_cast_from_cast_to_block_scaled_type_
diff eren
// CHECK: %[[block_scaled:.+]] = tosa.cast %[[values]]
// CHECK: return %[[block_scaled]] : tensor<32x!tosa.block_scaled<BLOCK_SHAPE_32:f8E8M0FNU:f6E3M2FN>>
func.func @test_do_not_canonicalize_cast_from_cast_to_block_scaled_type_
diff erent_types_f6E2M3_f6E3M2_through_f32(%arg0: tensor<32x!tosa.block_scaled<BLOCK_SHAPE_32:f8E8M0FNU:f6E2M3FN>>) -> tensor<32x!tosa.block_scaled<BLOCK_SHAPE_32:f8E8M0FNU:f6E3M2FN>> {
- %0 = tosa.cast %arg0 : (tensor<32x!tosa.block_scaled<BLOCK_SHAPE_32:f8E8M0FNU:f6E2M3FN>>) -> tensor<32xf32>
- %1 = tosa.cast %0 : (tensor<32xf32>) -> tensor<32x!tosa.block_scaled<BLOCK_SHAPE_32:f8E8M0FNU:f6E3M2FN>>
+ %0 = tosa.cast %arg0 {input_unsigned = false} : (tensor<32x!tosa.block_scaled<BLOCK_SHAPE_32:f8E8M0FNU:f6E2M3FN>>) -> tensor<32xf32>
+ %1 = tosa.cast %0 {input_unsigned = false} : (tensor<32xf32>) -> tensor<32x!tosa.block_scaled<BLOCK_SHAPE_32:f8E8M0FNU:f6E3M2FN>>
return %1 : tensor<32x!tosa.block_scaled<BLOCK_SHAPE_32:f8E8M0FNU:f6E3M2FN>>
}
@@ -1755,8 +1778,8 @@ func.func @test_do_not_canonicalize_cast_from_cast_to_block_scaled_type_
diff eren
// CHECK: %[[block_scaled:.+]] = tosa.cast %[[values]]
// CHECK: return %[[block_scaled]] : tensor<*x!tosa.block_scaled<BLOCK_SHAPE_32:f8E8M0FNU:f6E2M3FN>>
func.func @test_do_not_canonicalize_cast_from_cast_to_block_scaled_type_unranked(%arg0: tensor<3x64x!tosa.block_scaled<BLOCK_SHAPE_32:f8E8M0FNU:f6E2M3FN>>) -> tensor<*x!tosa.block_scaled<BLOCK_SHAPE_32:f8E8M0FNU:f6E2M3FN>> {
- %0 = tosa.cast %arg0 : (tensor<3x64x!tosa.block_scaled<BLOCK_SHAPE_32:f8E8M0FNU:f6E2M3FN>>) -> tensor<*xf32>
- %1 = tosa.cast %0 : (tensor<*xf32>) -> tensor<*x!tosa.block_scaled<BLOCK_SHAPE_32:f8E8M0FNU:f6E2M3FN>>
+ %0 = tosa.cast %arg0 {input_unsigned = false} : (tensor<3x64x!tosa.block_scaled<BLOCK_SHAPE_32:f8E8M0FNU:f6E2M3FN>>) -> tensor<*xf32>
+ %1 = tosa.cast %0 {input_unsigned = false} : (tensor<*xf32>) -> tensor<*x!tosa.block_scaled<BLOCK_SHAPE_32:f8E8M0FNU:f6E2M3FN>>
return %1 : tensor<*x!tosa.block_scaled<BLOCK_SHAPE_32:f8E8M0FNU:f6E2M3FN>>
}
@@ -1766,8 +1789,8 @@ func.func @test_do_not_canonicalize_cast_from_cast_to_block_scaled_type_unranked
// CHECK: tosa.cast
// CHECK: tosa.cast
func.func @test_do_not_canonicalize_cast_from_cast_to_block_scaled_type_f8E5M2_f8E4M3(%arg0: tensor<15x3x2x256x!tosa.block_scaled<BLOCK_SHAPE_32:f8E8M0FNU:f8E5M2>>) -> tensor<15x3x2x256x!tosa.block_scaled<BLOCK_SHAPE_32:f8E8M0FNU:f8E5M2>> {
- %0 = tosa.cast %arg0 : (tensor<15x3x2x256x!tosa.block_scaled<BLOCK_SHAPE_32:f8E8M0FNU:f8E5M2>>) -> tensor<15x3x2x256xf8E4M3FN>
- %1 = tosa.cast %0 : (tensor<15x3x2x256xf8E4M3FN>) -> tensor<15x3x2x256x!tosa.block_scaled<BLOCK_SHAPE_32:f8E8M0FNU:f8E5M2>>
+ %0 = tosa.cast %arg0 {input_unsigned = false} : (tensor<15x3x2x256x!tosa.block_scaled<BLOCK_SHAPE_32:f8E8M0FNU:f8E5M2>>) -> tensor<15x3x2x256xf8E4M3FN>
+ %1 = tosa.cast %0 {input_unsigned = false} : (tensor<15x3x2x256xf8E4M3FN>) -> tensor<15x3x2x256x!tosa.block_scaled<BLOCK_SHAPE_32:f8E8M0FNU:f8E5M2>>
return %1 : tensor<15x3x2x256x!tosa.block_scaled<BLOCK_SHAPE_32:f8E8M0FNU:f8E5M2>>
}
diff --git a/mlir/test/Dialect/Tosa/constant_folding.mlir b/mlir/test/Dialect/Tosa/constant_folding.mlir
index a2a0cab592220..678ad8cbde413 100644
--- a/mlir/test/Dialect/Tosa/constant_folding.mlir
+++ b/mlir/test/Dialect/Tosa/constant_folding.mlir
@@ -43,7 +43,7 @@ func.func @try_fold_unranked_constant_results() {
%0 = tosa.equal %lhs, %rhs : (tensor<1xi32>, tensor<1xi32>) -> tensor<*xi1>
%1 = tosa.greater %lhs, %rhs : (tensor<1xi32>, tensor<1xi32>) -> tensor<*xi1>
%2 = tosa.greater_equal %lhs, %rhs : (tensor<1xi32>, tensor<1xi32>) -> tensor<*xi1>
- %3 = tosa.cast %lhs : (tensor<1xi32>) -> tensor<*xf32>
+ %3 = tosa.cast %lhs {input_unsigned = false} : (tensor<1xi32>) -> tensor<*xf32>
%4 = tosa.reciprocal %f : (tensor<1xf32>) -> tensor<*xf32>
%5 = tosa.abs %f : (tensor<1xf32>) -> tensor<*xf32>
return
@@ -959,7 +959,7 @@ func.func @test_slice_resource_no_fold() -> tensor<1x1xi32> {
func.func @cast_float_to_float() -> tensor<f16> {
%splat = "tosa.const"() {values = dense<42.0> : tensor<f32>} : () -> tensor<f32>
// CHECK: %[[SPLAT:.+]] = "tosa.const"() <{values = dense<4.200000e+01> : tensor<f16>}
- %cast = tosa.cast %splat : (tensor<f32>) -> tensor<f16>
+ %cast = tosa.cast %splat {input_unsigned = false} : (tensor<f32>) -> tensor<f16>
// CHECK: return %[[SPLAT]]
return %cast : tensor<f16>
}
@@ -970,18 +970,40 @@ func.func @cast_float_to_float() -> tensor<f16> {
func.func @cast_int_to_float() -> tensor<f16> {
%splat = "tosa.const"() {values = dense<4> : tensor<i32>} : () -> tensor<i32>
// CHECK: %[[SPLAT:.+]] = "tosa.const"() <{values = dense<4.000000e+00> : tensor<f16>}
- %cast = tosa.cast %splat : (tensor<i32>) -> tensor<f16>
+ %cast = tosa.cast %splat {input_unsigned = false} : (tensor<i32>) -> tensor<f16>
// CHECK: return %[[SPLAT]]
return %cast : tensor<f16>
}
// -----
+// CHECK: func.func @cast_signless_to_float_input_unsigned
+func.func @cast_signless_to_float_input_unsigned() -> tensor<f16> {
+ %splat = "tosa.const"() {values = dense<200> : tensor<i8>} : () -> tensor<i8>
+ // CHECK: %[[SPLAT:.+]] = "tosa.const"() <{values = dense<2.000000e+02> : tensor<f16>}
+ %cast = tosa.cast %splat {input_unsigned = true} : (tensor<i8>) -> tensor<f16>
+ // CHECK: return %[[SPLAT]]
+ return %cast : tensor<f16>
+}
+
+// -----
+
+// CHECK: func.func @cast_int_to_int_input_unsigned
+func.func @cast_int_to_int_input_unsigned() -> tensor<i32> {
+ %splat = "tosa.const"() {values = dense<200> : tensor<i8>} : () -> tensor<i8>
+ // CHECK: %[[SPLAT:.+]] = "tosa.const"() <{values = dense<200> : tensor<i32>}
+ %cast = tosa.cast %splat {input_unsigned = true} : (tensor<i8>) -> tensor<i32>
+ // CHECK: return %[[SPLAT]]
+ return %cast : tensor<i32>
+}
+
+// -----
+
// CHECK: func.func @cast_float_to_int
func.func @cast_float_to_int() -> tensor<i16> {
%splat = "tosa.const"() {values = dense<-4.0> : tensor<f32>} : () -> tensor<f32>
// CHECK: %[[SPLAT:.+]] = "tosa.const"() <{values = dense<-4> : tensor<i16>}
- %cast = tosa.cast %splat : (tensor<f32>) -> tensor<i16>
+ %cast = tosa.cast %splat {input_unsigned = false} : (tensor<f32>) -> tensor<i16>
// CHECK: return %[[SPLAT]]
return %cast : tensor<i16>
}
@@ -992,7 +1014,7 @@ func.func @cast_float_to_int() -> tensor<i16> {
func.func @cast_float_to_int_round() -> tensor<i16> {
%splat = "tosa.const"() {values = dense<-3.5> : tensor<f32>} : () -> tensor<f32>
// CHECK: %[[SPLAT:.+]] = "tosa.const"() <{values = dense<-4> : tensor<i16>}
- %cast = tosa.cast %splat : (tensor<f32>) -> tensor<i16>
+ %cast = tosa.cast %splat {input_unsigned = false} : (tensor<f32>) -> tensor<i16>
// CHECK: return %[[SPLAT]]
return %cast : tensor<i16>
}
@@ -1003,7 +1025,7 @@ func.func @cast_float_to_int_round() -> tensor<i16> {
func.func @cast_float_to_int_saturates_high() -> tensor<i8> {
%splat = "tosa.const"() {values = dense<1.000000e+20> : tensor<f32>} : () -> tensor<f32>
// CHECK: %[[SPLAT:.+]] = "tosa.const"() <{values = dense<127> : tensor<i8>}
- %cast = tosa.cast %splat : (tensor<f32>) -> tensor<i8>
+ %cast = tosa.cast %splat {input_unsigned = false} : (tensor<f32>) -> tensor<i8>
// CHECK: return %[[SPLAT]]
return %cast : tensor<i8>
}
@@ -1014,7 +1036,7 @@ func.func @cast_float_to_int_saturates_high() -> tensor<i8> {
func.func @cast_float_to_int_saturates_low() -> tensor<i8> {
%splat = "tosa.const"() {values = dense<-1.000000e+20> : tensor<f32>} : () -> tensor<f32>
// CHECK: %[[SPLAT:.+]] = "tosa.const"() <{values = dense<-128> : tensor<i8>}
- %cast = tosa.cast %splat : (tensor<f32>) -> tensor<i8>
+ %cast = tosa.cast %splat {input_unsigned = false} : (tensor<f32>) -> tensor<i8>
// CHECK: return %[[SPLAT]]
return %cast : tensor<i8>
}
@@ -1025,7 +1047,7 @@ func.func @cast_float_to_int_saturates_low() -> tensor<i8> {
func.func @cast_float_to_unsigned_int_saturates_low() -> tensor<ui8> {
%splat = "tosa.const"() {values = dense<-1.000000e+20> : tensor<f32>} : () -> tensor<f32>
// CHECK: %[[SPLAT:.+]] = "tosa.const"() <{values = dense<0> : tensor<ui8>}
- %cast = tosa.cast %splat : (tensor<f32>) -> tensor<ui8>
+ %cast = tosa.cast %splat {input_unsigned = false} : (tensor<f32>) -> tensor<ui8>
// CHECK: return %[[SPLAT]]
return %cast : tensor<ui8>
}
@@ -1036,7 +1058,7 @@ func.func @cast_float_to_unsigned_int_saturates_low() -> tensor<ui8> {
func.func @cast_float_to_unsigned_int_saturates_high() -> tensor<ui8> {
%splat = "tosa.const"() {values = dense<1.000000e+20> : tensor<f32>} : () -> tensor<f32>
// CHECK: %[[SPLAT:.+]] = "tosa.const"() <{values = dense<255> : tensor<ui8>}
- %cast = tosa.cast %splat : (tensor<f32>) -> tensor<ui8>
+ %cast = tosa.cast %splat {input_unsigned = false} : (tensor<f32>) -> tensor<ui8>
// CHECK: return %[[SPLAT]]
return %cast : tensor<ui8>
}
@@ -1047,7 +1069,7 @@ func.func @cast_float_to_unsigned_int_saturates_high() -> tensor<ui8> {
func.func @cast_int_to_int_trunc() -> tensor<i16> {
%splat = "tosa.const"() {values = dense<-1> : tensor<i32>} : () -> tensor<i32>
// CHECK: %[[SPLAT:.+]] = "tosa.const"() <{values = dense<-1> : tensor<i16>}
- %cast = tosa.cast %splat : (tensor<i32>) -> tensor<i16>
+ %cast = tosa.cast %splat {input_unsigned = false} : (tensor<i32>) -> tensor<i16>
// CHECK: return %[[SPLAT]]
return %cast : tensor<i16>
}
@@ -1058,7 +1080,7 @@ func.func @cast_int_to_int_trunc() -> tensor<i16> {
func.func @cast_int_to_int_sign() -> tensor<i32> {
%splat = "tosa.const"() {values = dense<-1> : tensor<i16>} : () -> tensor<i16>
// CHECK: %[[SPLAT:.+]] = "tosa.const"() <{values = dense<-1> : tensor<i32>}
- %cast = tosa.cast %splat : (tensor<i16>) -> tensor<i32>
+ %cast = tosa.cast %splat {input_unsigned = false} : (tensor<i16>) -> tensor<i32>
// CHECK: return %[[SPLAT]]
return %cast : tensor<i32>
}
diff --git a/mlir/test/Dialect/Tosa/invalid.mlir b/mlir/test/Dialect/Tosa/invalid.mlir
index 4ba9a868b07b4..19fb6390365a9 100644
--- a/mlir/test/Dialect/Tosa/invalid.mlir
+++ b/mlir/test/Dialect/Tosa/invalid.mlir
@@ -9,12 +9,11 @@
func.func @test_cast(%arg0: tensor<i1>) -> tensor<5xi32> {
// expected-error at +1{{'tosa.cast' op requires the same shape for all operands and results}}
- %1 = "tosa.cast"(%arg0) : (tensor<i1>) -> tensor<5xi32>
+ %1 = "tosa.cast"(%arg0) {input_unsigned = false} : (tensor<i1>) -> tensor<5xi32>
return %1 : tensor<5xi32>
}
// -----
-
func.func @test_const() -> tensor<1xf32> {
// expected-error at +1{{'tosa.const' op expected same attr/result element types}}
%0 = "tosa.const"() {values = dense<1> : tensor<1xi32>} : () -> tensor<1xf32>
@@ -2170,7 +2169,7 @@ func.func @test_conv2d_block_scaled(%arg0: tensor<*xf4E2M1FN>, %arg1: tensor<*xf
func.func @test_cast_f32_plain_fp4(%arg0: tensor<4x32xf32>) -> tensor<4x32xf4E2M1FN> {
// expected-error at +1 {{'tosa.cast' op illegal: operation operand/result data types did not align with any profile or extension, got (f32,fp4e2m1)}}
- %0 = tosa.cast %arg0 : (tensor<4x32xf32>) -> tensor<4x32xf4E2M1FN>
+ %0 = tosa.cast %arg0 {input_unsigned = false} : (tensor<4x32xf32>) -> tensor<4x32xf4E2M1FN>
return %0 : tensor<4x32xf4E2M1FN>
}
@@ -2178,7 +2177,7 @@ func.func @test_cast_f32_plain_fp4(%arg0: tensor<4x32xf32>) -> tensor<4x32xf4E2M
func.func @test_cast_fp4_block_scaled(%arg0: tensor<4x32xf4E2M1FN>) -> tensor<4x32x!tosa.block_scaled<BLOCK_SHAPE_32:f8E8M0FNU:f4E2M1FN>> {
// expected-error at +1 {{'tosa.cast' op illegal: operation operand/result data types did not align with any profile or extension, got (fp4e2m1,bs32_fp8e8m0_fp4e2m1), did you mean (fp8e4m3,bs32_fp8e8m0_fp4e2m1)? Otherwise, please refer to the 'supported data types' for 'tosa.cast' in the specification.}}
- %0 = tosa.cast %arg0 : (tensor<4x32xf4E2M1FN>) -> tensor<4x32x!tosa.block_scaled<BLOCK_SHAPE_32:f8E8M0FNU:f4E2M1FN>>
+ %0 = tosa.cast %arg0 {input_unsigned = false} : (tensor<4x32xf4E2M1FN>) -> tensor<4x32x!tosa.block_scaled<BLOCK_SHAPE_32:f8E8M0FNU:f4E2M1FN>>
return %0 : tensor<4x32x!tosa.block_scaled<BLOCK_SHAPE_32:f8E8M0FNU:f4E2M1FN>>
}
@@ -2186,7 +2185,7 @@ func.func @test_cast_fp4_block_scaled(%arg0: tensor<4x32xf4E2M1FN>) -> tensor<4x
func.func @test_cast_block_scaled_fp6e2m3(%arg0: tensor<4x32x!tosa.block_scaled<BLOCK_SHAPE_32:f8E8M0FNU:f4E2M1FN>>) -> tensor<4x32xf6E2M3FN> {
// expected-error at +1 {{'tosa.cast' op illegal: operation operand/result data types did not align with any profile or extension, got (bs32_fp8e8m0_fp4e2m1,fp6e2m3), did you mean (bs32_fp8e8m0_fp4e2m1,fp8e4m3)? Otherwise, please refer to the 'supported data types' for 'tosa.cast' in the specification.}}
- %0 = tosa.cast %arg0 : (tensor<4x32x!tosa.block_scaled<BLOCK_SHAPE_32:f8E8M0FNU:f4E2M1FN>>) -> tensor<4x32xf6E2M3FN>
+ %0 = tosa.cast %arg0 {input_unsigned = false} : (tensor<4x32x!tosa.block_scaled<BLOCK_SHAPE_32:f8E8M0FNU:f4E2M1FN>>) -> tensor<4x32xf6E2M3FN>
return %0 : tensor<4x32xf6E2M3FN>
}
@@ -2194,6 +2193,6 @@ func.func @test_cast_block_scaled_fp6e2m3(%arg0: tensor<4x32x!tosa.block_scaled<
func.func @test_cast_fp6e3m2_block_scaled(%arg0: tensor<4x32xf6E3M2FN>) -> tensor<4x32x!tosa.block_scaled<BLOCK_SHAPE_32:f8E8M0FNU:!tosa.mxint8>> {
// expected-error at +1 {{'tosa.cast' op illegal: operation operand/result data types did not align with any profile or extension, got (fp6e3m2,bs32_fp8e8m0_mxint8), did you mean (fp8e4m3,bs32_fp8e8m0_mxint8)? Otherwise, please refer to the 'supported data types' for 'tosa.cast' in the specification.}}
- %0 = tosa.cast %arg0 : (tensor<4x32xf6E3M2FN>) -> tensor<4x32x!tosa.block_scaled<BLOCK_SHAPE_32:f8E8M0FNU:!tosa.mxint8>>
+ %0 = tosa.cast %arg0 {input_unsigned = false} : (tensor<4x32xf6E3M2FN>) -> tensor<4x32x!tosa.block_scaled<BLOCK_SHAPE_32:f8E8M0FNU:!tosa.mxint8>>
return %0 : tensor<4x32x!tosa.block_scaled<BLOCK_SHAPE_32:f8E8M0FNU:!tosa.mxint8>>
}
diff --git a/mlir/test/Dialect/Tosa/invalid_extension.mlir b/mlir/test/Dialect/Tosa/invalid_extension.mlir
index c7e814c703985..e7d76459897ea 100644
--- a/mlir/test/Dialect/Tosa/invalid_extension.mlir
+++ b/mlir/test/Dialect/Tosa/invalid_extension.mlir
@@ -330,49 +330,49 @@ func.func @test_resize_mxfp(%arg0: tensor<1x32x32x32x!tosa.block_scaled<BLOCK_SH
// -----
func.func @test_cast_i8_bf16(%arg0: tensor<13x21x3xi8>) -> tensor<13x21x3xbf16> {
// expected-error at +1 {{'tosa.cast' op illegal: requires any of [bf16] profiles/extensions to be specified in the target environment}}
- %0 = tosa.cast %arg0 : (tensor<13x21x3xi8>) -> tensor<13x21x3xbf16>
+ %0 = tosa.cast %arg0 {input_unsigned = false} : (tensor<13x21x3xi8>) -> tensor<13x21x3xbf16>
return %0 : tensor<13x21x3xbf16>
}
// -----
func.func @test_cast_bf16_i8(%arg0: tensor<13x21x3xbf16>) -> tensor<13x21x3xi8> {
// expected-error at +1 {{'tosa.cast' op illegal: requires any of [bf16] profiles/extensions to be specified in the target environment}}
- %0 = tosa.cast %arg0 : (tensor<13x21x3xbf16>) -> tensor<13x21x3xi8>
+ %0 = tosa.cast %arg0 {input_unsigned = false} : (tensor<13x21x3xbf16>) -> tensor<13x21x3xi8>
return %0 : tensor<13x21x3xi8>
}
// -----
func.func @test_cast_f32_bf16(%arg0: tensor<13x21x3xf32>) -> tensor<13x21x3xbf16> {
// expected-error at +1 {{'tosa.cast' op illegal: requires any of [bf16] profiles/extensions to be specified in the target environment}}
- %0 = tosa.cast %arg0 : (tensor<13x21x3xf32>) -> tensor<13x21x3xbf16>
+ %0 = tosa.cast %arg0 {input_unsigned = false} : (tensor<13x21x3xf32>) -> tensor<13x21x3xbf16>
return %0 : tensor<13x21x3xbf16>
}
// -----
func.func @test_cast_f32_block_scaled(%arg0: tensor<4x32xf32>) -> tensor<4x32x!tosa.block_scaled<BLOCK_SHAPE_32:f8E8M0FNU:f4E2M1FN>> {
// expected-error at +1 {{'tosa.cast' op illegal: requires all of [mx_common, mx_fp4e2m1] profiles/extensions to be specified in the target environment}}
- %0 = tosa.cast %arg0 : (tensor<4x32xf32>) -> tensor<4x32x!tosa.block_scaled<BLOCK_SHAPE_32:f8E8M0FNU:f4E2M1FN>>
+ %0 = tosa.cast %arg0 {input_unsigned = false} : (tensor<4x32xf32>) -> tensor<4x32x!tosa.block_scaled<BLOCK_SHAPE_32:f8E8M0FNU:f4E2M1FN>>
return %0 : tensor<4x32x!tosa.block_scaled<BLOCK_SHAPE_32:f8E8M0FNU:f4E2M1FN>>
}
// -----
func.func @test_cast_block_scaled_f32(%arg0: tensor<4x32x!tosa.block_scaled<BLOCK_SHAPE_32:f8E8M0FNU:f4E2M1FN>>) -> tensor<4x32xf32> {
// expected-error at +1 {{'tosa.cast' op illegal: requires all of [mx_common, mx_fp4e2m1] profiles/extensions to be specified in the target environment}}
- %0 = tosa.cast %arg0 : (tensor<4x32x!tosa.block_scaled<BLOCK_SHAPE_32:f8E8M0FNU:f4E2M1FN>>) -> tensor<4x32xf32>
+ %0 = tosa.cast %arg0 {input_unsigned = false} : (tensor<4x32x!tosa.block_scaled<BLOCK_SHAPE_32:f8E8M0FNU:f4E2M1FN>>) -> tensor<4x32xf32>
return %0 : tensor<4x32xf32>
}
// -----
func.func @test_cast_bf16_block_scaled(%arg0: tensor<4x32xbf16>) -> tensor<4x32x!tosa.block_scaled<BLOCK_SHAPE_32:f8E8M0FNU:f4E2M1FN>> {
// expected-error at +1 {{'tosa.cast' op illegal: requires all of [bf16, mx_common, mx_fp4e2m1] profiles/extensions to be specified in the target environment}}
- %0 = tosa.cast %arg0 : (tensor<4x32xbf16>) -> tensor<4x32x!tosa.block_scaled<BLOCK_SHAPE_32:f8E8M0FNU:f4E2M1FN>>
+ %0 = tosa.cast %arg0 {input_unsigned = false} : (tensor<4x32xbf16>) -> tensor<4x32x!tosa.block_scaled<BLOCK_SHAPE_32:f8E8M0FNU:f4E2M1FN>>
return %0 : tensor<4x32x!tosa.block_scaled<BLOCK_SHAPE_32:f8E8M0FNU:f4E2M1FN>>
}
// -----
func.func @test_cast_fp8_block_scaled(%arg0: tensor<4x32xf8E4M3FN>) -> tensor<4x32x!tosa.block_scaled<BLOCK_SHAPE_32:f8E8M0FNU:!tosa.mxint8>> {
// expected-error at +1 {{'tosa.cast' op illegal: requires all of [fp8e4m3, mx_common, mx_int8] profiles/extensions to be specified in the target environment}}
- %0 = tosa.cast %arg0 : (tensor<4x32xf8E4M3FN>) -> tensor<4x32x!tosa.block_scaled<BLOCK_SHAPE_32:f8E8M0FNU:!tosa.mxint8>>
+ %0 = tosa.cast %arg0 {input_unsigned = false} : (tensor<4x32xf8E4M3FN>) -> tensor<4x32x!tosa.block_scaled<BLOCK_SHAPE_32:f8E8M0FNU:!tosa.mxint8>>
return %0 : tensor<4x32x!tosa.block_scaled<BLOCK_SHAPE_32:f8E8M0FNU:!tosa.mxint8>>
}
@@ -443,7 +443,7 @@ module {
// -----
func.func @test_cast_bf16_i32(%arg0: tensor<13x21x3xbf16>) -> tensor<13x21x3xi32> {
// expected-error at +1 {{'tosa.cast' op illegal: requires any of [bf16] profiles/extensions to be specified in the target environment}}
- %0 = tosa.cast %arg0 : (tensor<13x21x3xbf16>) -> tensor<13x21x3xi32>
+ %0 = tosa.cast %arg0 {input_unsigned = false} : (tensor<13x21x3xbf16>) -> tensor<13x21x3xi32>
return %0 : tensor<13x21x3xi32>
}
diff --git a/mlir/test/Dialect/Tosa/ops.mlir b/mlir/test/Dialect/Tosa/ops.mlir
index 43aee928aee1f..a2a7ca043bda2 100644
--- a/mlir/test/Dialect/Tosa/ops.mlir
+++ b/mlir/test/Dialect/Tosa/ops.mlir
@@ -1226,47 +1226,54 @@ func.func @test_resize_enum(%arg0: tensor<1x32x32x8xf32>) -> tensor<1x64x64x8xf3
// -----
// CHECK-LABEL: test_cast1
func.func @test_cast1(%arg0: tensor<13x21x3xi32>) -> tensor<13x21x3xf32> {
- %0 = tosa.cast %arg0 : (tensor<13x21x3xi32>) -> tensor<13x21x3xf32>
+ %0 = tosa.cast %arg0 {input_unsigned = false} : (tensor<13x21x3xi32>) -> tensor<13x21x3xf32>
+ return %0 : tensor<13x21x3xf32>
+}
+
+// -----
+// CHECK-LABEL: test_cast_input_unsigned
+func.func @test_cast_input_unsigned(%arg0: tensor<13x21x3xi32>) -> tensor<13x21x3xf32> {
+ %0 = tosa.cast %arg0 {input_unsigned = true} : (tensor<13x21x3xi32>) -> tensor<13x21x3xf32>
return %0 : tensor<13x21x3xf32>
}
// -----
// CHECK-LABEL: cast2
func.func @test_cast2(%arg0: tensor<13x21x3xi32>) -> tensor<13x21x3x!quant.uniform<u8:f32, 0.078431375324726104:128>> {
- %0 = tosa.cast %arg0 : (tensor<13x21x3xi32>) -> tensor<13x21x3x!quant.uniform<u8:f32, 0.078431375324726104:128>>
+ %0 = tosa.cast %arg0 {input_unsigned = false}: (tensor<13x21x3xi32>) -> tensor<13x21x3x!quant.uniform<u8:f32, 0.078431375324726104:128>>
return %0 : tensor<13x21x3x!quant.uniform<u8:f32, 0.078431375324726104:128>>
}
// -----
// CHECK-LABEL: cast3
func.func @test_cast3(%arg0: tensor<13x21x3xi32>) -> tensor<13x21x3x!quant.uniform<i16:f32, 0.078431375324726104:128>> {
- %0 = tosa.cast %arg0 : (tensor<13x21x3xi32>) -> tensor<13x21x3x!quant.uniform<i16:f32, 0.078431375324726104:128>>
+ %0 = tosa.cast %arg0 {input_unsigned = false} : (tensor<13x21x3xi32>) -> tensor<13x21x3x!quant.uniform<i16:f32, 0.078431375324726104:128>>
return %0 : tensor<13x21x3x!quant.uniform<i16:f32, 0.078431375324726104:128>>
}
// -----
// CHECK-LABEL: test_cast_to_block_scaled
func.func @test_cast_to_block_scaled(%arg0: tensor<4x32xf32>, %arg1: tensor<4x32xbf16>, %arg2: tensor<4x32xf8E4M3FN>) -> (tensor<4x32x!tosa.block_scaled<BLOCK_SHAPE_32:f8E8M0FNU:f4E2M1FN>>, tensor<4x32x!tosa.block_scaled<BLOCK_SHAPE_32:f8E8M0FNU:f6E3M2FN>>, tensor<4x32x!tosa.block_scaled<BLOCK_SHAPE_32:f8E8M0FNU:!tosa.mxint8>>) {
- %0 = tosa.cast %arg0 : (tensor<4x32xf32>) -> tensor<4x32x!tosa.block_scaled<BLOCK_SHAPE_32:f8E8M0FNU:f4E2M1FN>>
- %1 = tosa.cast %arg1 : (tensor<4x32xbf16>) -> tensor<4x32x!tosa.block_scaled<BLOCK_SHAPE_32:f8E8M0FNU:f6E3M2FN>>
- %2 = tosa.cast %arg2 : (tensor<4x32xf8E4M3FN>) -> tensor<4x32x!tosa.block_scaled<BLOCK_SHAPE_32:f8E8M0FNU:!tosa.mxint8>>
+ %0 = tosa.cast %arg0 {input_unsigned = false} : (tensor<4x32xf32>) -> tensor<4x32x!tosa.block_scaled<BLOCK_SHAPE_32:f8E8M0FNU:f4E2M1FN>>
+ %1 = tosa.cast %arg1 {input_unsigned = false} : (tensor<4x32xbf16>) -> tensor<4x32x!tosa.block_scaled<BLOCK_SHAPE_32:f8E8M0FNU:f6E3M2FN>>
+ %2 = tosa.cast %arg2 {input_unsigned = false} : (tensor<4x32xf8E4M3FN>) -> tensor<4x32x!tosa.block_scaled<BLOCK_SHAPE_32:f8E8M0FNU:!tosa.mxint8>>
return %0, %1, %2 : tensor<4x32x!tosa.block_scaled<BLOCK_SHAPE_32:f8E8M0FNU:f4E2M1FN>>, tensor<4x32x!tosa.block_scaled<BLOCK_SHAPE_32:f8E8M0FNU:f6E3M2FN>>, tensor<4x32x!tosa.block_scaled<BLOCK_SHAPE_32:f8E8M0FNU:!tosa.mxint8>>
}
// -----
// CHECK-LABEL: test_cast_from_block_scaled
func.func @test_cast_from_block_scaled(%arg0: tensor<4x32x!tosa.block_scaled<BLOCK_SHAPE_32:f8E8M0FNU:f8E5M2>>, %arg1: tensor<4x32x!tosa.block_scaled<BLOCK_SHAPE_32:f8E8M0FNU:f6E2M3FN>>, %arg2: tensor<4x32x!tosa.block_scaled<BLOCK_SHAPE_32:f8E8M0FNU:!tosa.mxint8>>) -> (tensor<4x32xf32>, tensor<4x32xbf16>, tensor<4x32xf8E5M2>) {
- %0 = tosa.cast %arg0 : (tensor<4x32x!tosa.block_scaled<BLOCK_SHAPE_32:f8E8M0FNU:f8E5M2>>) -> tensor<4x32xf32>
- %1 = tosa.cast %arg1 : (tensor<4x32x!tosa.block_scaled<BLOCK_SHAPE_32:f8E8M0FNU:f6E2M3FN>>) -> tensor<4x32xbf16>
- %2 = tosa.cast %arg2 : (tensor<4x32x!tosa.block_scaled<BLOCK_SHAPE_32:f8E8M0FNU:!tosa.mxint8>>) -> tensor<4x32xf8E5M2>
+ %0 = tosa.cast %arg0 {input_unsigned = false} : (tensor<4x32x!tosa.block_scaled<BLOCK_SHAPE_32:f8E8M0FNU:f8E5M2>>) -> tensor<4x32xf32>
+ %1 = tosa.cast %arg1 {input_unsigned = false} : (tensor<4x32x!tosa.block_scaled<BLOCK_SHAPE_32:f8E8M0FNU:f6E2M3FN>>) -> tensor<4x32xbf16>
+ %2 = tosa.cast %arg2 {input_unsigned = false} : (tensor<4x32x!tosa.block_scaled<BLOCK_SHAPE_32:f8E8M0FNU:!tosa.mxint8>>) -> tensor<4x32xf8E5M2>
return %0, %1, %2 : tensor<4x32xf32>, tensor<4x32xbf16>, tensor<4x32xf8E5M2>
}
// -----
// CHECK-LABEL: test_cast_block_scaled_dynamic
func.func @test_cast_block_scaled_dynamic(%arg0: tensor<?x32x!tosa.block_scaled<BLOCK_SHAPE_32:f8E8M0FNU:f8E5M2>>, %arg1: tensor<4x?x!tosa.block_scaled<BLOCK_SHAPE_32:f8E8M0FNU:f8E5M2>>) -> (tensor<?x32xf32>, tensor<4x?xf32>) {
- %0 = tosa.cast %arg0 : (tensor<?x32x!tosa.block_scaled<BLOCK_SHAPE_32:f8E8M0FNU:f8E5M2>>) -> tensor<?x32xf32>
- %1 = tosa.cast %arg1 : (tensor<4x?x!tosa.block_scaled<BLOCK_SHAPE_32:f8E8M0FNU:f8E5M2>>) -> tensor<4x?xf32>
+ %0 = tosa.cast %arg0 {input_unsigned = false} : (tensor<?x32x!tosa.block_scaled<BLOCK_SHAPE_32:f8E8M0FNU:f8E5M2>>) -> tensor<?x32xf32>
+ %1 = tosa.cast %arg1 {input_unsigned = false} : (tensor<4x?x!tosa.block_scaled<BLOCK_SHAPE_32:f8E8M0FNU:f8E5M2>>) -> tensor<4x?xf32>
return %0, %1 : tensor<?x32xf32>, tensor<4x?xf32>
}
@@ -1484,7 +1491,7 @@ func.func @test_const_f8E5M2(%arg0 : index) -> tensor<4xf8E5M2> {
// -----
// CHECK-LABEL: cast_f8E5M2
func.func @test_cast_f8E5M2(%arg0: tensor<13x21x3xf8E5M2>) -> tensor<13x21x3xf16> {
- %0 = tosa.cast %arg0 : (tensor<13x21x3xf8E5M2>) -> tensor<13x21x3xf16>
+ %0 = tosa.cast %arg0 {input_unsigned = false} : (tensor<13x21x3xf8E5M2>) -> tensor<13x21x3xf16>
return %0 : tensor<13x21x3xf16>
}
@@ -1645,7 +1652,7 @@ func.func @test_const_f8E4M3FN(%arg0 : index) -> tensor<4xf8E4M3FN> {
// -----
// CHECK-LABEL: cast_f8E4M3FN
func.func @test_cast_f8E4M3FN(%arg0: tensor<13x21x3xf8E4M3FN>) -> tensor<13x21x3xf16> {
- %0 = tosa.cast %arg0 : (tensor<13x21x3xf8E4M3FN>) -> tensor<13x21x3xf16>
+ %0 = tosa.cast %arg0 {input_unsigned = false} : (tensor<13x21x3xf8E4M3FN>) -> tensor<13x21x3xf16>
return %0 : tensor<13x21x3xf16>
}
@@ -2080,7 +2087,7 @@ func.func @test_block_scaled_const_scale_values_wide_inner_dim() -> tensor<2x64x
// CHECK-LABEL: test_block_scaled_const_cast_scale_values_no_propagate
func.func @test_block_scaled_const_cast_scale_values_no_propagate() -> tensor<2x32xf32> {
%0 = "tosa.const"() <{values = dense<tensor<2x32x!tosa.block_scaled<BLOCK_SHAPE_32:f8E8M0FNU:f8E4M3FN, {2.0, 4.0}>> : 0.0 : f8E4M3FN>}> : () -> tensor<2x32x!tosa.block_scaled<BLOCK_SHAPE_32:f8E8M0FNU:f8E4M3FN>>
- %1 = tosa.cast %0 : (tensor<2x32x!tosa.block_scaled<BLOCK_SHAPE_32:f8E8M0FNU:f8E4M3FN>>) -> tensor<2x32xf32>
+ %1 = tosa.cast %0 {input_unsigned = false} : (tensor<2x32x!tosa.block_scaled<BLOCK_SHAPE_32:f8E8M0FNU:f8E4M3FN>>) -> tensor<2x32xf32>
return %1 : tensor<2x32xf32>
}
diff --git a/mlir/test/Dialect/Tosa/profile_all_unsupported.mlir b/mlir/test/Dialect/Tosa/profile_all_unsupported.mlir
index 1c2899151cf4e..8cba320230486 100644
--- a/mlir/test/Dialect/Tosa/profile_all_unsupported.mlir
+++ b/mlir/test/Dialect/Tosa/profile_all_unsupported.mlir
@@ -316,7 +316,7 @@ func.func @test_transpose(%arg0: tensor<13x21x3xi1>) -> tensor<3x13x21xi1> {
// -----
func.func @test_cast_i32_f32(%arg0: tensor<13x21x3xi32>) -> tensor<13x21x3xf32> {
// expected-error at +1 {{'tosa.cast' op illegal: requires any of [pro_fp] profiles/extensions to be specified in the target environment}}
- %0 = tosa.cast %arg0 : (tensor<13x21x3xi32>) -> tensor<13x21x3xf32>
+ %0 = tosa.cast %arg0 {input_unsigned = false} : (tensor<13x21x3xi32>) -> tensor<13x21x3xf32>
return %0 : tensor<13x21x3xf32>
}
diff --git a/mlir/test/Dialect/Tosa/profile_pro_fp_unsupported.mlir b/mlir/test/Dialect/Tosa/profile_pro_fp_unsupported.mlir
index 3f0ffab5fcd7d..7d8bd3024b940 100644
--- a/mlir/test/Dialect/Tosa/profile_pro_fp_unsupported.mlir
+++ b/mlir/test/Dialect/Tosa/profile_pro_fp_unsupported.mlir
@@ -120,7 +120,7 @@ func.func @test_concat(%arg0: tensor<13x21x3xf32>, %arg1: tensor<13x21x3xf32>) -
// -----
func.func @test_cast_i32_f32(%arg0: tensor<13x21x3xi32>) -> tensor<13x21x3xf32> {
// expected-error at +1 {{'tosa.cast' op illegal: requires any of [pro_fp] profiles/extensions to be specified in the target environment}}
- %0 = tosa.cast %arg0 : (tensor<13x21x3xi32>) -> tensor<13x21x3xf32>
+ %0 = tosa.cast %arg0 {input_unsigned = false} : (tensor<13x21x3xi32>) -> tensor<13x21x3xf32>
return %0 : tensor<13x21x3xf32>
}
diff --git a/mlir/test/Dialect/Tosa/profile_pro_int_unsupported.mlir b/mlir/test/Dialect/Tosa/profile_pro_int_unsupported.mlir
index c6239d1bba72b..f951c302c049a 100644
--- a/mlir/test/Dialect/Tosa/profile_pro_int_unsupported.mlir
+++ b/mlir/test/Dialect/Tosa/profile_pro_int_unsupported.mlir
@@ -251,28 +251,28 @@ func.func @test_resize(%arg0: tensor<1x32x32x8xi8>) -> tensor<1x64x64x8xi32> {
// -----
func.func @test_cast_i1_i8(%arg0: tensor<13x21x3xi1>) -> tensor<13x21x3xi8> {
// expected-error at +1 {{'tosa.cast' op illegal: requires any of [pro_int] profiles/extensions to be specified in the target environment}}
- %0 = tosa.cast %arg0 : (tensor<13x21x3xi1>) -> tensor<13x21x3xi8>
+ %0 = tosa.cast %arg0 {input_unsigned = false} : (tensor<13x21x3xi1>) -> tensor<13x21x3xi8>
return %0 : tensor<13x21x3xi8>
}
// -----
func.func @test_cast_i8_i32(%arg0: tensor<13x21x3xi8>) -> tensor<13x21x3xi32> {
// expected-error at +1 {{'tosa.cast' op illegal: requires any of [pro_int] profiles/extensions to be specified in the target environment}}
- %0 = tosa.cast %arg0 : (tensor<13x21x3xi8>) -> tensor<13x21x3xi32>
+ %0 = tosa.cast %arg0 {input_unsigned = false} : (tensor<13x21x3xi8>) -> tensor<13x21x3xi32>
return %0 : tensor<13x21x3xi32>
}
// -----
func.func @test_cast_i16_i8(%arg0: tensor<13x21x3xi16>) -> tensor<13x21x3xi8> {
// expected-error at +1 {{'tosa.cast' op illegal: requires any of [pro_int] profiles/extensions to be specified in the target environment}}
- %0 = tosa.cast %arg0 : (tensor<13x21x3xi16>) -> tensor<13x21x3xi8>
+ %0 = tosa.cast %arg0 {input_unsigned = false} : (tensor<13x21x3xi16>) -> tensor<13x21x3xi8>
return %0 : tensor<13x21x3xi8>
}
// -----
func.func @test_cast_i32_i16(%arg0: tensor<13x21x3xi32>) -> tensor<13x21x3xi16> {
// expected-error at +1 {{'tosa.cast' op illegal: requires any of [pro_int] profiles/extensions to be specified in the target environment}}
- %0 = tosa.cast %arg0 : (tensor<13x21x3xi32>) -> tensor<13x21x3xi16>
+ %0 = tosa.cast %arg0 {input_unsigned = false} : (tensor<13x21x3xi32>) -> tensor<13x21x3xi16>
return %0 : tensor<13x21x3xi16>
}
diff --git a/mlir/test/Dialect/Tosa/tosa-downgrade-1-1-to-1-0.mlir b/mlir/test/Dialect/Tosa/tosa-downgrade-1-1-to-1-0.mlir
index 1532ec91d53e8..1dd67777dee10 100644
--- a/mlir/test/Dialect/Tosa/tosa-downgrade-1-1-to-1-0.mlir
+++ b/mlir/test/Dialect/Tosa/tosa-downgrade-1-1-to-1-0.mlir
@@ -5,7 +5,7 @@
// CHECK: %[[I8_TO_F32:.+]] = tosa.cast %[[BOOL_TO_I8]] : (tensor<13x21x3xi8>) -> tensor<13x21x3xf32>
// CHECK: return %[[I8_TO_F32]]
func.func @test_bool_to_fp32(%arg0: tensor<13x21x3xi1>) -> tensor<13x21x3xf32> {
- %0 = tosa.cast %arg0 : (tensor<13x21x3xi1>) -> tensor<13x21x3xf32>
+ %0 = tosa.cast %arg0 {input_unsigned = false} : (tensor<13x21x3xi1>) -> tensor<13x21x3xf32>
return %0 : tensor<13x21x3xf32>
}
@@ -16,7 +16,7 @@ func.func @test_bool_to_fp32(%arg0: tensor<13x21x3xi1>) -> tensor<13x21x3xf32> {
// CHECK: %[[I8_TO_F32:.+]] = tosa.cast %[[BOOL_TO_I8]] : (tensor<*xi8>) -> tensor<*xf32>
// CHECK: return %[[I8_TO_F32]]
func.func @test_bool_to_fp32_unranked(%arg0: tensor<*xi1>) -> tensor<*xf32> {
- %0 = tosa.cast %arg0 : (tensor<*xi1>) -> tensor<*xf32>
+ %0 = tosa.cast %arg0 {input_unsigned = false} : (tensor<*xi1>) -> tensor<*xf32>
return %0 : tensor<*xf32>
}
@@ -27,7 +27,7 @@ func.func @test_bool_to_fp32_unranked(%arg0: tensor<*xi1>) -> tensor<*xf32> {
// CHECK: %[[I8_TO_BOOL:.+]] = tosa.cast %[[FP32_TO_I8]] : (tensor<13x?x3xi8>) -> tensor<13x?x3xi1>
// CHECK: return %[[I8_TO_BOOL]]
func.func @test_fp32_to_bool_ranked_dynamic(%arg0: tensor<13x?x3xf32>) -> tensor<13x?x3xi1> {
- %0 = tosa.cast %arg0 : (tensor<13x?x3xf32>) -> tensor<13x?x3xi1>
+ %0 = tosa.cast %arg0 {input_unsigned = false} : (tensor<13x?x3xf32>) -> tensor<13x?x3xi1>
return %0 : tensor<13x?x3xi1>
}
@@ -38,7 +38,7 @@ func.func @test_fp32_to_bool_ranked_dynamic(%arg0: tensor<13x?x3xf32>) -> tensor
// CHECK: %[[I8_TO_BOOL:.+]] = tosa.cast %[[FP32_TO_I8]] : (tensor<*xi8>) -> tensor<*xi1>
// CHECK: return %[[I8_TO_BOOL]]
func.func @test_unranked_fp32_to_bool(%arg0: tensor<*xf32>) -> tensor<*xi1> {
- %0 = tosa.cast %arg0 : (tensor<*xf32>) -> tensor<*xi1>
+ %0 = tosa.cast %arg0 {input_unsigned = false} : (tensor<*xf32>) -> tensor<*xi1>
return %0 : tensor<*xi1>
}
@@ -48,7 +48,7 @@ func.func @test_unranked_fp32_to_bool(%arg0: tensor<*xf32>) -> tensor<*xi1> {
// CHECK: %[[CAST:.+]] = tosa.cast %arg0 : (tensor<13x21x3xi1>) -> tensor<13x21x3xi8>
// CHECK: return %[[CAST]]
func.func @test_preserve_bool_to_i8(%arg0: tensor<13x21x3xi1>) -> tensor<13x21x3xi8> {
- %0 = tosa.cast %arg0 : (tensor<13x21x3xi1>) -> tensor<13x21x3xi8>
+ %0 = tosa.cast %arg0 {input_unsigned = false} : (tensor<13x21x3xi1>) -> tensor<13x21x3xi8>
return %0 : tensor<13x21x3xi8>
}
@@ -92,7 +92,7 @@ func.func @test_preserve_gather_i8_i32(%arg0: tensor<13x21x3xi8>, %arg1: tensor<
// CHECK: %[[SCATTER_I8:.+]] = tosa.scatter %[[VALUES_IN_TO_I8]], %arg1, %[[INPUT_TO_I8]] : (tensor<13x52x3xi8>, tensor<13x26xi32>, tensor<13x26x3xi8>) -> tensor<13x52x3xi8>
// CHECK: %[[I8_TO_BOOL:.+]] = tosa.cast %[[SCATTER_I8]] : (tensor<13x52x3xi8>) -> tensor<13x52x3xi1>
// CHECK: return %[[I8_TO_BOOL]]
-func.func @test_scatter_bool_i32(%arg0: tensor<13x52x3xi1>, %arg1: tensor<13x26xi32>, %arg2: tensor<13x26x3xi1>) -> tensor<13x52x3xi1> {
+func.func @test_scatter_bool_i32(%arg0: tensor<13x52x3xi1>, %arg1 : tensor<13x26xi32>, %arg2: tensor<13x26x3xi1>) -> tensor<13x52x3xi1> {
%0 = tosa.scatter %arg0, %arg1, %arg2 : (tensor<13x52x3xi1>, tensor<13x26xi32>, tensor<13x26x3xi1>) -> tensor<13x52x3xi1>
return %0 : tensor<13x52x3xi1>
}
diff --git a/mlir/test/Dialect/Tosa/tosa-infer-shapes.mlir b/mlir/test/Dialect/Tosa/tosa-infer-shapes.mlir
index d0d1906524f83..c0b5ec23abee2 100644
--- a/mlir/test/Dialect/Tosa/tosa-infer-shapes.mlir
+++ b/mlir/test/Dialect/Tosa/tosa-infer-shapes.mlir
@@ -69,7 +69,7 @@ func.func @test_unary_f32(%arg0 : tensor<4xf32>) -> () {
%11 = tosa.sigmoid %arg0 : (tensor<4xf32>) -> tensor<*xf32>
// CHECK: tosa.cast %arg0 : (tensor<4xf32>) -> tensor<4xi32>
- %12 = tosa.cast %arg0 : (tensor<4xf32>) -> tensor<*xi32>
+ %12 = tosa.cast %arg0 {input_unsigned = false} : (tensor<4xf32>) -> tensor<*xi32>
// CHECK: tosa.erf %arg0 : (tensor<4xf32>) -> tensor<4xf32>
%13 = tosa.erf %arg0 : (tensor<4xf32>) -> tensor<*xf32>
@@ -357,7 +357,7 @@ func.func @test_dynamic_mixed_matmul(%arg0 : tensor<?x3x?xi32>, %arg1 : tensor<?
// CHECK-LABEL: @test_unranked_zero_points_matmul
func.func @test_unranked_zero_points_matmul(%arg0: tensor<1x2x3xf32>, %arg1: tensor<1x3x4xf32>, %zero_point: tensor<1xf32>) -> tensor<1x2x4xf32> {
// CHECK: %[[ZP:.*]] = tosa.cast %arg2 : (tensor<1xf32>) -> tensor<1xf32>
- %zero_point_unranked = "tosa.cast"(%zero_point) : (tensor<1xf32>) -> tensor<*xf32>
+ %zero_point_unranked = "tosa.cast"(%zero_point) {input_unsigned = false} : (tensor<1xf32>) -> tensor<*xf32>
// CHECK: tosa.matmul %arg0, %arg1, %[[ZP]], %[[ZP]] : (tensor<1x2x3xf32>, tensor<1x3x4xf32>, tensor<1xf32>, tensor<1xf32>) -> tensor<1x2x4xf32>
%0 = tosa.matmul %arg0, %arg1, %zero_point_unranked, %zero_point_unranked : (tensor<1x2x3xf32>, tensor<1x3x4xf32>, tensor<*xf32>, tensor<*xf32>) -> tensor<1x2x4xf32>
return %0 : tensor<1x2x4xf32>
@@ -435,7 +435,7 @@ func.func @test_unranked_matmul_t(%arg0 : tensor<*xi32>, %arg1 : tensor<*xi32>)
func.func @test_accepts_unranked_scalar_tensor(%arg0: tensor<1x2x2xf32>, %arg1: tensor<1xf32>) -> tensor<*xf32> {
// CHECK-DAG: %[[SHAPE:.*]] = tosa.const_shape {values = dense<[0, 0, 0, 1, 0, 1]> : tensor<6xindex>} : () -> !tosa.shape<6>
// CHECK-DAG: %[[ZP:.*]] = tosa.cast %arg1 : (tensor<1xf32>) -> tensor<1xf32>
- %0 = tosa.cast %arg1 : (tensor<1xf32>) -> tensor<*xf32>
+ %0 = tosa.cast %arg1 {input_unsigned = false} : (tensor<1xf32>) -> tensor<*xf32>
%1 = tosa.const_shape {values = dense<[0, 0, 0, 1, 0, 1]> : tensor<6xindex>} : () -> !tosa.shape<6>
// CHECK: %[[PAD:.*]] = tosa.pad %arg0, %[[SHAPE]], %[[ZP]] : (tensor<1x2x2xf32>, !tosa.shape<6>, tensor<1xf32>) -> tensor<1x3x3xf32>
%2 = tosa.pad %arg0, %1, %0 : (tensor<1x2x2xf32>, !tosa.shape<6>, tensor<*xf32>) -> tensor<*xf32>
@@ -450,7 +450,7 @@ func.func @test_accepts_unranked_scalar_tensor(%arg0: tensor<1x2x2xf32>, %arg1:
// CHECK-LABEL: @test_unranked_scalar_i8_tensor
func.func @test_unranked_scalar_i8_tensor(%arg0: tensor<4xi32>, %arg1: tensor<4xi32>, %arg2: tensor<1xi8>) -> tensor<4xi32> {
// CHECK: %[[SHIFT:.*]] = tosa.cast %arg2 : (tensor<1xi8>) -> tensor<1xi8>
- %shift = tosa.cast %arg2 : (tensor<1xi8>) -> tensor<*xi8>
+ %shift = tosa.cast %arg2 {input_unsigned = false} : (tensor<1xi8>) -> tensor<*xi8>
// CHECK: tosa.mul %arg0, %arg1, %[[SHIFT]] : (tensor<4xi32>, tensor<4xi32>, tensor<1xi8>) -> tensor<4xi32>
%0 = tosa.mul %arg0, %arg1, %shift : (tensor<4xi32>, tensor<4xi32>, tensor<*xi8>) -> tensor<4xi32>
return %0 : tensor<4xi32>
@@ -1877,7 +1877,7 @@ func.func @test_tosa_use_def_chain(%arg0: tensor<1x32x32x3xf32>, %arg1: tensor<1
func.func @test_multiple_non_inferrable_consumers(%arg0: tensor<1x2x8xf32>) {
// CHECK: %[[TOSA_CAST:.*]] = tosa.cast %[[ARG]] : (tensor<1x2x8xf32>) -> tensor<1x2x8xf32>
// CHECK: %[[TENSOR_CAST:.*]] = tensor.cast %[[TOSA_CAST]] : tensor<1x2x8xf32> to tensor<?x2x8xf32>
- %0 = tosa.cast %arg0 : (tensor<1x2x8xf32>) -> tensor<?x2x8xf32>
+ %0 = tosa.cast %arg0 {input_unsigned = false} : (tensor<1x2x8xf32>) -> tensor<?x2x8xf32>
%c0 = arith.constant 0 : index
%dim = tensor.dim %0, %c0 : tensor<?x2x8xf32>
diff --git a/mlir/test/Dialect/Tosa/tosa-narrow-f64-to-f32-aggressive.mlir b/mlir/test/Dialect/Tosa/tosa-narrow-f64-to-f32-aggressive.mlir
index 2f02e3e9e7609..40e9a7b2dba5f 100644
--- a/mlir/test/Dialect/Tosa/tosa-narrow-f64-to-f32-aggressive.mlir
+++ b/mlir/test/Dialect/Tosa/tosa-narrow-f64-to-f32-aggressive.mlir
@@ -51,7 +51,7 @@ func.func @test_convert_input_parameters(%arg0: tensor<1x3xf64>) -> tensor<1x3xf
// FUNCBOUND: %[[IDENTITY:.*]] = tosa.identity %[[IN]] : (tensor<1x3xf32>) -> tensor<1x3xf32>
%0 = tosa.identity %arg0 : (tensor<1x3xf64>) -> tensor<1x3xf64>
// COMMON: %[[TO_F32:.*]] = tosa.cast %[[IDENTITY]] : (tensor<1x3xf32>) -> tensor<1x3xf32>
- %1 = tosa.cast %0 : (tensor<1x3xf64>) -> tensor<1x3xf32>
+ %1 = tosa.cast %0 {input_unsigned = false} : (tensor<1x3xf64>) -> tensor<1x3xf32>
// DEFAULT: return %[[TO_F32]] : tensor<1x3xf32>
// FUNCBOUND: return %[[TO_F32]] : tensor<1x3xf32>
return %1 : tensor<1x3xf32>
diff --git a/mlir/test/Dialect/Tosa/tosa-narrow-i64-to-i32-aggressive.mlir b/mlir/test/Dialect/Tosa/tosa-narrow-i64-to-i32-aggressive.mlir
index b7d0a025a04e7..5d8ca4dcd5ad5 100644
--- a/mlir/test/Dialect/Tosa/tosa-narrow-i64-to-i32-aggressive.mlir
+++ b/mlir/test/Dialect/Tosa/tosa-narrow-i64-to-i32-aggressive.mlir
@@ -17,10 +17,10 @@ func.func @test_convert_input_parameters(%arg0: tensor<1x513x513x3xi64>) -> tens
// DEFAULT: %[[FUNC_BOUND_CAST:.*]] = tosa.cast %[[IN]] : (tensor<1x513x513x3xi64>) -> tensor<1x513x513x3xi32>
// DEFAULT: %[[CAST1:.*]] = tosa.cast %[[FUNC_BOUND_CAST]] : (tensor<1x513x513x3xi32>) -> tensor<1x513x513x3xi32>
// FUNCBOUND: %[[CAST1:.*]] = tosa.cast %[[IN]] : (tensor<1x513x513x3xi32>) -> tensor<1x513x513x3xi32>
- %0 = tosa.cast %arg0 : (tensor<1x513x513x3xi64>) -> tensor<1x513x513x3xi32>
+ %0 = tosa.cast %arg0 {input_unsigned = false} : (tensor<1x513x513x3xi64>) -> tensor<1x513x513x3xi32>
// COMMON: %[[CAST2:.*]] = tosa.cast %[[CAST1]] : (tensor<1x513x513x3xi32>) -> tensor<1x513x513x3xf32>
- %1 = tosa.cast %0 : (tensor<1x513x513x3xi32>) -> tensor<1x513x513x3xf32>
+ %1 = tosa.cast %0 {input_unsigned = false} : (tensor<1x513x513x3xi32>) -> tensor<1x513x513x3xf32>
return %1 : tensor<1x513x513x3xf32>
}
diff --git a/mlir/test/Dialect/Tosa/tosa-narrow-i64-to-i32.mlir b/mlir/test/Dialect/Tosa/tosa-narrow-i64-to-i32.mlir
index f51c5b714378e..4ff8a38548c81 100644
--- a/mlir/test/Dialect/Tosa/tosa-narrow-i64-to-i32.mlir
+++ b/mlir/test/Dialect/Tosa/tosa-narrow-i64-to-i32.mlir
@@ -32,7 +32,7 @@ func.func @test_i64_argmax_cast(%arg0: tensor<1x513x513x19xi8>) -> tensor<1x513x
// COMMON: %[[ARGMAX:.*]] = tosa.argmax %arg0 {axis = 3 : i32} : (tensor<1x513x513x19xi8>) -> tensor<1x513x513xi32>
%0 = tosa.argmax %arg0 {axis = 3 : i32} : (tensor<1x513x513x19xi8>) -> tensor<1x513x513xi64>
// COMMON: tosa.cast %[[ARGMAX]] : (tensor<1x513x513xi32>) -> tensor<1x513x513xf32>
- %1 = tosa.cast %0 : (tensor<1x513x513xi64>) -> tensor<1x513x513xf32>
+ %1 = tosa.cast %0 {input_unsigned = false} : (tensor<1x513x513xi64>) -> tensor<1x513x513xf32>
return %1 : tensor<1x513x513xf32>
}
@@ -63,7 +63,7 @@ func.func @test_regions(%arg0: tensor<1x2xi32>, %arg1: tensor<1xi32>, %arg2: ten
// COMMON: %[[ARGMAX:.*]] = tosa.argmax %arg0 {axis = 1 : i32} : (tensor<1x2xi32>) -> tensor<1xi32>
%1 = tosa.argmax %arg0 {axis = 1 : i32} : (tensor<1x2xi32>) -> tensor<1xi64>
// COMMON: %[[CAST:.*]] = tosa.cast %[[ARGMAX]] : (tensor<1xi32>) -> tensor<1xi32>
- %2 = tosa.cast %1 : (tensor<1xi64>) -> tensor<1xi32>
+ %2 = tosa.cast %1 {input_unsigned = false} : (tensor<1xi64>) -> tensor<1xi32>
// COMMON: tosa.yield %[[CAST]] : tensor<1xi32>
tosa.yield %2 : tensor<1xi32>
} else {
@@ -167,7 +167,7 @@ func.func @test_transpose(%arg0: tensor<13x21x3xi64>) -> tensor<3x13x21xi64> {
// CHECK-LABEL: test_transition_to_i64
func.func @test_transition_to_i64(%arg0: tensor<1xi32>) -> tensor<1xi64> {
// COMMON: %[[CAST:.*]] = tosa.cast %arg0 : (tensor<1xi32>) -> tensor<1xi32>
- %0 = tosa.cast %arg0 : (tensor<1xi32>) -> tensor<1xi64>
+ %0 = tosa.cast %arg0 {input_unsigned = false} : (tensor<1xi32>) -> tensor<1xi64>
// COMMON: %[[IDENTITY1:.*]] = tosa.identity %[[CAST]] : (tensor<1xi32>) -> tensor<1xi32>
%1 = tosa.identity %0 : (tensor<1xi64>) -> tensor<1xi64>
// COMMON: %[[IDENTITY2:.*]] = tosa.identity %[[IDENTITY1]] : (tensor<1xi32>) -> tensor<1xi32>
@@ -189,13 +189,27 @@ func.func @test_transition_from_i64(%arg0: tensor<1xi64>) -> tensor<1xi32> {
// COMMON: %[[IDENTITY2:.*]] = tosa.identity %[[IDENTITY1]] : (tensor<1xi32>) -> tensor<1xi32>
%1 = tosa.identity %0 : (tensor<1xi64>) -> tensor<1xi64>
// COMMON: %[[OUT_CAST:.*]] = tosa.cast %[[IDENTITY2]] : (tensor<1xi32>) -> tensor<1xi32>
- %2 = tosa.cast %1 : (tensor<1xi64>) -> tensor<1xi32>
+ %2 = tosa.cast %1 {input_unsigned = false} : (tensor<1xi64>) -> tensor<1xi32>
// COMMON: return %[[OUT_CAST]] : tensor<1xi32>
return %2 : tensor<1xi32>
}
// -----
+// CHECK-LABEL test_transition_from_i64_input_unsigned
+func.func @test_transition_from_i64_input_unsigned(%arg0: tensor<1xui64>) -> tensor<1xui64> {
+ // DEFAULT: %[[CAST:.*]] = tosa.cast %arg0 {input_unsigned = true} : (tensor<1xui64>) -> tensor<1xi32>
+ // FUNCBOUND: %[[IDENTITY:.*]] = tosa.identity %arg0 : (tensor<1xi32>) -> tensor<1xi32>
+ // DEFAULT: %[[IDENTITY:.*]] = tosa.identity %[[CAST]] : (tensor<1xi32>) -> tensor<1xi32>
+ %0 = tosa.identity %arg0 : (tensor<1xui64>) -> tensor<1xui64>
+ // DEFAULT: %[[OUT_CAST:.*]] = tosa.cast %[[IDENTITY]] : (tensor<1xi32>) -> tensor<1xui64>
+ // DEFAULT: return %[[OUT_CAST]] : tensor<1xui64>
+ // FUNCBOUND: return %[[IDENTITY]] : tensor<1xi32>
+ return %0 : tensor<1xui64>
+}
+
+// -----
+
// CHECK-LABEL: test_clamp
func.func @test_clamp(%arg0: tensor<100xi64>) -> tensor<100xi64> {
// COMMON: tosa.clamp %{{.*}} {max_val = 2147483647 : i32, min_val = -2147483648 : i32} : (tensor<100xi32>) -> tensor<100xi32>
diff --git a/mlir/test/Dialect/Tosa/tosa-validation-valid.mlir b/mlir/test/Dialect/Tosa/tosa-validation-valid.mlir
index 0543e9395f42d..a5276248eecc4 100644
--- a/mlir/test/Dialect/Tosa/tosa-validation-valid.mlir
+++ b/mlir/test/Dialect/Tosa/tosa-validation-valid.mlir
@@ -47,3 +47,11 @@ func.func @test_pad_large_input_rank(%arg0: tensor<13x21x3x1x1x1xf32>) -> tensor
%1 = tosa.pad %arg0, %padding, %0 : (tensor<13x21x3x1x1x1xf32>, !tosa.shape<12>, tensor<1xf32>) -> tensor<13x21x3x1x1x1xf32>
return %1 : tensor<13x21x3x1x1x1xf32>
}
+
+// -----
+
+// CHECK-LABEL: test_cast_input_unsigned_false
+func.func @test_cast_input_unsigned_false(%arg0: tensor<13x21x3xi32>) -> tensor<13x21x3xf32> {
+ %0 = tosa.cast %arg0 {input_unsigned = false} : (tensor<13x21x3xi32>) -> tensor<13x21x3xf32>
+ return %0 : tensor<13x21x3xf32>
+}
diff --git a/mlir/test/Dialect/Tosa/tosa-validation-version-1p0-invalid.mlir b/mlir/test/Dialect/Tosa/tosa-validation-version-1p0-invalid.mlir
index 4112b23957a63..1a8aedf8d3c62 100644
--- a/mlir/test/Dialect/Tosa/tosa-validation-version-1p0-invalid.mlir
+++ b/mlir/test/Dialect/Tosa/tosa-validation-version-1p0-invalid.mlir
@@ -158,6 +158,14 @@ func.func @test_cast_bool_fp32(%arg0: tensor<13x21x3xi1>) -> tensor<13x21x3xf32>
// -----
+func.func @test_cast_input_unsigned_true_wrong_version(%arg0: tensor<13x21x3xi32>) -> tensor<13x21x3xf32> {
+ // expected-error at +1 {{'tosa.cast' op failed attribute check: CAST attribute input_unsigned requires version 1.1.draft (got 1.0)}}
+ %0 = tosa.cast %arg0 {input_unsigned = true} : (tensor<13x21x3xi32>) -> tensor<13x21x3xf32>
+ return %0 : tensor<13x21x3xf32>
+}
+
+// -----
+
func.func @test_cast_bool_i64(%arg0: tensor<13x21x3xi1>) -> tensor<13x21x3xi64> {
// expected-error at +1 {{'tosa.cast' op illegal: requires specification version compatible with 1.1.draft (got 1.0) and requires any of [int64] profiles/extensions to be specified in the target environment}}
%0 = tosa.cast %arg0 : (tensor<13x21x3xi1>) -> tensor<13x21x3xi64>
diff --git a/mlir/test/Dialect/Tosa/tosa-validation-version-1p1-valid.mlir b/mlir/test/Dialect/Tosa/tosa-validation-version-1p1-valid.mlir
index 2a9f9287d1f7b..0de49d17de282 100644
--- a/mlir/test/Dialect/Tosa/tosa-validation-version-1p1-valid.mlir
+++ b/mlir/test/Dialect/Tosa/tosa-validation-version-1p1-valid.mlir
@@ -455,7 +455,7 @@ func.func @test_scatter_i32_i64_indices(%arg0: tensor<13x27x3xi32>, %arg1: tenso
// CHECK-LABEL: test_cast_bool_fp32
func.func @test_cast_bool_fp32(%arg0: tensor<13x21x3xi1>) -> tensor<13x21x3xf32> {
- %0 = tosa.cast %arg0 : (tensor<13x21x3xi1>) -> tensor<13x21x3xf32>
+ %0 = tosa.cast %arg0 {input_unsigned = false} : (tensor<13x21x3xi1>) -> tensor<13x21x3xf32>
return %0 : tensor<13x21x3xf32>
}
@@ -463,7 +463,7 @@ func.func @test_cast_bool_fp32(%arg0: tensor<13x21x3xi1>) -> tensor<13x21x3xf32>
// CHECK-LABEL: test_cast_bool_i64
func.func @test_cast_bool_i64(%arg0: tensor<13x21x3xi1>) -> tensor<13x21x3xi64> {
- %0 = tosa.cast %arg0 : (tensor<13x21x3xi1>) -> tensor<13x21x3xi64>
+ %0 = tosa.cast %arg0 {input_unsigned = false} : (tensor<13x21x3xi1>) -> tensor<13x21x3xi64>
return %0 : tensor<13x21x3xi64>
}
@@ -471,7 +471,7 @@ func.func @test_cast_bool_i64(%arg0: tensor<13x21x3xi1>) -> tensor<13x21x3xi64>
// CHECK-LABEL: test_cast_fp32_bool
func.func @test_cast_fp32_bool(%arg0: tensor<13x21x3xf32>) -> tensor<13x21x3xi1> {
- %0 = tosa.cast %arg0 : (tensor<13x21x3xf32>) -> tensor<13x21x3xi1>
+ %0 = tosa.cast %arg0 {input_unsigned = false} : (tensor<13x21x3xf32>) -> tensor<13x21x3xi1>
return %0 : tensor<13x21x3xi1>
}
@@ -479,7 +479,7 @@ func.func @test_cast_fp32_bool(%arg0: tensor<13x21x3xf32>) -> tensor<13x21x3xi1>
// CHECK-LABEL: test_cast_i64_bool
func.func @test_cast_i64_bool(%arg0: tensor<13x21x3xi64>) -> tensor<13x21x3xi1> {
- %0 = tosa.cast %arg0 : (tensor<13x21x3xi64>) -> tensor<13x21x3xi1>
+ %0 = tosa.cast %arg0 {input_unsigned = false} : (tensor<13x21x3xi64>) -> tensor<13x21x3xi1>
return %0 : tensor<13x21x3xi1>
}
@@ -487,13 +487,13 @@ func.func @test_cast_i64_bool(%arg0: tensor<13x21x3xi64>) -> tensor<13x21x3xi1>
// CHECK-LABEL: test_cast_to_block_scaled_types
func.func @test_cast_to_block_scaled_types(%fp16: tensor<4x32xf16>, %fp32: tensor<4x32xf32>, %bf16: tensor<4x32xbf16>, %fp8e4m3: tensor<4x32xf8E4M3FN>, %fp8e5m2: tensor<4x32xf8E5M2>) -> (tensor<4x32x!tosa.block_scaled<BLOCK_SHAPE_32:f8E8M0FNU:f4E2M1FN>>, tensor<4x32x!tosa.block_scaled<BLOCK_SHAPE_32:f8E8M0FNU:f6E2M3FN>>, tensor<4x32x!tosa.block_scaled<BLOCK_SHAPE_32:f8E8M0FNU:f6E3M2FN>>, tensor<4x32x!tosa.block_scaled<BLOCK_SHAPE_32:f8E8M0FNU:f8E4M3FN>>, tensor<4x32x!tosa.block_scaled<BLOCK_SHAPE_32:f8E8M0FNU:f8E5M2>>, tensor<4x32x!tosa.block_scaled<BLOCK_SHAPE_32:f8E8M0FNU:!tosa.mxint8>>) {
- %0 = tosa.cast %fp32 : (tensor<4x32xf32>) -> tensor<4x32x!tosa.block_scaled<BLOCK_SHAPE_32:f8E8M0FNU:f4E2M1FN>>
- %1 = tosa.cast %fp32 : (tensor<4x32xf32>) -> tensor<4x32x!tosa.block_scaled<BLOCK_SHAPE_32:f8E8M0FNU:f6E2M3FN>>
- %2 = tosa.cast %fp32 : (tensor<4x32xf32>) -> tensor<4x32x!tosa.block_scaled<BLOCK_SHAPE_32:f8E8M0FNU:f6E3M2FN>>
- %3 = tosa.cast %fp16 : (tensor<4x32xf16>) -> tensor<4x32x!tosa.block_scaled<BLOCK_SHAPE_32:f8E8M0FNU:f8E4M3FN>>
- %4 = tosa.cast %bf16 : (tensor<4x32xbf16>) -> tensor<4x32x!tosa.block_scaled<BLOCK_SHAPE_32:f8E8M0FNU:f8E5M2>>
- %5 = tosa.cast %fp8e4m3 : (tensor<4x32xf8E4M3FN>) -> tensor<4x32x!tosa.block_scaled<BLOCK_SHAPE_32:f8E8M0FNU:!tosa.mxint8>>
- %6 = tosa.cast %fp8e5m2 : (tensor<4x32xf8E5M2>) -> tensor<4x32x!tosa.block_scaled<BLOCK_SHAPE_32:f8E8M0FNU:f6E2M3FN>>
+ %0 = tosa.cast %fp32 {input_unsigned = false} : (tensor<4x32xf32>) -> tensor<4x32x!tosa.block_scaled<BLOCK_SHAPE_32:f8E8M0FNU:f4E2M1FN>>
+ %1 = tosa.cast %fp32 {input_unsigned = false} : (tensor<4x32xf32>) -> tensor<4x32x!tosa.block_scaled<BLOCK_SHAPE_32:f8E8M0FNU:f6E2M3FN>>
+ %2 = tosa.cast %fp32 {input_unsigned = false} : (tensor<4x32xf32>) -> tensor<4x32x!tosa.block_scaled<BLOCK_SHAPE_32:f8E8M0FNU:f6E3M2FN>>
+ %3 = tosa.cast %fp16 {input_unsigned = false} : (tensor<4x32xf16>) -> tensor<4x32x!tosa.block_scaled<BLOCK_SHAPE_32:f8E8M0FNU:f8E4M3FN>>
+ %4 = tosa.cast %bf16 {input_unsigned = false} : (tensor<4x32xbf16>) -> tensor<4x32x!tosa.block_scaled<BLOCK_SHAPE_32:f8E8M0FNU:f8E5M2>>
+ %5 = tosa.cast %fp8e4m3 {input_unsigned = false} : (tensor<4x32xf8E4M3FN>) -> tensor<4x32x!tosa.block_scaled<BLOCK_SHAPE_32:f8E8M0FNU:!tosa.mxint8>>
+ %6 = tosa.cast %fp8e5m2 {input_unsigned = false} : (tensor<4x32xf8E5M2>) -> tensor<4x32x!tosa.block_scaled<BLOCK_SHAPE_32:f8E8M0FNU:f6E2M3FN>>
return %0, %1, %2, %3, %4, %5 : tensor<4x32x!tosa.block_scaled<BLOCK_SHAPE_32:f8E8M0FNU:f4E2M1FN>>, tensor<4x32x!tosa.block_scaled<BLOCK_SHAPE_32:f8E8M0FNU:f6E2M3FN>>, tensor<4x32x!tosa.block_scaled<BLOCK_SHAPE_32:f8E8M0FNU:f6E3M2FN>>, tensor<4x32x!tosa.block_scaled<BLOCK_SHAPE_32:f8E8M0FNU:f8E4M3FN>>, tensor<4x32x!tosa.block_scaled<BLOCK_SHAPE_32:f8E8M0FNU:f8E5M2>>, tensor<4x32x!tosa.block_scaled<BLOCK_SHAPE_32:f8E8M0FNU:!tosa.mxint8>>
}
@@ -501,13 +501,13 @@ func.func @test_cast_to_block_scaled_types(%fp16: tensor<4x32xf16>, %fp32: tenso
// CHECK-LABEL: test_cast_from_block_scaled_types
func.func @test_cast_from_block_scaled_types(%fp4: tensor<4x32x!tosa.block_scaled<BLOCK_SHAPE_32:f8E8M0FNU:f4E2M1FN>>, %fp6e2m3: tensor<4x32x!tosa.block_scaled<BLOCK_SHAPE_32:f8E8M0FNU:f6E2M3FN>>, %fp6e3m2: tensor<4x32x!tosa.block_scaled<BLOCK_SHAPE_32:f8E8M0FNU:f6E3M2FN>>, %fp8e4m3: tensor<4x32x!tosa.block_scaled<BLOCK_SHAPE_32:f8E8M0FNU:f8E4M3FN>>, %fp8e5m2: tensor<4x32x!tosa.block_scaled<BLOCK_SHAPE_32:f8E8M0FNU:f8E5M2>>, %mxint8: tensor<4x32x!tosa.block_scaled<BLOCK_SHAPE_32:f8E8M0FNU:!tosa.mxint8>>) -> (tensor<4x32xf32>, tensor<4x32xf16>, tensor<4x32xbf16>, tensor<4x32xf8E4M3FN>, tensor<4x32xf8E5M2>) {
- %0 = tosa.cast %fp4 : (tensor<4x32x!tosa.block_scaled<BLOCK_SHAPE_32:f8E8M0FNU:f4E2M1FN>>) -> tensor<4x32xf32>
- %1 = tosa.cast %fp6e2m3 : (tensor<4x32x!tosa.block_scaled<BLOCK_SHAPE_32:f8E8M0FNU:f6E2M3FN>>) -> tensor<4x32xf32>
- %2 = tosa.cast %fp6e3m2 : (tensor<4x32x!tosa.block_scaled<BLOCK_SHAPE_32:f8E8M0FNU:f6E3M2FN>>) -> tensor<4x32xf32>
- %3 = tosa.cast %fp8e4m3 : (tensor<4x32x!tosa.block_scaled<BLOCK_SHAPE_32:f8E8M0FNU:f8E4M3FN>>) -> tensor<4x32xf16>
- %4 = tosa.cast %fp8e5m2 : (tensor<4x32x!tosa.block_scaled<BLOCK_SHAPE_32:f8E8M0FNU:f8E5M2>>) -> tensor<4x32xbf16>
- %5 = tosa.cast %mxint8 : (tensor<4x32x!tosa.block_scaled<BLOCK_SHAPE_32:f8E8M0FNU:!tosa.mxint8>>) -> tensor<4x32xf8E4M3FN>
- %6 = tosa.cast %fp4 : (tensor<4x32x!tosa.block_scaled<BLOCK_SHAPE_32:f8E8M0FNU:f4E2M1FN>>) -> tensor<4x32xf8E5M2>
+ %0 = tosa.cast %fp4 {input_unsigned = false} : (tensor<4x32x!tosa.block_scaled<BLOCK_SHAPE_32:f8E8M0FNU:f4E2M1FN>>) -> tensor<4x32xf32>
+ %1 = tosa.cast %fp6e2m3 {input_unsigned = false} : (tensor<4x32x!tosa.block_scaled<BLOCK_SHAPE_32:f8E8M0FNU:f6E2M3FN>>) -> tensor<4x32xf32>
+ %2 = tosa.cast %fp6e3m2 {input_unsigned = false} : (tensor<4x32x!tosa.block_scaled<BLOCK_SHAPE_32:f8E8M0FNU:f6E3M2FN>>) -> tensor<4x32xf32>
+ %3 = tosa.cast %fp8e4m3 {input_unsigned = false} : (tensor<4x32x!tosa.block_scaled<BLOCK_SHAPE_32:f8E8M0FNU:f8E4M3FN>>) -> tensor<4x32xf16>
+ %4 = tosa.cast %fp8e5m2 {input_unsigned = false} : (tensor<4x32x!tosa.block_scaled<BLOCK_SHAPE_32:f8E8M0FNU:f8E5M2>>) -> tensor<4x32xbf16>
+ %5 = tosa.cast %mxint8 {input_unsigned = false} : (tensor<4x32x!tosa.block_scaled<BLOCK_SHAPE_32:f8E8M0FNU:!tosa.mxint8>>) -> tensor<4x32xf8E4M3FN>
+ %6 = tosa.cast %fp4 {input_unsigned = false} : (tensor<4x32x!tosa.block_scaled<BLOCK_SHAPE_32:f8E8M0FNU:f4E2M1FN>>) -> tensor<4x32xf8E5M2>
return %0, %3, %4, %5, %6 : tensor<4x32xf32>, tensor<4x32xf16>, tensor<4x32xbf16>, tensor<4x32xf8E4M3FN>, tensor<4x32xf8E5M2>
}
diff --git a/mlir/test/Dialect/Tosa/verifier.mlir b/mlir/test/Dialect/Tosa/verifier.mlir
index 061ea403a40b5..b64c7e6cffa54 100644
--- a/mlir/test/Dialect/Tosa/verifier.mlir
+++ b/mlir/test/Dialect/Tosa/verifier.mlir
@@ -1635,6 +1635,22 @@ func.func @cast_from_block_scaled_data_scale_channel_mismatch(%arg0: tensor<4x32
// -----
+func.func @test_cast_invalid_input_unsigned_f32(%arg0: tensor<13x21x3xf32>) -> tensor<13x21x3xf16> {
+ // expected-error at +1{{'tosa.cast' op attribute input_unsigned requires integer type inputs. Got: 'f32'}}
+ %0 = tosa.cast %arg0 {input_unsigned = true} : (tensor<13x21x3xf32>) -> tensor<13x21x3xf16>
+ return %0 : tensor<13x21x3xf16>
+}
+
+// -----
+
+func.func @test_cast_invalid_input_unsigned_bool(%arg0: tensor<13x21x3xi1>) -> tensor<13x21x3xf16> {
+ // expected-error at +1{{'tosa.cast' op attribute input_unsigned requires integer type inputs. Got: 'i1'}}
+ %0 = tosa.cast %arg0 {input_unsigned = true} : (tensor<13x21x3xi1>) -> tensor<13x21x3xf16>
+ return %0 : tensor<13x21x3xf16>
+}
+
+// -----
+
func.func @test_cast_from_block_scaled_block_size_mismatch(%arg0: tensor<4x32xf4E2M1FN>, %arg1: tensor<4x1xf8E8M0FNU>) -> tensor<4x32xf32> {
// expected-error at +1 {{'tosa.cast_from_block_scaled' op expect block size to be 32, got 1}}
%0 = tosa.cast_from_block_scaled %arg0, %arg1 {block_size = #tosa.block_size<BLOCK_SIZE_1> : i32} : (tensor<4x32xf4E2M1FN>, tensor<4x1xf8E8M0FNU>) -> tensor<4x32xf32>
@@ -1693,7 +1709,7 @@ func.func @test_cast_to_block_scaled_block_size_mismatch(%arg0: tensor<4x32xf32>
func.func @test_cast_i8_block_scaled(%arg0: tensor<4x32xi8>) -> tensor<4x32x!tosa.block_scaled<BLOCK_SHAPE_32:f8E8M0FNU:f4E2M1FN>> {
// expected-error at +1 {{'tosa.cast' op requires non-block-scaled element type to be floating-point when casting to or from block scaled element type, got 'i8'}}
- %0 = tosa.cast %arg0 : (tensor<4x32xi8>) -> tensor<4x32x!tosa.block_scaled<BLOCK_SHAPE_32:f8E8M0FNU:f4E2M1FN>>
+ %0 = tosa.cast %arg0 {input_unsigned = false} : (tensor<4x32xi8>) -> tensor<4x32x!tosa.block_scaled<BLOCK_SHAPE_32:f8E8M0FNU:f4E2M1FN>>
return %0 : tensor<4x32x!tosa.block_scaled<BLOCK_SHAPE_32:f8E8M0FNU:f4E2M1FN>>
}
@@ -1701,7 +1717,7 @@ func.func @test_cast_i8_block_scaled(%arg0: tensor<4x32xi8>) -> tensor<4x32x!tos
func.func @test_cast_block_scaled_i32(%arg0: tensor<4x32x!tosa.block_scaled<BLOCK_SHAPE_32:f8E8M0FNU:f4E2M1FN>>) -> tensor<4x32xi32> {
// expected-error at +1 {{'tosa.cast' op requires non-block-scaled element type to be floating-point when casting to or from block scaled element type, got 'i32'}}
- %0 = tosa.cast %arg0 : (tensor<4x32x!tosa.block_scaled<BLOCK_SHAPE_32:f8E8M0FNU:f4E2M1FN>>) -> tensor<4x32xi32>
+ %0 = tosa.cast %arg0 {input_unsigned = false} : (tensor<4x32x!tosa.block_scaled<BLOCK_SHAPE_32:f8E8M0FNU:f4E2M1FN>>) -> tensor<4x32xi32>
return %0 : tensor<4x32xi32>
}
@@ -1709,7 +1725,7 @@ func.func @test_cast_block_scaled_i32(%arg0: tensor<4x32x!tosa.block_scaled<BLOC
func.func @test_cast_between_block_scaled(%arg0: tensor<4x32x!tosa.block_scaled<BLOCK_SHAPE_32:f8E8M0FNU:f4E2M1FN>>) -> tensor<4x32x!tosa.block_scaled<BLOCK_SHAPE_32:f8E8M0FNU:f8E4M3FN>> {
// expected-error at +1 {{'tosa.cast' op requires exactly one of input or output to have block scaled element type}}
- %0 = tosa.cast %arg0 : (tensor<4x32x!tosa.block_scaled<BLOCK_SHAPE_32:f8E8M0FNU:f4E2M1FN>>) -> tensor<4x32x!tosa.block_scaled<BLOCK_SHAPE_32:f8E8M0FNU:f8E4M3FN>>
+ %0 = tosa.cast %arg0 {input_unsigned = false} : (tensor<4x32x!tosa.block_scaled<BLOCK_SHAPE_32:f8E8M0FNU:f4E2M1FN>>) -> tensor<4x32x!tosa.block_scaled<BLOCK_SHAPE_32:f8E8M0FNU:f8E4M3FN>>
return %0 : tensor<4x32x!tosa.block_scaled<BLOCK_SHAPE_32:f8E8M0FNU:f8E4M3FN>>
}
@@ -1717,7 +1733,7 @@ func.func @test_cast_between_block_scaled(%arg0: tensor<4x32x!tosa.block_scaled<
func.func @test_block_scaled_cast_invalid_block_shape(%arg0: tensor<1x16x31x!tosa.block_scaled<BLOCK_SHAPE_32:f8E8M0FNU:f8E4M3FN>>) -> tensor<1x16x31xf32> {
// expected-error at +1 {{'tosa.cast' op operand #0 must be tosa-conformant tensor of number values: last dimension of block scaled tensor type (31) must be divisible by block size (32), but got 'tensor<1x16x31x!tosa.block_scaled<BLOCK_SHAPE_32:f8E8M0FNU:f8E4M3FN>>'}}
- %0 = tosa.cast %arg0 : (tensor<1x16x31x!tosa.block_scaled<BLOCK_SHAPE_32:f8E8M0FNU:f8E4M3FN>>) -> tensor<1x16x31xf32>
+ %0 = tosa.cast %arg0 {input_unsigned = false} : (tensor<1x16x31x!tosa.block_scaled<BLOCK_SHAPE_32:f8E8M0FNU:f8E4M3FN>>) -> tensor<1x16x31xf32>
return %0 : tensor<1x16x31xf32>
}
@@ -1725,7 +1741,7 @@ func.func @test_block_scaled_cast_invalid_block_shape(%arg0: tensor<1x16x31x!tos
func.func @test_block_scaled_cast_scalar(%arg0: tensor<!tosa.block_scaled<BLOCK_SHAPE_32:f8E8M0FNU:f8E4M3FN>>) -> tensor<f32> {
// expected-error at +1 {{'tosa.cast' op operand #0 must be tosa-conformant tensor of number values: block scaled tensor type must have rank greater than zero, but got 'tensor<!tosa.block_scaled<BLOCK_SHAPE_32:f8E8M0FNU:f8E4M3FN>>'}}
- %0 = tosa.cast %arg0 : (tensor<!tosa.block_scaled<BLOCK_SHAPE_32:f8E8M0FNU:f8E4M3FN>>) -> tensor<f32>
+ %0 = tosa.cast %arg0 {input_unsigned = false} : (tensor<!tosa.block_scaled<BLOCK_SHAPE_32:f8E8M0FNU:f8E4M3FN>>) -> tensor<f32>
return %0 : tensor<f32>
}
More information about the Mlir-commits
mailing list