40 lines
1.8 KiB
MLIR
40 lines
1.8 KiB
MLIR
|
func private @print_memref_f32(memref<*xf32>) attributes { llvm.emit_c_interface }
|
||
|
|
||
|
func @main() {
|
||
|
%c0 = constant 0 : index
|
||
|
%c1 = constant 1 : index
|
||
|
|
||
|
// Initialize input.
|
||
|
%input = memref.alloc() : memref<2x3xf32>
|
||
|
%dim_x = memref.dim %input, %c0 : memref<2x3xf32>
|
||
|
%dim_y = memref.dim %input, %c1 : memref<2x3xf32>
|
||
|
scf.parallel (%i, %j) = (%c0, %c0) to (%dim_x, %dim_y) step (%c1, %c1) {
|
||
|
%i_i64 = index_cast %i : index to i64
|
||
|
%i_f32 = sitofp %i_i64 : i64 to f32
|
||
|
memref.store %i_f32, %input[%i, %j] : memref<2x3xf32>
|
||
|
}
|
||
|
%unranked_input = memref.cast %input : memref<2x3xf32> to memref<*xf32>
|
||
|
call @print_memref_f32(%unranked_input) : (memref<*xf32>) -> ()
|
||
|
// CHECK: rank = 2 offset = 0 sizes = [2, 3] strides = [3, 1]
|
||
|
// CHECK: [0, 0, 0]
|
||
|
// CHECK: [1, 1, 1]
|
||
|
|
||
|
%in = memref.tensor_load %input : memref<2x3xf32>
|
||
|
|
||
|
%add = "mhlo.add"(%in, %in) {name = "add.3"} : (tensor<2x3xf32>, tensor<2x3xf32>) -> tensor<2x3xf32>
|
||
|
|
||
|
%output = memref.buffer_cast %add : memref<2x3xf32>
|
||
|
%unranked_output = memref.cast %output : memref<2x3xf32> to memref<*xf32>
|
||
|
|
||
|
call @print_memref_f32(%unranked_output) : (memref<*xf32>) -> ()
|
||
|
// CHECK: rank = 2 offset = 0 sizes = [2, 3] strides = [3, 1]
|
||
|
// CHECK: [0, 0, 0]
|
||
|
// CHECK: [2, 2, 2]
|
||
|
|
||
|
return
|
||
|
}
|
||
|
|
||
|
// ./mlir-hlo-opt -chlo-legalize-to-hlo -hlo-legalize-to-lhlo -buffer-hoisting -buffer-deallocation -canonicalize -cse -lhlo-legalize-to-linalg -convert-linalg-to-loops -lower-affine -convert-scf-to-std -convert-std-to-llvm ../../../tests/test.mlir > a.mlir
|
||
|
// /root/mlir-hlo/llvm-build/bin/mlir-cpu-runner --entry-point-result=void -shared-libs=/root/mlir-hlo/llvm-build/lib/libmlir_runner_utils.so.13git a.mlir > b.mlir
|
||
|
// /root/mlir-hlo/llvm-build/bin/FileCheck --input-file b.mlir ../../../tests/test.mlir
|