mirror of
https://github.com/capstone-engine/llvm-capstone.git
synced 2024-11-27 15:41:46 +00:00
Activate OpenMP translation in MLIR execution engine CAPI.
We've observed that the MLIR Jit Engine fails when the `omp` dialect is used due to a failure to register OpenMP-related translations. This small patch addresses this issue. Reviewed By: mehdi_amini Differential Revision: https://reviews.llvm.org/D151577
This commit is contained in:
parent
94407e1bba
commit
db7cc0348c
@ -13,6 +13,7 @@
|
||||
#include "mlir/ExecutionEngine/OptUtils.h"
|
||||
#include "mlir/Target/LLVMIR/Dialect/Builtin/BuiltinToLLVMIRTranslation.h"
|
||||
#include "mlir/Target/LLVMIR/Dialect/LLVMIR/LLVMToLLVMIRTranslation.h"
|
||||
#include "mlir/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.h"
|
||||
#include "llvm/ExecutionEngine/Orc/Mangling.h"
|
||||
#include "llvm/Support/TargetSelect.h"
|
||||
|
||||
@ -33,6 +34,7 @@ mlirExecutionEngineCreate(MlirModule op, int optLevel, int numPaths,
|
||||
auto &ctx = *unwrap(op)->getContext();
|
||||
mlir::registerBuiltinDialectTranslation(ctx);
|
||||
mlir::registerLLVMDialectTranslation(ctx);
|
||||
mlir::registerOpenMPDialectTranslation(ctx);
|
||||
|
||||
auto tmBuilderOrError = llvm::orc::JITTargetMachineBuilder::detectHost();
|
||||
if (!tmBuilderOrError) {
|
||||
|
@ -85,6 +85,52 @@ void testSimpleExecution(void) {
|
||||
mlirContextDestroy(ctx);
|
||||
}
|
||||
|
||||
// CHECK-LABEL: Running test 'testOmpCreation'
|
||||
void testOmpCreation(void) {
|
||||
MlirContext ctx = mlirContextCreate();
|
||||
registerAllUpstreamDialects(ctx);
|
||||
|
||||
MlirModule module = mlirModuleCreateParse(
|
||||
ctx, mlirStringRefCreateFromCString(
|
||||
// clang-format off
|
||||
"module { \n"
|
||||
" func.func @main() attributes { llvm.emit_c_interface } { \n"
|
||||
" %0 = arith.constant 0 : i32 \n"
|
||||
" %1 = arith.constant 1 : i32 \n"
|
||||
" %2 = arith.constant 2 : i32 \n"
|
||||
" omp.parallel { \n"
|
||||
" omp.wsloop for (%3) : i32 = (%0) to (%2) step (%1) { \n"
|
||||
" omp.yield \n"
|
||||
" } \n"
|
||||
" omp.terminator \n"
|
||||
" } \n"
|
||||
" llvm.return \n"
|
||||
" } \n"
|
||||
"} \n"
|
||||
));
|
||||
// clang-format on
|
||||
lowerModuleToLLVM(ctx, module);
|
||||
|
||||
// At this point all operations in the MLIR module have been lowered to the
|
||||
// 'llvm' dialect except 'omp' operations. The goal of this test is
|
||||
// guaranteeing that the execution engine C binding has registered OpenMP
|
||||
// translations and therefore does not fail when it encounters 'omp' ops.
|
||||
// We don't attempt to run the engine, since that would force us to link
|
||||
// against the OpenMP library.
|
||||
MlirExecutionEngine jit = mlirExecutionEngineCreate(
|
||||
module, /*optLevel=*/2, /*numPaths=*/0, /*sharedLibPaths=*/NULL,
|
||||
/*enableObjectDump=*/false);
|
||||
if (mlirExecutionEngineIsNull(jit)) {
|
||||
fprintf(stderr, "Engine creation failed with OpenMP");
|
||||
exit(2);
|
||||
}
|
||||
// CHECK: Engine creation succeeded with OpenMP
|
||||
printf("Engine creation succeeded with OpenMP\n");
|
||||
mlirExecutionEngineDestroy(jit);
|
||||
mlirModuleDestroy(module);
|
||||
mlirContextDestroy(ctx);
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
|
||||
#define _STRINGIFY(x) #x
|
||||
@ -94,5 +140,6 @@ int main(void) {
|
||||
test();
|
||||
|
||||
TEST(testSimpleExecution);
|
||||
TEST(testOmpCreation);
|
||||
return 0;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user