Hi Everyone,
I was trying to do a small exercise (compile a mlir function and call it from c after that).
So I used the following mlir code:
#id = affine_map<(d0) -> (d0)>
#ub = affine_map<(d0) -> (d0 + 64)>
// Map used to index the buffer while computing.
// CHECK-DAG: [[$MAP_IDENTITY:map[0-9]+]] = affine_map<(d0) -> (d0)>
// CHECK-DAG: [[$MAP_PLUS_128:map[0-9]+]] = affine_map<(d0) -> (d0 + 128)>
// CHECK-LABEL: func @matmul
// FILTER-LABEL: func @matmul
func @matmul(%A: memref<256x256xf32>, %B: memref<256x256xf32>, %C: memref<256x256xf32>) -> memref<256x256xf32> {
affine.for %i = 0 to 256 step 64 {
affine.for %j = 0 to 256 step 64 {
affine.for %k = 0 to 256 step 64 {
affine.for %ii = #id(%i) to #ub(%i) {
affine.for %jj = #id(%j) to #ub(%j) {
affine.for %kk = #id(%k) to #ub(%k) {
%5 = affine.load %A[%ii, %kk] : memref<256x256xf32>
%6 = affine.load %B[%kk, %jj] : memref<256x256xf32>
%7 = affine.load %C[%ii, %jj] : memref<256x256xf32>
%8 = arith.mulf %5, %6 : f32
%9 = arith.addf %7, %8 : f32
affine.store %9, %C[%ii, %jj] : memref<256x256xf32>
}
}
}
}
}
}
return %C : memref<256x256xf32>
}
and lower it to llvm ir than compile it to generate object file.
mlir-opt --lower-affine -convert-scf-to-std --convert-arith-to-llvm --convert-std-to-llvm --convert-memref-to-llvm matmul.mlir > matmul_llvm.mlir
mlir-opt -reconcile-unrealized-casts matmul_llvm.mlir > matmul_reconcil.mlir
mlir-translate -mlir-to-llvmir matmul_reconcil.mlir>matmul.ir
llvm-as matmul.ir -o matmul.bc
llc -filetype=obj matmul.bc -o matmul.o
But when I check the signature of matmul in matmul.o by using this command:
nm -C matmul.o
I got
0000000000000000 T matmul
am I doing something wrong ?