Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OpenMP need a different linking way #88

Closed
EllisLambda opened this issue Sep 1, 2023 · 2 comments
Closed

OpenMP need a different linking way #88

EllisLambda opened this issue Sep 1, 2023 · 2 comments

Comments

@EllisLambda
Copy link

EllisLambda commented Sep 1, 2023

Is your feature request related to a problem? Please describe.
I tried to use these CMake code for the BatchMatMulBroadcast.mlir in my PR to compile static library. -fopenmp could only be used in clang and I have ruled out the possibility that the problem arises from using clang instead of llc.

function(build_batch_matmul_broadcast_omp step)
  add_custom_command(OUTPUT batch-matmul-broadcast-${step}-omp.o
    COMMAND cat ${BUDDY_SOURCE_DIR}/benchmarks/OpOptimization/MatMul/BatchMatMulBroadcast.mlir |
          sed 's/batch_matmul_broadcast_STEP_PLACEHOLDER/batch_matmul_broadcast_STEP_PLACEHOLDER_omp/g' |
          sed 's/STEP_PLACEHOLDER/${step}/g' |
          ${BUDDY_MLIR_BUILD_DIR}/bin/buddy-opt
            -batchmatmul-optimize="step-placeholder=${step}"
            -expand-strided-metadata
            -affine-super-vectorize
            -lower-affine
            -convert-scf-to-openmp
            -convert-vector-to-llvm
            -finalize-memref-to-llvm
            -convert-scf-to-cf
            -convert-linalg-to-llvm
            -convert-openmp-to-llvm
            -llvm-request-c-wrappers
            -convert-func-to-llvm
            -reconcile-unrealized-casts | 
          ${LLVM_MLIR_BINARY_DIR}/mlir-translate --mlir-to-llvmir |
          clang -c -x ir -O3 --target=${BUDDY_OPT_TRIPLE} -fopenmp
            -o ${BUDDY_BINARY_DIR}/../benchmarks/OpOptimization/MatMul/batch-matmul-broadcast-${step}-omp.o -
  )
  add_library(BatchMatMulBroadcast${step}OMP STATIC batch-matmul-broadcast-${step}-omp.o)
  set_target_properties(BatchMatMulBroadcast${step}OMP PROPERTIES LINKER_LANGUAGE CXX)
endfunction()

Under normal circumstances, OpenMP requires dynamic library to start. I originally wanted to try statically linking the OpenMP library, gcc has libgomp.a and the compiler can do that, but I found that the Clang/LLVM official discourages this approach. nm -n shows that the entry name of the library is named batch_matmul_broadcast_64_omp..omp_par, not starts with _mlir_ciface_, also the C++ program cannot pass the Memref parameters to the MLIR function, I guess it should be called by the OpenMP dynamic library, but I can't find the way to use it.

Describe the solution you'd like
Discuss various possibilities to solve this problem. Perhaps correctly utilizing OpenMP::OpenMP_CXX in CMake is a good idea.

@xlinsist
Copy link
Collaborator

xlinsist commented Sep 2, 2023

We had better dive into this issue after PR #73 and buddy-compiler/buddy-mlir#187 are merged, since this issue depends on the previous PRs, but they haven't been fully settled. Other reviewers may find it hard to understand the background hided in a downstream file.

@EllisLambda
Copy link
Author

EllisLambda commented Sep 9, 2023

We had better dive into this issue after PR #73 and buddy-compiler/buddy-mlir#187 are merged, since this issue depends on the previous PRs, but they haven't been fully settled. Other reviewers may find it hard to understand the background hided in a downstream file.

The problem had been solved.

EllisLambda pushed a commit to EllisLambda/buddy-benchmark that referenced this issue Sep 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants