@mehdi_amini thanks. the information is helpful. I was able to invoke execution engine in python. But I still need to get the C++ version of execution engine work in order to connect with rest of my project (written in C++)
I found a good example to follow here: llvm-project/ExecutionEngine.cpp at fdec50182d85ec0b8518af3baae37ae28b102f1c · llvm/llvm-project · GitHub
Here is the code I am using right now after referring to the examples and many rounds of trail and errors.
static bool runTaskFlowExecutor(
std::map<std::string, MlirModule> &modules,
std::map<std::string, std::vector<py::array_t<float>>> argsMap) {
for (auto& [stage, mlir_mod]: modules ) {
auto mod = unwrap(mlir_mod);
mlir::registerLLVMDialectTranslation(*mod->getContext());
auto maybeEngine = mlir::ExecutionEngine::create(mod);
if (!maybeEngine)
throw std::runtime_error("maybeEngine failed");
auto engine = std::move(*maybeEngine);
auto entryPoint = StringRef("top");
auto expectedFPtr = engine->lookupPacked(entryPoint);
if (!expectedFPtr)
throw std::runtime_error("not found entryPoint top");
auto modArgs = argsMap[stage];
void** args = (void **) malloc(sizeof(void *) * modArgs.size());;
size_t index = 0;
for (auto tensor: modArgs) {
py::buffer_info buf = tensor.request();
args[index] = buf.ptr;
index++;
}
// void (*fptr)(void **) = *expectedFPtr;
// (*fptr)((void**)args);
llvm::Error error = engine->invokePacked(entryPoint,
llvm::MutableArrayRef<void *>{args, (size_t)0});
if (error)
return false;
}
return false;
}
But I still run into this mysterious SegFault. Here is the stack trace. I cannot really understand the trace; it does not provide much useful information why invokePacked
failed.
#0 0x00007f048a9f8b3f PrintStackTraceSignalHandler(void*) Signals.cpp:0:0
#1 0x00007f048a9f682c SignalHandler(int) Signals.cpp:0:0
#2 0x00007f0512060630 __restore_rt sigaction.c:0:0
#3 0x00007f05129e5096
#4 0x00007f048ae4d089 mlir::ExecutionEngine::invokePacked(llvm::StringRef, llvm::MutableArrayRef<void*>) (/scratch/users/sx233/hcl-dialect-prototype/build/tools/hcl/python_packages/hcl_core/hcl_mlir/_mlir
_libs/libHCLMLIRAggregateCAPI.so.15+0x15c6089)
#5 0x00007f0488d459b2 runTaskFlowExecutor(std::map<std::string, MlirModule, std::less<std::string>, std::allocator<std::pair<std::string const, MlirModule>>>&, std::map<std::string, std::vector<pybind11::
array_t<float, 16>, std::allocator<pybind11::array_t<float, 16>>>, std::less<std::string>, std::allocator<std::pair<std::string const, std::vector<pybind11::array_t<float, 16>, std::allocator<pybind11::arr
ay_t<float, 16>>>>>>) //scratch/users/sx233/hcl-dialect-prototype/lib/Bindings/Python/HCLModule.cpp:192:0
#6 0x00007f0488d955c3 bool pybind11::detail::argument_loader<std::map<std::string, MlirModule, std::less<std::string>, std::allocator<std::pair<std::string const, MlirModule>>>&, std::map<std::string, std
::vector<pybind11::array_t<float, 16>, std::allocator<pybind11::array_t<float, 16>>>, std::less<std::string>, std::allocator<std::pair<std::string const, std::vector<pybind11::array_t<float, 16>, std::allo
cator<pybind11::array_t<float, 16>>>>>>>::call_impl<bool, bool (*&)(std::map<std::string, MlirModule, std::less<std::string>, std::allocator<std::pair<std::string const, MlirModule>>>&, std::map<std::strin
g, std::vector<pybind11::array_t<float, 16>, std::allocator<pybind11::array_t<float, 16>>>, std::less<std::string>, std::allocator<std::pair<std::string const, std::vector<pybind11::array_t<float, 16>, std
::allocator<pybind11::array_t<float, 16>>>>>>), 0ul, 1ul, pybind11::detail::void_type>(bool (*&)(std::map<std::string, MlirModule, std::less<std::string>, std::allocator<std::pair<std::string const, MlirMo
dule>>>&, std::map<std::string, std::vector<pybind11::array_t<float, 16>, std::allocator<pybind11::array_t<float, 16>>>, std::less<std::string>, std::allocator<std::pair<std::string const, std::vector<pybi
nd11::array_t<float, 16>, std::allocator<pybind11::array_t<float, 16>>>>>>), std::integer_sequence<unsigned long, 0ul, 1ul>, pybind11::detail::void_type&&) && /work/shared/users/phd/sx233/conda/envs/py36/l
ib/python3.6/site-packages/pybind11/include/pybind11/cast.h:1441:0
#7 0x00007f0488d8ed63 _ZNO8pybind116detail15argument_loaderIJRSt3mapISs10MlirModuleSt4lessISsESaISt4pairIKSsS3_EEES2_ISsSt6vectorINS_7array_tIfLi16EEESaISE_EES5_SaIS6_IS7_SG_EEEEE4callIbNS0_9void_typeERPF
bSB_SJ_EEENSt9enable_ifIXntsrSt7is_voidIT_E5valueESS_E4typeEOT1_ /work/shared/users/phd/sx233/conda/envs/py36/lib/python3.6/site-packages/pybind11/include/pybind11/cast.h:1410:0
#8 0x00007f0488d842f5 void pybind11::cpp_function::initialize<bool (*&)(std::map<std::string, MlirModule, std::less<std::string>, std::allocator<std::pair<std::string const, MlirModule>>>&, std::map<std::
string, std::vector<pybind11::array_t<float, 16>, std::allocator<pybind11::array_t<float, 16>>>, std::less<std::string>, std::allocator<std::pair<std::string const, std::vector<pybind11::array_t<float, 16>
, std::allocator<pybind11::array_t<float, 16>>>>>>), bool, std::map<std::string, MlirModule, std::less<std::string>, std::allocator<std::pair<std::string const, MlirModule>>>&, std::map<std::string, std::v
ector<pybind11::array_t<float, 16>, std::allocator<pybind11::array_t<float, 16>>>, std::less<std::string>, std::allocator<std::pair<std::string const, std::vector<pybind11::array_t<float, 16>, std::allocat
or<pybind11::array_t<float, 16>>>>>>, pybind11::name, pybind11::scope, pybind11::sibling>(bool (*&)(std::map<std::string, MlirModule, std::less<std::string>, std::allocator<std::pair<std::string const, Mli
rModule>>>&, std::map<std::string, std::vector<pybind11::array_t<float, 16>, std::allocator<pybind11::array_t<float, 16>>>, std::less<std::string>, std::allocator<std::pair<std::string const, std::vector<p
ybind11::array_t<float, 16>, std::allocator<pybind11::array_t<float, 16>>>>>>), bool (*)(std::map<std::string, MlirModule, std::less<std::string>, std::allocator<std::pair<std::string const, MlirModule>>>&
, std::map<std::string, std::vector<pybind11::array_t<float, 16>, std::allocator<pybind11::array_t<float, 16>>>, std::less<std::string>, std::allocator<std::pair<std::string const, std::vector<pybind11::ar
ray_t<float, 16>, std::allocator<pybind11::array_t<float, 16>>>>>>), pybind11::name const&, pybind11::scope const&, pybind11::sibling const&)::'lambda1'(pybind11::detail::function_call&)::operator()(pybind
11::detail::function_call&) const /work/shared/users/phd/sx233/conda/envs/py36/lib/python3.6/site-packages/pybind11/include/pybind11/pybind11.h:249:0