69 lines · plain
1// RUN: mlir-opt %s --one-shot-bufferize="dialect-filter=vector,bufferization copy-before-write unknown-type-conversion=identity-layout-map" -split-input-file | FileCheck %s2 3// CHECK-LABEL: func @transfer_read(4// CHECK-SAME: %[[t:.*]]: tensor<?x?xf32>, %[[o1:.*]]: index, %[[o2:.*]]: index, %[[pad:.*]]: f32)5// CHECK: %[[m:.*]] = bufferization.to_buffer %[[t]] : tensor<?x?xf32> to memref<?x?xf32>6// CHECK: %[[r:.*]] = vector.transfer_read %[[m]][%[[o1]], %[[o2]]], %[[pad]] {in_bounds = [true, false]} : memref<?x?xf32>, vector<5x6xf32>7// CHECK: return %[[r]]8func.func @transfer_read(%t: tensor<?x?xf32>, %o1: index,9 %o2: index, %pad: f32) -> vector<5x6xf32> {10 %0 = vector.transfer_read %t[%o1, %o2], %pad {in_bounds = [true, false]}11 : tensor<?x?xf32>, vector<5x6xf32>12 return %0 : vector<5x6xf32>13}14 15// -----16 17// CHECK-LABEL: func @transfer_write(18// CHECK-SAME: %[[t:.*]]: tensor<?x?xf32>, %[[o1:.*]]: index, %[[o2:.*]]: index, %[[vec:.*]]: vector<5x6xf32>, %[[mask:.*]]: vector<5x6xi1>)19// CHECK: %[[m:.*]] = bufferization.to_buffer %[[t]] : tensor<?x?xf32> to memref<?x?xf32>20// CHECK: %[[alloc:.*]] = memref.alloc(%{{.*}}, %{{.*}}) {{.*}} : memref<?x?xf32>21// CHECK: memref.copy %[[m]], %[[alloc]]22// CHECK: vector.transfer_write %[[vec]], %[[alloc]][%[[o1]], %[[o2]]], %[[mask]] {in_bounds = [true, false]} : vector<5x6xf32>, memref<?x?xf32>23// CHECK: %[[r:.*]] = bufferization.to_tensor %[[alloc]] : memref<?x?xf32>24// CHECK: return %[[r]]25func.func @transfer_write(%t: tensor<?x?xf32>, %o1: index,26 %o2: index, %vec: vector<5x6xf32>,27 %mask: vector<5x6xi1>) -> tensor<?x?xf32> {28 %0 = vector.transfer_write %vec, %t[%o1, %o2], %mask {in_bounds = [true, false]}29 : vector<5x6xf32>, tensor<?x?xf32>30 return %0 : tensor<?x?xf32>31}32 33// -----34 35// CHECK-LABEL: func @scatter(36// CHECK-SAME: %[[base:.*]]: tensor<16x16xf32>, %[[v:.*]]: vector<16xi32>,37// CHECK-SAME: %[[mask:.*]]: vector<16xi1>, %[[value:.*]]: vector<16xf32>) -> tensor<16x16xf32>38// CHECK: %[[buf:.*]] = bufferization.to_buffer %[[base]] : tensor<16x16xf32> to memref<16x16xf32>39// CHECK: %[[c0:.*]] = arith.constant 0 : index40// CHECK: %[[alloc:.*]] = memref.alloc() {alignment = 64 : i64} : memref<16x16xf32>41// CHECK: memref.copy %[[buf]], %[[alloc]] : memref<16x16xf32> to memref<16x16xf32>42// CHECK: vector.scatter %[[alloc]][%[[c0]], %[[c0]]] [%[[v]]], %[[mask]], %[[value]] : memref<16x16xf32>, vector<16xi32>, vector<16xi1>, vector<16xf32>43// CHECK: %[[tensor:.*]] = bufferization.to_tensor %[[alloc]] : memref<16x16xf32> to tensor<16x16xf32>44// CHECK: return %[[tensor]] : tensor<16x16xf32>45func.func @scatter(%base: tensor<16x16xf32>, %v: vector<16xi32>, 46 %mask: vector<16xi1>, %value: vector<16xf32>) -> tensor<16x16xf32> {47 %c0 = arith.constant 0 : index48 %0 = vector.scatter %base[%c0, %c0][%v], %mask, %value49 : tensor<16x16xf32>, vector<16xi32>, vector<16xi1>, vector<16xf32> -> tensor<16x16xf32>50 return %0 : tensor<16x16xf32>51}52 53// -----54 55// CHECK-LABEL: func @gather(56// CHECK-SAME: %[[base:.*]]: tensor<?x?xf32>, %[[v:.*]]: vector<16xi32>,57// CHECK-SAME: %[[mask:.*]]: vector<16xi1>, %[[pass_thru:.*]]: vector<16xf32>)58// CHECK: %[[m:.*]] = bufferization.to_buffer %[[base]] : tensor<?x?xf32> to memref<?x?xf32>59// CHECK: %[[c0:.*]] = arith.constant 0 : index60// CHECK: %[[out:.*]] = vector.gather %[[m]][%[[c0]], %[[c0]]] [%[[v]]], %[[mask]], %[[pass_thru]] : memref<?x?xf32>, vector<16xi32>, vector<16xi1>, vector<16xf32> into vector<16xf32>61func.func @gather(%base: tensor<?x?xf32>, %v: vector<16xi32>, %mask: vector<16xi1>, %pass_thru: vector<16xf32>) -> vector<16xf32> {62 %c0 = arith.constant 0 : index63 %0 = vector.gather %base[%c0, %c0][%v], %mask, %pass_thru : tensor<?x?xf32>, vector<16xi32>, vector<16xi1>, vector<16xf32> into vector<16xf32>64 return %0 : vector<16xf32>65}66 67// TODO: Add test case for vector.mask. The masked op can currently not68// bufferize out-of-place, so the only test case is in one-shot-bufferize.mlir.69