brintos

brintos / llvm-project-archived public Read only

0
0
Text · 10.0 KiB · 8014bb7 Raw
140 lines · plain
1// RUN: mlir-opt %s -convert-vector-to-scf -lower-affine \2// RUN: -one-shot-bufferize="bufferize-function-boundaries" \3// RUN: -convert-scf-to-cf -convert-vector-to-llvm="enable-amx" \4// RUN:  -finalize-memref-to-llvm -convert-func-to-llvm -reconcile-unrealized-casts | \5// RUN: mlir-translate -mlir-to-llvmir | \6// RUN: %lli --entry-function=entry --mattr="+amx-tile,+amx-int8,+amx-bf16" \7// RUN:  --dlopen=%mlir_c_runner_utils | \8// RUN: FileCheck %s9 10// Note: To run this test, your CPU must support AMX.11 12// Multiply full size tiles into zero destination.13func.func @kernel(%arg0: memref<16x32xbf16>,14             %arg1: memref<16x32xbf16>,15             %arg2: memref<16x16xf32>) {16  %0 = arith.constant 0 : index17  %1 = amx.tile_load %arg0[%0, %0] : memref<16x32xbf16>  into vector<16x32xbf16>18  %2 = amx.tile_load %arg1[%0, %0] : memref<16x32xbf16>  into vector<16x32xbf16>19  %3 = amx.tile_zero : vector<16x16xf32>20  %4 = amx.tile_mulf %1, %2, %3 : vector<16x32xbf16>, vector<16x32xbf16>, vector<16x16xf32>21  amx.tile_store %arg2[%0, %0], %4 : memref<16x16xf32>, vector<16x16xf32>22  return23}24 25func.func @entry() -> i32 {26  %fu = arith.constant -1.0: f3227  %c0 = arith.constant 0: index28  %c1 = arith.constant 1: index29  %c16 = arith.constant 16: index30  %c32 = arith.constant 32: index31 32  // Setup simple test data.33  %0 = arith.constant dense<[34     [ 1.1, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0,35       1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0 ],36     [ 1.0, 1.2, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.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, 1.0, 1.0, 1.0, 1.0 ]100  ]> : tensor<16x32xbf16>101 102  // Set up memory.103  %a = bufferization.to_buffer %0 : tensor<16x32xbf16> to memref<16x32xbf16>104  %b = bufferization.to_buffer %1 : tensor<16x32xbf16> to memref<16x32xbf16>105  %c = memref.alloc() : memref<16x16xf32>106 107  // Call kernel.108  call @kernel(%a, %b, %c) : (memref<16x32xbf16>, memref<16x32xbf16>, memref<16x16xf32>) -> ()109 110  //111  // Print and verify the 16x16 result.112  //113  // CHECK:      ( 32.1016, 34.3984, 34.5078, 33.6953, 32.9062, 32.2031, 32.1016, 32.1016, 32.1016, 32.1016, 32.1016, 32.1016, 32.1016, 32.1016, 32.1016, 32.1016 )114  // CHECK-NEXT: ( 32.2031, 34.5, 34.6094, 33.7969, 33.0284, 32.3047, 32.2031, 32.2031, 32.2031, 32.2031, 32.2031, 32.2031, 32.2031, 32.2031, 32.2031, 32.2031 )115  // CHECK-NEXT: ( 32.2969, 34.5938, 34.7031, 33.8906, 33.1619, 32.3984, 32.2969, 32.2969, 32.2969, 32.2969, 32.2969, 32.2969, 32.2969, 32.2969, 32.2969, 32.2969 )116  // CHECK-NEXT: ( 32.3984, 34.6953, 34.8047, 33.9922, 33.2031, 32.5, 32.3984, 32.3984, 32.3984, 32.3984, 32.3984, 32.3984, 32.3984, 32.3984, 32.3984, 32.3984 )117  // CHECK-NEXT: ( 32.5, 34.7969, 34.9062, 34.0938, 33.3047, 32.6016, 32.5, 32.5, 32.5, 32.5, 32.5, 32.5, 32.5, 32.5, 32.5, 32.5 )118  // CHECK-NEXT: ( 32.6016, 34.8984, 35.0078, 34.3739, 33.4062, 32.7031, 32.6016, 32.6016, 32.6016, 32.6016, 32.6016, 32.6016, 32.6016, 32.6016, 32.6016, 32.6016 )119  // CHECK-NEXT: ( 32.7031, 35, 35.1094, 34.577, 33.5078, 32.8047, 32.7031, 32.7031, 32.7031, 32.7031, 32.7031, 32.7031, 32.7031, 32.7031, 32.7031, 32.7031 )120  // CHECK-NEXT: ( 32.7969, 35.0938, 35.2031, 34.3906, 33.6016, 32.8984, 32.7969, 32.7969, 32.7969, 32.7969, 32.7969, 32.7969, 32.7969, 32.7969, 32.7969, 32.7969 )121  // CHECK-NEXT: ( 32.7969, 35.0938, 35.2031, 34.3906, 33.6016, 32.8984, 32.7969, 32.7969, 32.7969, 32.7969, 32.7969, 32.7969, 32.7969, 32.7969, 32.7969, 32.7969 )122  // CHECK-NEXT: ( 32.7031, 35, 35.4609, 34.2969, 33.5078, 32.8047, 32.7031, 32.7031, 32.7031, 32.7031, 32.7031, 32.7031, 32.7031, 32.7031, 32.7031, 32.7031 )123  // CHECK-NEXT: ( 32.6016, 34.8984, 35.3697, 34.1953, 33.4062, 32.7031, 32.6016, 32.6016, 32.6016, 32.6016, 32.6016, 32.6016, 32.6016, 32.6016, 32.6016, 32.6016 )124  // CHECK-NEXT: ( 32.5, 34.7969, 34.9062, 34.0938, 33.3047, 32.6016, 32.5, 32.5, 32.5, 32.5, 32.5, 32.5, 32.5, 32.5, 32.5, 32.5 )125  // CHECK-NEXT: ( 32.3984, 34.6953, 34.8047, 33.9922, 33.2031, 32.5, 32.3984, 32.3984, 32.3984, 32.3984, 32.3984, 32.3984, 32.3984, 32.3984, 32.3984, 32.3984 )126  // CHECK-NEXT: ( 32.2969, 34.8025, 34.7031, 33.8906, 33.1016, 32.3984, 32.2969, 32.2969, 32.2969, 32.2969, 32.2969, 32.2969, 32.2969, 32.2969, 32.2969, 32.2969 )127  // CHECK-NEXT: ( 32.2031, 34.6619, 34.6094, 33.7969, 33.0078, 32.3047, 32.2031, 32.2031, 32.2031, 32.2031, 32.2031, 32.2031, 32.2031, 32.2031, 32.2031, 32.2031 )128  // CHECK-NEXT: ( 32.1016, 34.3984, 34.5078, 33.6953, 32.9062, 32.2031, 32.1016, 32.1016, 32.1016, 32.1016, 32.1016, 32.1016, 32.1016, 32.1016, 32.1016, 32.1016 )129  //130  scf.for %i = %c0 to %c16 step %c1 {131    %v = vector.transfer_read %c[%i, %c0], %fu: memref<16x16xf32>, vector<16xf32>132    vector.print %v : vector<16xf32>133  }134 135  // Release resources.136  memref.dealloc %c : memref<16x16xf32>137  %i0 = arith.constant 0 : i32138  return %i0 : i32139}140