Skip to content

Commit 48c179b

Browse files
Merge branch 'develop' into bogdan-petkovic/attn-splitkv-limit
2 parents 3473ab6 + d00e8f8 commit 48c179b

47 files changed

Lines changed: 958 additions & 637 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

mlir/include/mlir/Dialect/MIGraphX/IR/MIGraphX.td

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -229,12 +229,22 @@ def MIGraphX_UnpackOp : MIGraphX_Op<"unpack">,
229229

230230
// Quantization operations.
231231

232-
def MIGraphX_QuantizeLinearOp :
233-
MIGraphX_Op<"quantizelinear", [AllElementTypesMatch<["input", "scale"]>]>,
234-
Arguments<(ins MIXRShapedOf<[AnyFloat]>:$input,
235-
MIXRShapedOf<[AnyFloat]>:$scale,
236-
Optional<MIXRShapedOf<[AnyInteger, AnyFloat]>>:$bias)>,
237-
Results<(outs MIXRShapedOf<[AnyInteger, AnyFloat]>:$output)> {
232+
def MIGraphX_QuantizeLinearOp
233+
: MIGraphX_Op<
234+
"quantizelinear",
235+
[AllElementTypesMatch<["input", "scale"]>,
236+
PredOpTrait<
237+
"output and bias must have the same element type",
238+
Or<[CPred<"!::llvm::cast<QuantizeLinearOp>($_op).getBias()">,
239+
CPred<"::mlir::getElementTypeOrSelf("
240+
"::llvm::cast<QuantizeLinearOp>($_op).getBias()) =="
241+
" ::mlir::getElementTypeOrSelf("
242+
"::llvm::cast<QuantizeLinearOp>($_op).getOutput()"
243+
")">]>>]>,
244+
Arguments<(ins MIXRShapedOf<[AnyFloat]>:$input,
245+
MIXRShapedOf<[AnyFloat]>:$scale,
246+
Optional<MIXRShapedOf<[AnyInteger, AnyFloat]>>:$bias)>,
247+
Results<(outs MIXRShapedOf<[AnyInteger, AnyFloat]>:$output)> {
238248
let summary = "Channelwise quantization";
239249
let description = [{
240250
Quantization tensor channelwise. It computes the following:

mlir/lib/Conversion/MIGraphXToLinalg/MIGraphXToLinalg.cpp

Lines changed: 371 additions & 10 deletions
Large diffs are not rendered by default.

mlir/lib/Conversion/MIGraphXToTosa/MIGraphXToTosa.cpp

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1265,19 +1265,13 @@ LogicalResult QuantizeLinearConverter::matchAndRewrite(
12651265
&itsExtendNoWayWeCanLoseInfo);
12661266
std::ignore = maxF.convert(biasSem, APFloat::rmNearestTiesToEven,
12671267
&itsExtendNoWayWeCanLoseInfo);
1268-
minI = APInt(64, (int64_t)(minF.convertToFloat()));
1269-
maxI = APInt(64, (int64_t)(minF.convertToFloat()));
12701268
} else {
12711269
minI = origOutputType.isUnsignedInteger()
12721270
? APInt::getMinValue(width)
12731271
: APInt::getSignedMinValue(width);
12741272
maxI = origOutputType.isUnsignedInteger()
12751273
? APInt::getMaxValue(width)
12761274
: APInt::getSignedMaxValue(width);
1277-
minF.convertFromAPInt(minI, /*IsSigned=*/origOutputType.isSignedInteger(),
1278-
APFloat::rmNearestTiesToEven);
1279-
maxF.convertFromAPInt(maxI, /*IsSigned=*/origOutputType.isSignedInteger(),
1280-
APFloat::rmNearestTiesToEven);
12811275
}
12821276

12831277
Attribute minVal, maxVal;

mlir/test/Conversion/MIGraphXToLinalg/migraphx-to-linalg-not-implemented.mlir

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,5 @@
11
// RUN: rocmlir-opt --migraphx-to-linalg -verify-diagnostics %s
22

3-
func.func @func_quantizelinear(%arg0: !migraphx.shaped<1x1xf32, 1x1>, %arg1: !migraphx.shaped<1x1xf32, 1x1>) {
4-
// expected-error @+1{{failed to legalize operation 'migraphx.quantizelinear'}}
5-
migraphx.quantizelinear %arg0, %arg1: <1x1xf32, 1x1>, <1x1xf32, 1x1> -> <1x1xf32, 1x1>
6-
func.return
7-
}
8-
9-
func.func @func_dequantizelinear(%arg0: !migraphx.shaped<1x1xf32, 1x1>, %arg1: !migraphx.shaped<1x1xf32, 1x1>) {
10-
// expected-error @+1{{failed to legalize operation 'migraphx.dequantizelinear'}}
11-
migraphx.dequantizelinear %arg0, %arg1: <1x1xf32, 1x1>, <1x1xf32, 1x1> -> <1x1xf32, 1x1>
12-
func.return
13-
}
14-
153
func.func @func_quant_convolution(%arg0: !migraphx.shaped<1x1xi8, 1x1>, %arg1: !migraphx.shaped<1x1xi8, 1x1>) {
164
// expected-error @+1{{failed to legalize operation 'migraphx.quant_convolution'}}
175
migraphx.quant_convolution %arg0, %arg1 {dilation = [1, 1], group = 1 : i64, padding = [0, 0], stride = [1, 1]}: <1x1xi8, 1x1>, <1x1xi8, 1x1> -> <1x1xf32, 1x1>

mlir/test/Conversion/MIGraphXToLinalg/mixr-to-linalg-ops.mlir

Lines changed: 302 additions & 0 deletions
Large diffs are not rendered by default.

mlir/test/Conversion/MIGraphXToTosa/mixr-to-tosa-ops.mlir

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,8 +186,8 @@ module {
186186
// CHECK: tosa.add
187187
// CHECK: tosa.clamp
188188
// CHECK: tosa.cast
189-
func.func @quantize_scale_i32_bias_f16(%arg: !migraphx.shaped<1x112x112x64xf16, 802816x7168x64x1>, %scale: !migraphx.shaped<1x1x1x64xf16, 64x64x64x1>, %bias: !migraphx.shaped<1x1x1x64xi32, 64x64x64x1>) -> !migraphx.shaped<1x112x112x64xi8, 802816x7168x64x1> attributes {rock.kernel = "mixr"} {
190-
%1 = migraphx.quantizelinear %arg, %scale, %bias : <1x112x112x64xf16, 802816x7168x64x1>, <1x1x1x64xf16, 64x64x64x1>, !migraphx.shaped<1x1x1x64xi32, 64x64x64x1> -> <1x112x112x64xi8, 802816x7168x64x1>
189+
func.func @quantize_scale_i32_bias_f16(%arg: !migraphx.shaped<1x112x112x64xf16, 802816x7168x64x1>, %scale: !migraphx.shaped<1x1x1x64xf16, 64x64x64x1>, %bias: !migraphx.shaped<1x1x1x64xi8, 64x64x64x1>) -> !migraphx.shaped<1x112x112x64xi8, 802816x7168x64x1> attributes {rock.kernel = "mixr"} {
190+
%1 = migraphx.quantizelinear %arg, %scale, %bias : <1x112x112x64xf16, 802816x7168x64x1>, <1x1x1x64xf16, 64x64x64x1>, !migraphx.shaped<1x1x1x64xi8, 64x64x64x1> -> <1x112x112x64xi8, 802816x7168x64x1>
191191
return %1 : !migraphx.shaped<1x112x112x64xi8, 802816x7168x64x1>
192192
}
193193

mlir/test/Dialect/MIGraphX/invalid.mlir

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -458,3 +458,14 @@ func.func @invalid_shape_mismatch(%input: !migraphx.shaped<10x10xf32, 10x1>) {
458458
%result = migraphx.slice %input {axes = [0], starts = [0], ends = [5]} : <10x10xf32, 10x1> -> <3x10xf32, 10x1>
459459
func.return
460460
}
461+
462+
// -----
463+
464+
func.func @quantize_scale_bias_ui32(%arg: !migraphx.shaped<1x112x112x64xf32, 802816x7168x64x1>,
465+
%scale: !migraphx.shaped<1x1x1x64xf32, 64x64x64x1>,
466+
%bias: !migraphx.shaped<1x1x1x64xi32, 64x64x64x1>) -> !migraphx.shaped<1x112x112x64xf16, 802816x7168x64x1> attributes {rock.kernel = "mixr"} {
467+
// expected-error @+1 {{failed to verify that output and bias must have the same element type}}
468+
%1 = migraphx.quantizelinear %arg, %scale, %bias :
469+
<1x112x112x64xf32, 802816x7168x64x1>, <1x1x1x64xf32, 64x64x64x1>, !migraphx.shaped<1x1x1x64xi32, 64x64x64x1> -> <1x112x112x64xf16, 802816x7168x64x1>
470+
return %1 : !migraphx.shaped<1x112x112x64xf16, 802816x7168x64x1>
471+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
if not config.arch_support_accel_fp8 or (config.arch and "gfx942" in config.arch):
2+
config.unsupported = True
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// RUN: rocmlir-gen -fut mlir_quantizelinear_f8E4M3FN --arch %arch --clone-harness %s | rocmlir-driver -kernel-pipeline=migraphx-linalg,highlevel -host-pipeline=migraphx,highlevel -targets %arch | rocmlir-gen -ph -rand 1 -rand_type float -fut mlir_quantizelinear_f8E4M3FN_wrapper --verifier clone -relDiff_threshold 0.00001 - | rocmlir-driver -host-pipeline mhal,runner -kernel-pipeline full -targets %arch | rocmlir-opt --emulate-fp8-ext-trunc | xmir-runner --shared-libs=%linalg_test_lib_dir/libmlir_rocm_runtime%shlibext,%conv_validation_wrapper_library_dir/libconv-validation-wrappers%shlibext,%linalg_test_lib_dir/libmlir_runner_utils%shlibext,%linalg_test_lib_dir/libmlir_float16_utils%shlibext,%linalg_test_lib_dir/libmlir_c_runner_utils%shlibext,%linalg_test_lib_dir/libmlir_async_runtime%shlibext --entry-point-result=void | FileCheck %s
2+
3+
// CHECK: [1 1 1]
4+
func.func @mlir_quantizelinear_f8E4M3FN(%input: !migraphx.shaped<2x2xf32, 2x1>, %scale: !migraphx.shaped<2x2xf32, 2x1>, %bias: !migraphx.shaped<2x2xf8E4M3FN, 2x1>) -> !migraphx.shaped<2x2xf32, 2x1> {
5+
%result = migraphx.quantizelinear %input, %scale, %bias : <2x2xf32, 2x1>, <2x2xf32, 2x1>, !migraphx.shaped<2x2xf8E4M3FN, 2x1> -> <2x2xf8E4M3FN, 2x1>
6+
%dot_result = migraphx.quant_dot %result, %result : <2x2xf8E4M3FN, 2x1>, <2x2xf8E4M3FN, 2x1> -> <2x2xf32, 2x1>
7+
return %dot_result : !migraphx.shaped<2x2xf32, 2x1>
8+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// RUN: rocmlir-gen -fut mlir_quantizelinear_i8 --arch %arch --clone-harness %s | rocmlir-driver -kernel-pipeline=migraphx-linalg,highlevel -host-pipeline=migraphx,highlevel -targets %arch | rocmlir-gen -ph -rand 1 -rand_type float -fut mlir_quantizelinear_i8_wrapper --verifier clone -relDiff_threshold 0.00001 - | rocmlir-driver -host-pipeline mhal,runner -kernel-pipeline full -targets %arch | xmir-runner --shared-libs=%linalg_test_lib_dir/libmlir_rocm_runtime%shlibext,%conv_validation_wrapper_library_dir/libconv-validation-wrappers%shlibext,%linalg_test_lib_dir/libmlir_runner_utils%shlibext,%linalg_test_lib_dir/libmlir_float16_utils%shlibext,%linalg_test_lib_dir/libmlir_c_runner_utils%shlibext,%linalg_test_lib_dir/libmlir_async_runtime%shlibext --entry-point-result=void | FileCheck %s
2+
3+
// CHECK: [1 1 1]
4+
func.func @mlir_quantizelinear_i8(%input: !migraphx.shaped<2x2xf32, 2x1>, %scale: !migraphx.shaped<2x2xf32, 2x1>, %bias: !migraphx.shaped<2x2xi8, 2x1>) -> !migraphx.shaped<2x2xi32, 2x1> {
5+
%result = migraphx.quantizelinear %input, %scale, %bias : <2x2xf32, 2x1>, <2x2xf32, 2x1>, !migraphx.shaped<2x2xi8, 2x1> -> <2x2xi8, 2x1>
6+
%dot_result = migraphx.quant_dot %result, %result : <2x2xi8, 2x1>, <2x2xi8, 2x1> -> <2x2xi32, 2x1>
7+
return %dot_result : !migraphx.shaped<2x2xi32, 2x1>
8+
}

0 commit comments

Comments
 (0)