mlir-hlo/tests/test.mlir

61 lines
2.6 KiB
MLIR

func private @print_memref_f32(memref<*xf32>) attributes { llvm.emit_c_interface }
// func @main() -> (i32) {
// %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]
// %c42_i32 = constant 42 : i32
// return %c42_i32 : i32
// }
// ./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
func @main(%1 : memref<*xf32>,%2 : memref<*xf32> ) -> memref<*xf32> {
%ranked1 = memref.cast %1 : memref<*xf32> to memref<6xf32>
%ranked2 = memref.cast %2 : memref<*xf32> to memref<6xf32>
%in1 = memref.tensor_load %ranked1 : memref<6xf32>
%in2 = memref.tensor_load %ranked2 : memref<6xf32>
%add = "mhlo.multiply"(%in1, %in2) {name = "mul.3"} : (tensor<6xf32>, tensor<6xf32>) -> tensor<6xf32>
%mul = "mhlo.add"(%in1, %add) {name = "add.3"} : (tensor<6xf32>, tensor<6xf32>) -> tensor<6xf32>
%output = memref.buffer_cast %mul : memref<6xf32>
%unranked_output = memref.cast %output : memref<6xf32> to memref<*xf32>
call @print_memref_f32(%1) : (memref<*xf32>) -> ()
return %unranked_output : memref<*xf32>
}