1// RUN: mlir-opt %s \ 2// RUN: -one-shot-bufferize="bufferize-function-boundaries" \ 3// RUN: -buffer-deallocation-pipeline -convert-bufferization-to-memref \ 4// RUN: -convert-scf-to-cf -expand-strided-metadata -lower-affine -convert-cf-to-llvm -convert-arith-to-llvm \ 5// RUN: -finalize-memref-to-llvm -convert-func-to-llvm -reconcile-unrealized-casts | \ 6// RUN: mlir-runner -e main -entry-point-result=void \ 7// RUN: -shared-libs=%mlir_runner_utils,%mlir_c_runner_utils \ 8// RUN: | FileCheck %s 9 10 11func.func @main() { 12 %const = arith.constant dense<[[[-3.9058,0.9072],[-2.9470,-2.2055],[18.3946,8.2997],[3.4700,5.9006],[-17.2267,4.9777],[1.0450,-0.8201]],[[17.6996,-11.1763],[26.7775,-3.8823],[-4.2492,-5.8966],[2.1259,13.1794],[-10.7136,0.8428],[16.4233,9.4589]]]> : tensor<2x6x2xf32> 13 %dynamic = tensor.cast %const: tensor<2x6x2xf32> to tensor<2x?x?xf32> 14 %expanded = call @expand_dynamic_shape(%dynamic) : (tensor<2x?x?xf32>) -> (tensor<2x2x?x1x?xf32>) 15 %unranked = tensor.cast %expanded: tensor<2x2x?x1x?xf32> to tensor<*xf32> 16 call @printMemrefF32(%unranked) : (tensor<*xf32>) -> () 17 18 // CHECK: Unranked Memref base@ = {{0x[-9a-f]*}} 19 // CHECK-SAME: rank = 5 offset = 0 sizes = [2, 2, 3, 1, 2] strides = [12, 6, 2, 2, 1] data = 20 // CHECK-NEXT{LITERAL}: [[[[[-3.9058, 0.9072]], 21 // CHECK-NEXT{LITERAL}: [[-2.947, -2.2055]], 22 // CHECK-NEXT{LITERAL}: [[18.3946, 8.2997]]], 23 // CHECK-NEXT{LITERAL}: [[[3.47, 5.9006]], 24 // CHECK-NEXT{LITERAL}: [[-17.2267, 4.9777]], 25 // CHECK-NEXT{LITERAL}: [[1.045, -0.8201]]]], 26 // CHECK-NEXT{LITERAL}: [[[[17.6996, -11.1763]], 27 // CHECK-NEXT{LITERAL}: [[26.7775, -3.8823]], 28 // CHECK-NEXT{LITERAL}: [[-4.2492, -5.8966]]], 29 // CHECK-NEXT{LITERAL}: [[[2.1259, 13.1794]], 30 // CHECK-NEXT{LITERAL}: [[-10.7136, 0.8428]], 31 // CHECK-NEXT{LITERAL}: [[16.4233, 9.4589]]]]] 32 return 33} 34 35func.func private @printMemrefF32(%ptr : tensor<*xf32>) 36 37func.func @expand_dynamic_shape(%arg0 : tensor<2x?x?xf32>) -> tensor<2x2x?x1x?xf32> { 38 %c0 = arith.constant 0 : index 39 %c1 = arith.constant 1 : index 40 %c2 = arith.constant 2 : index 41 %d1 = tensor.dim %arg0, %c1 : tensor<2x?x?xf32> 42 %d2 = tensor.dim %arg0, %c2 : tensor<2x?x?xf32> 43 %sz1 = arith.divui %d1, %c2 : index 44 %0 = tensor.expand_shape %arg0 [[0], [1, 2, 3], [4]] output_shape [2, 2, %sz1, 1, %d2] : tensor<2x?x?xf32> into tensor<2x2x?x1x?xf32> 45 return %0 : tensor<2x2x?x1x?xf32> 46} 47