• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// RUN: mlir-opt %s -split-input-file | FileCheck %s
2
3// -----
4// CHECK-LABEL: validConstFakeQuant
5func @validConstFakeQuant(%arg0: tensor<8x4x3xf32>) -> tensor<8x4x3xf32> {
6  %0 = "quant.const_fake_quant"(%arg0) {
7    min = 0.0 : f32, max = 1.0 : f32, num_bits = 8, narrow_range = true
8  } : (tensor<8x4x3xf32>) -> tensor<8x4x3xf32>
9  %1 = "quant.const_fake_quant"(%0) {
10    min = 0.0 : f32, max = 1.0 : f32, num_bits = 8, narrow_range = false
11  } : (tensor<8x4x3xf32>) -> tensor<8x4x3xf32>
12  %2 = "quant.const_fake_quant"(%1) {
13    min = 0.0 : f32, max = 1.0 : f32, num_bits = 8
14  } : (tensor<8x4x3xf32>) -> tensor<8x4x3xf32>
15  return %2 : tensor<8x4x3xf32>
16}
17
18// -----
19// CHECK-LABEL: validConstFakeQuantPerAxis
20func @validConstFakeQuantPerAxis(%arg0: tensor<8x4x2xf32>) -> tensor<8x4x2xf32> {
21  %0 = "quant.const_fake_quant_per_axis"(%arg0) {
22    min = [0.0 : f32, 1.0 : f32], max = [2.0 : f32, 3.0 : f32], axis = 2, num_bits = 8, narrow_range = true
23  } : (tensor<8x4x2xf32>) -> tensor<8x4x2xf32>
24  %1 = "quant.const_fake_quant_per_axis"(%0) {
25    min = [0.0 : f32, 1.0 : f32], max = [2.0 : f32, 3.0 : f32], axis = 2, num_bits = 8, narrow_range = false
26  } : (tensor<8x4x2xf32>) -> tensor<8x4x2xf32>
27  %2 = "quant.const_fake_quant_per_axis"(%1) {
28    min = [0.0 : f32, 1.0 : f32], max = [2.0 : f32, 3.0 : f32], axis = 2, num_bits = 8
29  } : (tensor<8x4x2xf32>) -> tensor<8x4x2xf32>
30  return %2 : tensor<8x4x2xf32>
31}
32
33// -----
34// CHECK-LABEL: validStatisticsRef
35func @validStatisticsRef(%arg0: tensor<8x4x3xf32>) -> tensor<8x4x3xf32> {
36  %0 = "quant.stats_ref"(%arg0) { statsKey = "foobar" } :
37      (tensor<8x4x3xf32>) -> tensor<8x4x3xf32>
38  return %0 : tensor<8x4x3xf32>
39}
40
41// -----
42// CHECK-LABEL: validStatistics
43func @validStatistics(%arg0: tensor<8x4x3xf32>) -> tensor<8x4x3xf32> {
44  %0 = "quant.stats"(%arg0) {
45    layerStats = dense<[-1.0, 1.0]> : tensor<2xf32>
46  } : (tensor<8x4x3xf32>) -> tensor<8x4x3xf32>
47  %1 = "quant.stats"(%0) {
48    layerStats = dense<[-1.0, 1.0]> : tensor<2xf32>,
49    axisStats = dense<[
50      [-1.0, 1.0],
51      [-8.0, 8.0],
52      [-0.5, 0.5]
53    ]> : tensor<3x2xf32>, axis = 2 : i64
54  } : (tensor<8x4x3xf32>) -> tensor<8x4x3xf32>
55  return %1 : tensor<8x4x3xf32>
56}
57
58// -----
59// CHECK-LABEL: validCoupledRef
60func @validCoupledRef(%arg0: tensor<8x4x3xf32>) -> tensor<8x4x3xf32> {
61  %0 = "quant.coupled_ref"(%arg0) { coupledKey = "foobar" } :
62      (tensor<8x4x3xf32>) -> tensor<8x4x3xf32>
63  return %0 : tensor<8x4x3xf32>
64}
65