Skip to content

Commit 4793f5d

Browse files
lhutton1Lukacma
authored andcommitted
[mlir][tosa] Add ext-mxfp support for const and cast ops (llvm#163641)
This commit allows const and cast ops with MXFP datatypes through the validation pass when specification version 1.1.draft is selected. Note: it doesn't include support for the mxint8 datatype. This will be added in a separate commit. Note: this commit adds support as defined in the spec in arm/tosa-specification@063846a. EXT_MXFP extension is considered experimental and subject to breaking change.
1 parent 090f24b commit 4793f5d

File tree

5 files changed

+49
-6
lines changed

5 files changed

+49
-6
lines changed

mlir/include/mlir/Dialect/Tosa/IR/TosaComplianceData.h.inc

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -855,7 +855,15 @@ extensionComplianceMap = {
855855
{{{fp8e5m2T, fp16T}, SpecificationVersion::V_1_0},
856856
{{fp8e5m2T, fp32T}, SpecificationVersion::V_1_0},
857857
{{fp16T, fp8e5m2T}, SpecificationVersion::V_1_0},
858-
{{fp32T, fp8e5m2T}, SpecificationVersion::V_1_0}}}}},
858+
{{fp32T, fp8e5m2T}, SpecificationVersion::V_1_0}}},
859+
{{Extension::bf16, Extension::mxfp},
860+
{{{fp4e2m1T, bf16T}, SpecificationVersion::V_1_1_DRAFT},
861+
{{fp6e3m2T, bf16T}, SpecificationVersion::V_1_1_DRAFT},
862+
{{fp6e2m3T, bf16T}, SpecificationVersion::V_1_1_DRAFT},
863+
{{bf16T, fp4e2m1T}, SpecificationVersion::V_1_1_DRAFT},
864+
{{bf16T, fp6e3m2T}, SpecificationVersion::V_1_1_DRAFT},
865+
{{bf16T, fp6e2m3T}, SpecificationVersion::V_1_1_DRAFT}},
866+
allOf}}},
859867
{"tosa.rescale",
860868
{{{Extension::int16},
861869
{{{i48T, i48T, i8T, i8T}, SpecificationVersion::V_1_0},
@@ -867,7 +875,12 @@ extensionComplianceMap = {
867875
{{Extension::int64}, {{{i64T}, SpecificationVersion::V_1_1_DRAFT}}},
868876
{{Extension::fp8e4m3}, {{{fp8e4m3T}, SpecificationVersion::V_1_0}}},
869877
{{Extension::fp8e5m2}, {{{fp8e5m2T}, SpecificationVersion::V_1_0}}},
870-
{{Extension::bf16}, {{{bf16T}, SpecificationVersion::V_1_0}}}}},
878+
{{Extension::bf16}, {{{bf16T}, SpecificationVersion::V_1_0}}},
879+
{{Extension::mxfp},
880+
{{{fp8ue8m0T}, SpecificationVersion::V_1_1_DRAFT},
881+
{{fp6e3m2T}, SpecificationVersion::V_1_1_DRAFT},
882+
{{fp6e2m3T}, SpecificationVersion::V_1_1_DRAFT},
883+
{{fp4e2m1T}, SpecificationVersion::V_1_1_DRAFT}}}}},
871884
{"tosa.identity",
872885
{{{Extension::int4}, {{{i4T, i4T}, SpecificationVersion::V_1_0}}},
873886
{{Extension::int16}, {{{i48T, i48T}, SpecificationVersion::V_1_0}}},

mlir/include/mlir/Dialect/Tosa/IR/TosaOps.td

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2462,7 +2462,7 @@ def Tosa_CastOp: Tosa_Op<"cast", [Pure, SameOperandsAndResultShape,
24622462

24632463
list<Availability> availability = [
24642464
Profile<[Tosa_PRO_INT, Tosa_PRO_FP]>,
2465-
Extension<[Tosa_EXT_FP8E4M3, Tosa_EXT_FP8E5M2, Tosa_EXT_BF16, Tosa_EXT_INT64]>,
2465+
Extension<[Tosa_EXT_FP8E4M3, Tosa_EXT_FP8E5M2, Tosa_EXT_BF16, Tosa_EXT_MXFP, Tosa_EXT_INT64]>,
24662466
];
24672467

24682468
let assemblyFormat = "operands attr-dict `:` functional-type(operands, results)";
@@ -2578,7 +2578,7 @@ def Tosa_ConstOp : Tosa_Op<"const", [ConstantLike, Pure,
25782578

25792579
list<Availability> availability = [
25802580
Profile<[Tosa_PRO_INT, Tosa_PRO_FP]>,
2581-
Extension<[Tosa_EXT_INT4, Tosa_EXT_INT16, Tosa_EXT_FP8E4M3, Tosa_EXT_FP8E5M2, Tosa_EXT_BF16, Tosa_EXT_INT64]>,
2581+
Extension<[Tosa_EXT_INT4, Tosa_EXT_INT16, Tosa_EXT_FP8E4M3, Tosa_EXT_FP8E5M2, Tosa_EXT_BF16, Tosa_EXT_MXFP, Tosa_EXT_INT64]>,
25822582
];
25832583

25842584
let hasFolder = 1;

mlir/test/Dialect/Tosa/availability.mlir

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -606,7 +606,7 @@ func.func @test_resize(%arg0: tensor<1x32x32x8xf32>) -> tensor<1x64x64x8xf32> {
606606
// CHECK-LABEL: cast
607607
func.func @test_cast1(%arg0: tensor<13x21x3xi32>) -> tensor<13x21x3xf32> {
608608
// CHECK: profiles: [ [pro_int, pro_fp] ]
609-
// CHECK: extensions: [ [fp8e4m3, fp8e5m2, bf16, int64] ]
609+
// CHECK: extensions: [ [fp8e4m3, fp8e5m2, bf16, mxfp, int64] ]
610610
%0 = tosa.cast %arg0 : (tensor<13x21x3xi32>) -> tensor<13x21x3xf32>
611611
return %0 : tensor<13x21x3xf32>
612612
}
@@ -626,7 +626,7 @@ func.func @test_rescale(%arg0: tensor<13x21x3x!quant.uniform<u8:f32, 0.015655439
626626
// CHECK-LABEL: test_const
627627
func.func @test_const(%arg0 : index) -> tensor<4xi32> {
628628
// CHECK: profiles: [ [pro_int, pro_fp] ]
629-
// CHECK: extensions: [ [int4, int16, fp8e4m3, fp8e5m2, bf16, int64] ]
629+
// CHECK: extensions: [ [int4, int16, fp8e4m3, fp8e5m2, bf16, mxfp, int64] ]
630630
%0 = "tosa.const"() {values = dense<[3, 0, 1, 2]> : tensor<4xi32>} : () -> tensor<4xi32>
631631
return %0 : tensor<4xi32>
632632
}

mlir/test/Dialect/Tosa/invalid_extension.mlir

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -555,3 +555,17 @@ func.func @test_argmax_int64(%arg0: tensor<1x13x13x5xf32>) -> tensor<1x13x13xi64
555555
%0 = tosa.argmax %arg0 {axis = 3 : i32} : (tensor<1x13x13x5xf32>) -> tensor<1x13x13xi64>
556556
return %0 : tensor<1x13x13xi64>
557557
}
558+
559+
// -----
560+
func.func @test_const_fp6e3m2(%arg0 : index) -> tensor<4xf6E3M2FN> {
561+
// expected-error@+1 {{'tosa.const' op illegal: requires [mxfp] but not enabled in target}}
562+
%0 = "tosa.const"() {values = dense<[0.0, 0.0, 0.0, 0.0]> : tensor<4xf6E3M2FN>} : () -> tensor<4xf6E3M2FN>
563+
return %0 : tensor<4xf6E3M2FN>
564+
}
565+
566+
// -----
567+
func.func @test_cast_f4e2m1(%arg0: tensor<13x21x3xf4E2M1FN>) -> tensor<13x21x3xbf16> {
568+
// expected-error@+1 {{'tosa.cast' op illegal: requires all of [bf16, mxfp] but not enabled in target}}
569+
%0 = tosa.cast %arg0 : (tensor<13x21x3xf4E2M1FN>) -> tensor<13x21x3xbf16>
570+
return %0 : tensor<13x21x3xbf16>
571+
}

mlir/test/Dialect/Tosa/tosa-validation-version-1p1-valid.mlir

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,19 @@ func.func @test_const_i64(%arg0 : index) -> tensor<4xi64> {
4242
%0 = "tosa.const"() {values = dense<[3, 0, 1, 2]> : tensor<4xi64>} : () -> tensor<4xi64>
4343
return %0 : tensor<4xi64>
4444
}
45+
46+
// -----
47+
48+
// CHECK-LABEL: test_const_fp6e3m2
49+
func.func @test_const_fp6e3m2(%arg0 : index) -> tensor<4xf6E3M2FN> {
50+
%0 = "tosa.const"() {values = dense<[0.0, 0.0, 0.0, 0.0]> : tensor<4xf6E3M2FN>} : () -> tensor<4xf6E3M2FN>
51+
return %0 : tensor<4xf6E3M2FN>
52+
}
53+
54+
// -----
55+
56+
// CHECK-LABEL: test_cast_f4e2m1
57+
func.func @test_cast_f4e2m1(%arg0: tensor<13x21x3xf4E2M1FN>) -> tensor<13x21x3xbf16> {
58+
%0 = tosa.cast %arg0 : (tensor<13x21x3xf4E2M1FN>) -> tensor<13x21x3xbf16>
59+
return %0 : tensor<13x21x3xbf16>
60+
}

0 commit comments

Comments
 (0)