summaryrefslogtreecommitdiffstats
path: root/mlir/test/Dialect/FxpMathOps/lower-uniform-casts.mlir
blob: 2401bebc3af03721cce7c16ad2a8e8a4123eaa3f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
// RUN: mlir-opt %s -split-input-file -fxpmath-lower-uniform-casts | FileCheck %s --dump-input=always

// -----
// CHECK-LABEL: dequantize_per_layer_fixedpoint
!type_input = type tensor<4x!quant.uniform<i8:f32, 6.25e-2>>
!type_result = type tensor<4xf32>
func @dequantize_per_layer_fixedpoint(%arg0 : !type_input) -> !type_result {
  // CHECK: %cst = constant dense<6.250000e-02> : tensor<4xf32>
  // CHECK-NEXT: %0 = "quant.scast"(%arg0) : (tensor<4x!quant.uniform<i8:f32, 6.250000e-02>>) -> tensor<4xi8>
  // CHECK-NEXT: %1 = "fxpmath.convertis"(%0) : (tensor<4xi8>) -> tensor<4xi32>
  // CHECK-NEXT: %2 = "fxpmath.convertistof"(%1) : (tensor<4xi32>) -> tensor<4xf32>
  // CHECK-NEXT: %3 = mulf %2, %cst : tensor<4xf32>
  // CHECK-NEXT: return %3 : tensor<4xf32>
  %0 = "quant.dcast"(%arg0) : (!type_input) -> (!type_result)
  return %0 : !type_result
}

// -----
// CHECK-LABEL: dequantize_per_layer_affine
!type_input = type tensor<4x!quant.uniform<i8:f32, 6.25e-2:-36>>
!type_result = type tensor<4xf32>
func @dequantize_per_layer_affine(%arg0 : !type_input) -> !type_result {
  // CHECK: %cst = constant dense<36> : tensor<4xi32>
  // CHECK-NEXT: %cst_0 = constant dense<6.250000e-02> : tensor<4xf32>
  // CHECK-NEXT: %0 = "quant.scast"(%arg0) : (tensor<4x!quant.uniform<i8:f32, 6.250000e-02:-36>>) -> tensor<4xi8>
  // CHECK-NEXT: %1 = "fxpmath.convertis"(%0) : (tensor<4xi8>) -> tensor<4xi32>
  // CHECK-NEXT: %2 = addi %1, %cst : tensor<4xi32>
  // CHECK-NEXT: %3 = "fxpmath.convertistof"(%2) : (tensor<4xi32>) -> tensor<4xf32>
  // CHECK-NEXT: %4 = mulf %3, %cst_0 : tensor<4xf32>
  // CHECK-NEXT: return %4 : tensor<4xf32>
  %0 = "quant.dcast"(%arg0) : (!type_input) -> (!type_result)
  return %0 : !type_result
}

// -----
// CHECK-LABEL: dequantize_per_axis_fixedpoint
!type_input = type tensor<4x!quant.uniform<i8:f32:0, {6.25e-2,3.26e-2,4.25e-2,1.23e-2}>>
!type_result = type tensor<4xf32>
func @dequantize_per_axis_fixedpoint(%arg0 : !type_input) -> !type_result {
  // expected-warning@+1 {{unimplemented: per-axis uniform dequantization}}
  %0 = "quant.dcast"(%arg0) : (!type_input) -> (!type_result)
  return %0 : !type_result
}

// -----
// CHECK-LABEL: dequantize_per_axis_affine
!type_input = type tensor<4x!quant.uniform<i8:f32:0, {6.25e-2,3.26e-2,4.25e-2,1.23e-2}>>
!type_result = type tensor<4xf32>
func @dequantize_per_axis_affine(%arg0 : !type_input) -> !type_result {
  // expected-warning@+1 {{unimplemented: per-axis uniform dequantization}}
  %0 = "quant.dcast"(%arg0) : (!type_input) -> (!type_result)
  return %0 : !type_result
}

// -----
// Noop dequantize should be skipped (will be canonicalized away later).
// CHECK-LABEL: dequantize_noop
!type_input = type tensor<4x!quant.uniform<i8:f32, 6.25e-2:-36>>
!type_result = type tensor<4x!quant.uniform<i8:f32, 6.25e-2:-36>>
func @dequantize_noop(%arg0 : !type_input) -> !type_result {
  // CHECK: %0 = "quant.dcast"(%arg0)
  %0 = "quant.dcast"(%arg0) : (!type_input) -> (!type_result)
  return %0 : !type_result
}
OpenPOWER on IntegriCloud