| // Numerical checks for data-tiling layouts materialized before dispatch | |
| // creation. The shapes are deliberately not multiples of the CPU tile sizes, | |
| // so the packed operands and the fused epilogues run on padded tiles. | |
| func.func @conv_nhwc_relu() { | |
| %input = util.unfoldable_constant dense<[[[[-1.0, 0.0, 0.0], [-1.0, 0.0, 0.0], [3.0, 1.0, 2.0], [-3.0, -1.0, 3.0], [-2.0, 0.0, 3.0]], [[1.0, 3.0, -2.0], [0.0, 1.0, -1.0], [1.0, 3.0, 2.0], [-1.0, -3.0, -2.0], [-2.0, 3.0, -2.0]], [[2.0, -2.0, 1.0], [0.0, 3.0, 0.0], [3.0, 3.0, 2.0], [1.0, 3.0, 3.0], [-2.0, 0.0, -3.0]], [[-3.0, 1.0, -3.0], [2.0, 2.0, -2.0], [1.0, -1.0, 3.0], [3.0, 1.0, 0.0], [1.0, 1.0, 2.0]], [[-2.0, 2.0, 0.0], [2.0, 0.0, -1.0], [-3.0, 0.0, 3.0], [-3.0, 0.0, 0.0], [-3.0, 0.0, 2.0]]]]> : tensor<1x5x5x3xf32> | |
| %filter = util.unfoldable_constant dense<[[[[2.0, 3.0, 0.0, 1.0, 3.0], [-1.0, 2.0, -2.0, -1.0, 1.0], [1.0, -2.0, 1.0, 1.0, 3.0]], [[1.0, 3.0, 3.0, -3.0, -3.0], [0.0, 0.0, 0.0, 2.0, -1.0], [-2.0, 1.0, -1.0, 3.0, -3.0]], [[1.0, 2.0, -2.0, -3.0, -1.0], [-1.0, 3.0, 3.0, -2.0, 0.0], [1.0, 3.0, -3.0, 2.0, 3.0]]], [[[3.0, -2.0, -3.0, 1.0, -3.0], [-3.0, -3.0, -2.0, 3.0, 1.0], [1.0, 3.0, 0.0, -3.0, -2.0]], [[-2.0, 1.0, -1.0, -1.0, -3.0], [1.0, -3.0, 0.0, 2.0, 0.0], [1.0, 2.0, -2.0, -3.0, -3.0]], [[1.0, -2.0, -2.0, 2.0, 2.0], [3.0, 0.0, 0.0, 3.0, 0.0], [-2.0, -2.0, 3.0, -3.0, 2.0]]], [[[1.0, 0.0, 2.0, 2.0, 0.0], [1.0, 2.0, 1.0, 0.0, 3.0], [3.0, -3.0, 0.0, 2.0, -3.0]], [[-1.0, 0.0, -1.0, 1.0, 3.0], [-1.0, 2.0, -3.0, 0.0, -3.0], [-1.0, -3.0, 3.0, 3.0, -3.0]], [[2.0, 1.0, -1.0, 2.0, 3.0], [2.0, 1.0, -1.0, 1.0, 2.0], [2.0, -2.0, -1.0, -1.0, 1.0]]]]> : tensor<3x3x3x5xf32> | |
| %zero = arith.constant 0.0 : f32 | |
| %empty = tensor.empty() : tensor<1x3x3x5xf32> | |
| %init = linalg.fill ins(%zero : f32) outs(%empty : tensor<1x3x3x5xf32>) -> tensor<1x3x3x5xf32> | |
| %conv = linalg.conv_2d_nhwc_hwcf {dilations = dense<1> : tensor<2xi64>, strides = dense<1> : tensor<2xi64>} ins(%input, %filter : tensor<1x5x5x3xf32>, tensor<3x3x3x5xf32>) outs(%init : tensor<1x3x3x5xf32>) -> tensor<1x3x3x5xf32> | |
| %relu = linalg.generic {indexing_maps = [affine_map<(n, h, w, c) -> (n, h, w, c)>, affine_map<(n, h, w, c) -> (n, h, w, c)>], iterator_types = ["parallel", "parallel", "parallel", "parallel"]} ins(%conv : tensor<1x3x3x5xf32>) outs(%empty : tensor<1x3x3x5xf32>) { | |
| ^bb0(%in: f32, %out: f32): | |
| %max = arith.maximumf %in, %zero : f32 | |
| linalg.yield %max : f32 | |
| } -> tensor<1x3x3x5xf32> | |
| check.expect_almost_eq_const(%relu, dense<[[[[15.0, 0.0, 0.0, 34.0, 15.0], [0.0, 8.0, 0.0, 26.0, 0.0], [0.0, 14.0, 0.0, 67.0, 4.0]], [[16.0, 30.0, 0.0, 0.0, 29.0], [0.0, 0.0, 4.0, 37.0, 0.0], [20.0, 0.0, 0.0, 6.0, 0.0]], [[0.0, 0.0, 11.0, 0.0, 40.0], [0.0, 16.0, 0.0, 10.0, 0.0], [6.0, 0.0, 7.0, 0.0, 0.0]]]]> : tensor<1x3x3x5xf32>) : tensor<1x3x3x5xf32> | |
| return | |
| } | |
| func.func @conv_nchw_stride2_relu() { | |
| %input = util.unfoldable_constant dense<[[[[-1.0, -1.0, 0.0, 1.0, -3.0, 3.0, -1.0], [-2.0, -3.0, 0.0, 2.0, -1.0, 2.0, -2.0], [-3.0, -1.0, 1.0, -1.0, 2.0, -3.0, 3.0], [-3.0, 2.0, -3.0, -1.0, -1.0, 3.0, 1.0], [3.0, -1.0, 0.0, 0.0, 2.0, 0.0, 3.0], [-2.0, 0.0, -2.0, 3.0, -3.0, 1.0, 3.0], [-1.0, -2.0, 2.0, 1.0, 0.0, 3.0, -3.0]], [[-2.0, -1.0, 3.0, -3.0, 0.0, 0.0, -3.0], [-1.0, 1.0, -1.0, -1.0, 1.0, 3.0, -3.0], [-1.0, 3.0, -1.0, 1.0, -1.0, 2.0, 1.0], [3.0, 1.0, 1.0, 0.0, -3.0, -3.0, 1.0], [1.0, 0.0, -3.0, 2.0, 2.0, 0.0, -2.0], [2.0, 0.0, 3.0, -2.0, -1.0, 2.0, -2.0], [-1.0, -1.0, 2.0, 2.0, 2.0, 0.0, 1.0]], [[1.0, 2.0, -3.0, -1.0, 2.0, -2.0, -2.0], [3.0, -2.0, 3.0, 3.0, -2.0, 0.0, -1.0], [0.0, 1.0, 3.0, 3.0, -3.0, -2.0, 1.0], [-2.0, -1.0, 1.0, -2.0, 3.0, 1.0, -2.0], [-1.0, 1.0, -1.0, 1.0, 3.0, -1.0, -2.0], [-1.0, 0.0, 0.0, -3.0, 1.0, -2.0, 1.0], [3.0, -2.0, 2.0, -3.0, 0.0, 1.0, -2.0]]], [[[2.0, 0.0, -1.0, -3.0, -3.0, 1.0, -1.0], [2.0, 3.0, 1.0, 2.0, 1.0, -1.0, -3.0], [1.0, -2.0, -3.0, 1.0, 1.0, -1.0, 1.0], [3.0, 2.0, 3.0, -3.0, -2.0, -1.0, 1.0], [1.0, 1.0, 3.0, -3.0, -2.0, -1.0, -2.0], [2.0, -1.0, 3.0, -2.0, -1.0, -1.0, -2.0], [2.0, 2.0, -1.0, 1.0, 3.0, 0.0, 3.0]], [[-2.0, -2.0, -3.0, 1.0, -3.0, -2.0, 1.0], [0.0, -2.0, 0.0, 3.0, 3.0, -3.0, 2.0], [0.0, 0.0, -1.0, 2.0, -2.0, 1.0, 2.0], [-1.0, 1.0, -3.0, 2.0, -1.0, -3.0, -1.0], [-1.0, 1.0, 0.0, 2.0, -1.0, 3.0, -3.0], [-1.0, -2.0, -1.0, 3.0, -3.0, -2.0, -1.0], [2.0, -3.0, 2.0, 2.0, -1.0, -3.0, 0.0]], [[1.0, 2.0, -2.0, 1.0, 0.0, 2.0, 1.0], [2.0, 2.0, 1.0, -1.0, 3.0, 0.0, 2.0], [-3.0, -2.0, 0.0, 2.0, 3.0, -3.0, 3.0], [-1.0, 3.0, -1.0, 3.0, -2.0, -1.0, 3.0], [3.0, -3.0, -2.0, -3.0, 3.0, -1.0, 0.0], [3.0, 2.0, -2.0, -1.0, 2.0, 0.0, -2.0], [3.0, 1.0, 2.0, 3.0, 1.0, 2.0, 3.0]]]]> : tensor<2x3x7x7xf32> | |
| %filter = util.unfoldable_constant dense<[[[[3.0, 0.0, 1.0], [1.0, 3.0, 0.0], [2.0, -2.0, 2.0]], [[-3.0, 3.0, -1.0], [1.0, -3.0, -1.0], [-3.0, 0.0, 3.0]], [[-2.0, -2.0, 2.0], [-2.0, -2.0, -2.0], [1.0, 0.0, 0.0]]], [[[-3.0, 1.0, -1.0], [2.0, 2.0, -3.0], [-1.0, 1.0, -2.0]], [[-1.0, -1.0, 1.0], [2.0, 1.0, -1.0], [1.0, 2.0, 2.0]], [[2.0, 0.0, 1.0], [0.0, 1.0, -1.0], [0.0, -2.0, 0.0]]], [[[1.0, 2.0, 1.0], [-2.0, -2.0, -1.0], [3.0, -3.0, 1.0]], [[-1.0, 0.0, -3.0], [2.0, 3.0, 0.0], [2.0, 0.0, 2.0]], [[-2.0, -1.0, -2.0], [0.0, 1.0, 2.0], [2.0, -2.0, 1.0]]], [[[-2.0, -1.0, -1.0], [1.0, 1.0, 0.0], [-3.0, 3.0, 2.0]], [[-1.0, 1.0, -2.0], [1.0, 3.0, 3.0], [3.0, -3.0, -3.0]], [[2.0, -2.0, -2.0], [1.0, -3.0, 2.0], [-2.0, 1.0, 1.0]]], [[[-2.0, -1.0, -3.0], [3.0, 0.0, -2.0], [2.0, 2.0, -2.0]], [[-1.0, -3.0, 0.0], [0.0, -3.0, -2.0], [0.0, -3.0, 2.0]], [[2.0, 1.0, 2.0], [2.0, -1.0, 0.0], [-1.0, -2.0, -2.0]]]]> : tensor<5x3x3x3xf32> | |
| %zero = arith.constant 0.0 : f32 | |
| %empty = tensor.empty() : tensor<2x5x3x3xf32> | |
| %init = linalg.fill ins(%zero : f32) outs(%empty : tensor<2x5x3x3xf32>) -> tensor<2x5x3x3xf32> | |
| %conv = linalg.conv_2d_nchw_fchw {dilations = dense<1> : tensor<2xi64>, strides = dense<2> : tensor<2xi64>} ins(%input, %filter : tensor<2x3x7x7xf32>, tensor<5x3x3x3xf32>) outs(%init : tensor<2x5x3x3xf32>) -> tensor<2x5x3x3xf32> | |
| %relu = linalg.generic {indexing_maps = [affine_map<(n, c, h, w) -> (n, c, h, w)>, affine_map<(n, c, h, w) -> (n, c, h, w)>], iterator_types = ["parallel", "parallel", "parallel", "parallel"]} ins(%conv : tensor<2x5x3x3xf32>) outs(%empty : tensor<2x5x3x3xf32>) { | |
| ^bb0(%in: f32, %out: f32): | |
| %max = arith.maximumf %in, %zero : f32 | |
| linalg.yield %max : f32 | |
| } -> tensor<2x5x3x3xf32> | |
| check.expect_almost_eq_const(%relu, dense<[[[[0.0, 1.0, 14.0], [10.0, 6.0, 39.0], [24.0, 46.0, 0.0]], [[0.0, 0.0, 27.0], [7.0, 0.0, 0.0], [0.0, 29.0, 0.0]], [[0.0, 0.0, 39.0], [11.0, 16.0, 0.0], [41.0, 15.0, 3.0]], [[14.0, 0.0, 4.0], [17.0, 0.0, 0.0], [0.0, 0.0, 18.0]], [[0.0, 5.0, 0.0], [0.0, 0.0, 0.0], [0.0, 15.0, 0.0]]], [[[0.0, 0.0, 9.0], [29.0, 0.0, 12.0], [8.0, 17.0, 19.0]], [[7.0, 0.0, 32.0], [0.0, 23.0, 0.0], [0.0, 0.0, 0.0]], [[1.0, 0.0, 20.0], [5.0, 19.0, 0.0], [6.0, 6.0, 0.0]], [[0.0, 59.0, 0.0], [0.0, 0.0, 0.0], [0.0, 19.0, 15.0]], [[28.0, 0.0, 37.0], [4.0, 7.0, 0.0], [11.0, 0.0, 19.0]]]]> : tensor<2x5x3x3xf32>) : tensor<2x5x3x3xf32> | |
| return | |
| } | |
| func.func @batchless_conv_hwc_relu() { | |
| %input = util.unfoldable_constant dense<[[[2.0, -1.0, 3.0], [1.0, 1.0, 0.0], [2.0, -1.0, 1.0], [1.0, 3.0, 1.0], [1.0, 0.0, -3.0]], [[-1.0, -1.0, 1.0], [-1.0, 1.0, 0.0], [-1.0, 0.0, -1.0], [-2.0, 0.0, 3.0], [1.0, 1.0, 1.0]], [[3.0, -1.0, -1.0], [0.0, 0.0, 3.0], [-2.0, -1.0, -2.0], [2.0, 0.0, -3.0], [-2.0, 3.0, 0.0]], [[3.0, -3.0, -2.0], [0.0, -3.0, -1.0], [0.0, -2.0, -2.0], [3.0, 3.0, 0.0], [3.0, 0.0, 3.0]], [[-3.0, 1.0, -3.0], [0.0, 3.0, 2.0], [-2.0, 1.0, -2.0], [-2.0, -1.0, 3.0], [1.0, 0.0, -2.0]]]> : tensor<5x5x3xf32> | |
| %filter = util.unfoldable_constant dense<[[[[2.0, 1.0, 0.0, 1.0, -2.0], [3.0, -1.0, 0.0, 1.0, -2.0], [-2.0, 0.0, -3.0, 1.0, 0.0]], [[-2.0, 2.0, -1.0, 1.0, -2.0], [-1.0, 1.0, 2.0, 1.0, 0.0], [-2.0, 3.0, 3.0, 2.0, -1.0]], [[2.0, 1.0, -2.0, 2.0, -2.0], [1.0, -2.0, -3.0, 0.0, 0.0], [0.0, -3.0, -2.0, -3.0, 2.0]]], [[[-3.0, 3.0, -2.0, -1.0, -1.0], [0.0, -1.0, 1.0, -1.0, 2.0], [3.0, -2.0, -3.0, -2.0, -2.0]], [[2.0, 2.0, 0.0, 3.0, 3.0], [3.0, 0.0, 0.0, -1.0, -2.0], [-1.0, 2.0, -2.0, -2.0, 1.0]], [[0.0, -2.0, -1.0, 3.0, -3.0], [-2.0, 0.0, 1.0, 1.0, 0.0], [2.0, 1.0, 1.0, 3.0, 2.0]]], [[[-2.0, 3.0, -2.0, 3.0, -3.0], [3.0, -3.0, 3.0, 0.0, 0.0], [-2.0, -3.0, 2.0, -2.0, -3.0]], [[0.0, -1.0, 0.0, 0.0, -3.0], [-2.0, -2.0, -1.0, -1.0, -2.0], [2.0, -2.0, 0.0, 3.0, 3.0]], [[-1.0, -1.0, -1.0, -1.0, 1.0], [1.0, 1.0, 2.0, 1.0, -2.0], [-3.0, -1.0, 1.0, 3.0, 2.0]]]]> : tensor<3x3x3x5xf32> | |
| %zero = arith.constant 0.0 : f32 | |
| %empty = tensor.empty() : tensor<3x3x5xf32> | |
| %init = linalg.fill ins(%zero : f32) outs(%empty : tensor<3x3x5xf32>) -> tensor<3x3x5xf32> | |
| %conv = linalg.generic {indexing_maps = [affine_map<(h, w, c, kh, kw, k) -> (h + kh, w + kw, k)>, affine_map<(h, w, c, kh, kw, k) -> (kh, kw, k, c)>, affine_map<(h, w, c, kh, kw, k) -> (h, w, c)>], iterator_types = ["parallel", "parallel", "parallel", "reduction", "reduction", "reduction"]} ins(%input, %filter : tensor<5x5x3xf32>, tensor<3x3x3x5xf32>) outs(%init : tensor<3x3x5xf32>) { | |
| ^bb0(%a: f32, %b: f32, %acc: f32): | |
| %prod = arith.mulf %a, %b : f32 | |
| %sum = arith.addf %prod, %acc : f32 | |
| linalg.yield %sum : f32 | |
| } -> tensor<3x3x5xf32> | |
| %relu = linalg.generic {indexing_maps = [affine_map<(h, w, c) -> (h, w, c)>, affine_map<(h, w, c) -> (h, w, c)>], iterator_types = ["parallel", "parallel", "parallel"]} ins(%conv : tensor<3x3x5xf32>) outs(%empty : tensor<3x3x5xf32>) { | |
| ^bb0(%in: f32, %out: f32): | |
| %max = arith.maximumf %in, %zero : f32 | |
| linalg.yield %max : f32 | |
| } -> tensor<3x3x5xf32> | |
| check.expect_almost_eq_const(%relu, dense<[[[6.0, 14.0, 0.0, 12.0, 0.0], [12.0, 0.0, 0.0, 0.0, 0.0], [0.0, 33.0, 14.0, 11.0, 0.0]], [[0.0, 53.0, 0.0, 0.0, 8.0], [0.0, 0.0, 0.0, 0.0, 0.0], [0.0, 0.0, 14.0, 24.0, 16.0]], [[0.0, 23.0, 20.0, 7.0, 0.0], [0.0, 0.0, 6.0, 31.0, 0.0], [37.0, 0.0, 0.0, 18.0, 35.0]]]> : tensor<3x3x5xf32>) : tensor<3x3x5xf32> | |
| return | |
| } |