brintos

brintos / llvm-project-archived public Read only

0
0
Text · 5.7 KiB · b0db1bb Raw
123 lines · plain
1// RUN: mlir-opt %s | mlir-opt | FileCheck %s2// RUN: mlir-opt %s --mlir-print-op-generic | mlir-opt | FileCheck %s3 4#CSR = #sparse_tensor.encoding<{5  map = (d0, d1) -> (d0 : dense, d1 : compressed)6}>7 8// CHECK-LABEL: func @test_clone9func.func @test_clone(%buf : memref<*xf32>) -> memref<*xf32> {10  %clone = bufferization.clone %buf : memref<*xf32> to memref<*xf32>11  return %clone : memref<*xf32>12}13 14// CHECK-LABEL: test_to_buffer15func.func @test_to_buffer(%arg0: tensor<?xi64>, %arg1: tensor<*xi64>)16    -> (memref<?xi64, affine_map<(d0) -> (d0 + 7)>>, memref<*xi64, 1>) {17  %0 = bufferization.to_buffer %arg018    : tensor<?xi64> to memref<?xi64, affine_map<(d0) -> (d0 + 7)>>19  %1 = bufferization.to_buffer %arg120    : tensor<*xi64> to memref<*xi64, 1>21  return %0, %1 : memref<?xi64, affine_map<(d0) -> (d0 + 7)>>, memref<*xi64, 1>22}23 24// CHECK-LABEL: func @test_to_tensor25func.func @test_to_tensor(%buf : memref<2xf32>) -> tensor<2xf32> {26  %tensor = bufferization.to_tensor %buf restrict writable : memref<2xf32> to tensor<2xf32>27  return %tensor : tensor<2xf32>28}29 30// CHECK-LABEL: func @test_alloc_tensor_op31func.func @test_alloc_tensor_op(%t: tensor<?x5xf32>, %sz: index)32  -> tensor<?x5xf32>33{34  // CHECK: bufferization.alloc_tensor(%{{.*}}) : tensor<?x5xf32>35  %0 = bufferization.alloc_tensor(%sz) : tensor<?x5xf32>36  // CHECK: bufferization.alloc_tensor() copy(%{{.*}}) : tensor<?x5xf32>37  %1 = bufferization.alloc_tensor() copy(%t) : tensor<?x5xf32>38  // CHECK: bufferization.alloc_tensor() : tensor<5x6xf32>39  %2 = bufferization.alloc_tensor() : tensor<5x6xf32>40  // CHECK: bufferization.alloc_tensor(%{{.*}}, %{{.*}}) : tensor<?x?xf32>41  %3 = bufferization.alloc_tensor(%sz, %sz) : tensor<?x?xf32>42  // CHECK: bufferization.alloc_tensor() copy(%{{.*}}) {escape = true} : tensor<?x5xf32>43  %4 = bufferization.alloc_tensor() copy(%t) {escape = true} : tensor<?x5xf32>44  // CHECK: bufferization.alloc_tensor() copy(%{{.*}}) {escape = false} : tensor<?x5xf32>45  %5 = bufferization.alloc_tensor() copy(%t) {escape = false} : tensor<?x5xf32>46  %c100 = arith.constant 100 : index47  // CHECK: bufferization.alloc_tensor() size_hint=48  %6 = bufferization.alloc_tensor() size_hint=%c100 : tensor<100x100xf64, #CSR>49  // CHECK: bufferization.alloc_tensor(%{{.+}}) {memory_space = "foo"} : tensor<?xf32>50  %7 = bufferization.alloc_tensor(%sz) {memory_space = "foo"} : tensor<?xf32>51  return %1 : tensor<?x5xf32>52}53 54// CHECK-LABEL: func @test_dealloc_tensor_op55func.func @test_dealloc_tensor_op(%arg0: tensor<4xi32>) {56  // CHECK: bufferization.dealloc_tensor {{.*}} : tensor<4xi32>57  bufferization.dealloc_tensor %arg0 : tensor<4xi32>58  return59}60 61// CHECK-LABEL: func @test_materialize_in_destination_op62func.func @test_materialize_in_destination_op(63    %arg0: tensor<?xf32>, %arg1: tensor<?xf32>, %arg2: memref<?xf32, 3>,64    %arg4: tensor<5xf32>) -> tensor<?xf32> {65  // CHECK: bufferization.materialize_in_destination {{.*}} : (tensor<?xf32>, tensor<?xf32>) -> tensor<?xf32>66  %1 = bufferization.materialize_in_destination %arg0 in %arg1 : (tensor<?xf32>, tensor<?xf32>) -> tensor<?xf32>67  // CHECK: bufferization.materialize_in_destination {{.*}} : (tensor<?xf32>, memref<?xf32, 3>) -> ()68  bufferization.materialize_in_destination %arg0 in restrict writable %arg2 : (tensor<?xf32>, memref<?xf32, 3>) -> ()69  // CHECK: bufferization.materialize_in_destination {{.*}} : (tensor<?xf32>, tensor<5xf32>) -> tensor<5xf32>70  %2 = bufferization.materialize_in_destination %arg0 in %arg4 : (tensor<?xf32>, tensor<5xf32>) -> tensor<5xf32>71  return %1 : tensor<?xf32>72}73 74// CHECK-LABEL: func @test_dealloc_op75func.func @test_dealloc_op(%arg0: memref<2xf32>, %arg1: memref<4xi32>,76                           %arg2: i1, %arg3: i1, %arg4: memref<?xf32>,77                           %arg5: memref<*xf64>) -> (i1, i1) {78  // CHECK: bufferization.dealloc (%arg0, %arg1 : memref<2xf32>, memref<4xi32>) if (%arg2, %arg3) retain (%arg4, %arg5 : memref<?xf32>, memref<*xf64>)79  %0:2 = bufferization.dealloc (%arg0, %arg1 : memref<2xf32>, memref<4xi32>) if (%arg2, %arg3) retain (%arg4, %arg5 : memref<?xf32>, memref<*xf64>)80  // CHECK: bufferization.dealloc (%arg0 : memref<2xf32>) if (%arg2)81  bufferization.dealloc (%arg0 : memref<2xf32>) if (%arg2)82  // CHECK: bufferization.dealloc83  bufferization.dealloc84  return %0#0, %0#1 : i1, i185}86 87// CHECK: func.func @test_builtin_custom_builtin_type_conversion88// CHECK-SAME: (%[[t:.*]]: tensor<42xf32>) -> tensor<42xf32>89func.func @test_builtin_custom_builtin_type_conversion(%t: tensor<42xf32>)90    -> tensor<42xf32> {91  // CHECK: %[[buffer:.*]] = bufferization.to_buffer %[[t]]92  // CHECK-SAME: to !test.test_memref<[42], f32>93  %buffer = bufferization.to_buffer %t94    : tensor<42xf32> to !test.test_memref<[42], f32>95 96  // CHECK: %[[tensor:.*]] = bufferization.to_tensor %[[buffer]]97  // CHECK-SAME: to tensor<42xf32>98  %tensor = bufferization.to_tensor %buffer99    : !test.test_memref<[42], f32> to tensor<42xf32>100 101  // CHECK: return %[[tensor]]102  return %tensor : tensor<42xf32>103}104 105// CHECK: func.func @test_custom_builtin_custom_type_conversion106// CHECK-SAME: (%[[t:.*]]: !test.test_tensor<[42], f32>)107// CHECK-SAME: -> !test.test_tensor<[42], f32>108func.func @test_custom_builtin_custom_type_conversion(%t: !test.test_tensor<[42], f32>)109    -> !test.test_tensor<[42], f32> {110  // CHECK: %[[buffer:.*]] = bufferization.to_buffer %[[t]]111  // CHECK-SAME: to memref<42xf32>112  %buffer = bufferization.to_buffer %t113    : !test.test_tensor<[42], f32> to memref<42xf32>114 115  // CHECK: %[[tensor:.*]] = bufferization.to_tensor %[[buffer]]116  // CHECK-SAME: to !test.test_tensor<[42], f32>117  %tensor = bufferization.to_tensor %buffer118    : memref<42xf32> to !test.test_tensor<[42], f32>119 120  // CHECK: return %[[tensor]]121  return %tensor : !test.test_tensor<[42], f32>122}123