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

Add Python interface for compilation and one single interface for compilation and running process #1690

Merged
merged 44 commits into from
Oct 24, 2022

Conversation

Jiaqing-ASU
Copy link
Contributor

An ONNX model can be compiled directly using the onnx-mlir -O3 --EmitLib command. The resulting library can then be executed using Python. At times, it might be convenient to also compile a model directly in Python. We explores the Python methods to do so. And we also design an interface to package the compilation and operation of the model.

Jiaqing-ASU and others added 4 commits August 6, 2022 01:04
Signed-off-by: Jiaqing Chen <jchen501@asu.edu>
Signed-off-by: Jiaqing Chen <jchen501@asu.edu>
Signed-off-by: Jiaqing Chen <jchen501@asu.edu>
@jenkins-droid
Copy link
Collaborator

Can one of the admins verify this patch?

@AlexandreEichenberger
Copy link
Collaborator

@Jiaqing-ASU great, will review once #1683 has landed... thanks for working on this

@Jiaqing-ASU
Copy link
Contributor Author

@Jiaqing-ASU great, will review once #1683 has landed... thanks for working on this

Please allow some time for me to modify some of the code in this PR after #1683 has landed. I will make this PR Ready to review once I am done. Many thanks!

@AlexandreEichenberger
Copy link
Collaborator

PR landed now, so you can update your changes with the latest main branch.

@jenkins-droid
Copy link
Collaborator

Can one of the admins verify this patch?

Signed-off-by: Jiaqing Chen <jchen501@asu.edu>
@jenkins-droid
Copy link
Collaborator

Can one of the admins verify this patch?

1 similar comment
@jenkins-droid
Copy link
Collaborator

Can one of the admins verify this patch?

@AlexandreEichenberger
Copy link
Collaborator

@jenkins-droid test this please

Signed-off-by: Jiaqing Chen <jchen501@asu.edu>
@jenkins-droid
Copy link
Collaborator

Can one of the admins verify this patch?

@AlexandreEichenberger
Copy link
Collaborator

updating branch

Signed-off-by: Jiaqing Chen <jchen501@asu.edu>
@jenkins-droid
Copy link
Collaborator

Can one of the admins verify this patch?

@AlexandreEichenberger
Copy link
Collaborator

updated the branch to run all cis

@Jiaqing-ASU
Copy link
Contributor Author

updated the branch to run all cis

@AlexandreEichenberger Thanks for the merge. I guess this will pass the tests since it works in my environment. However, this are still several things of the new constructor need to be modify. I am working on this. Maybe you could review this later. Many thanks.

@AlexandreEichenberger
Copy link
Collaborator

yes, ping me when you feel its in a state where reviewing it make sense.

Signed-off-by: Jiaqing Chen <jchen501@asu.edu>
@jenkins-droid
Copy link
Collaborator

Can one of the admins verify this patch?

@jenkins-droid
Copy link
Collaborator

Can one of the admins verify this patch?

docs/mnist_example/README.md Outdated Show resolved Hide resolved
src/Compiler/PyOMCompileSession.cpp Show resolved Hide resolved
src/Compiler/PyOMCompileSession.cpp Show resolved Hide resolved
src/Runtime/PyOMCompileExecutionSession.hpp Show resolved Hide resolved
@jenkins-droid
Copy link
Collaborator

Can one of the admins verify this patch?

1 similar comment
@jenkins-droid
Copy link
Collaborator

Can one of the admins verify this patch?

Signed-off-by: Jiaqing Chen <jchen501@asu.edu>
@jenkins-droid
Copy link
Collaborator

Can one of the admins verify this patch?

@Jiaqing-ASU
Copy link
Contributor Author

Hello @sstamenova. Thanks for your guidance to solve /EHsc issue! It works well in my previous version of code. But, right now, I meet a new issue. MLIR-Windows-CI gives new errors (error LNK2001: unresolved external symbol) which seems like I need to link the header files where these functions are located in the target_link_libraries.

PyOMCompileExecutionSession.cpp.obj : error LNK2001: unresolved external symbol "public: class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > __cdecl onnx_mlir::PyExecutionSession::pyOutputSignature(void)" (?pyOutputSignature@PyExecutionSession@onnx_mlir@@QEAA?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@XZ)
PyOMCompileExecutionSession.cpp.obj : error LNK2001: unresolved external symbol "public: class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > __cdecl onnx_mlir::PyExecutionSession::pyInputSignature(void)" (?pyInputSignature@PyExecutionSession@onnx_mlir@@QEAA?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@XZ)
PyOMCompileExecutionSession.cpp.obj : error LNK2001: unresolved external symbol "public: class std::vector<class pybind11::array,class std::allocator<class pybind11::array> > __cdecl onnx_mlir::PyExecutionSession::pyRun(class std::vector<class pybind11::array,class std::allocator<class pybind11::array> > const &)" (?pyRun@PyExecutionSession@onnx_mlir@@QEAA?AV?$vector@Varray@pybind11@@V?$allocator@Varray@pybind11@@@std@@@std@@AEBV34@@Z)
PyOMCompileExecutionSession.cpp.obj : error LNK2001: unresolved external symbol "public: void __cdecl onnx_mlir::PyExecutionSession::pySetEntryPoint(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >)" (?pySetEntryPoint@PyExecutionSession@onnx_mlir@@QEAAXV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z)
PyOMCompileExecutionSession.cpp.obj : error LNK2001: unresolved external symbol "public: class std::vector<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,class std::allocator<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > > > __cdecl onnx_mlir::PyExecutionSession::pyQueryEntryPoints(void)" (?pyQueryEntryPoints@PyExecutionSession@onnx_mlir@@QEAA?AV?$vector@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@V?$allocator@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@2@@std@@XZ)
PyOMCompileExecutionSession.cpp.obj : error LNK2001: unresolved external symbol "public: __cdecl onnx_mlir::PyExecutionSession::PyExecutionSession(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,bool)" (??0PyExecutionSession@onnx_mlir@@QEAA@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@_N@Z)
PyOMCompileExecutionSession.cpp.obj : error LNK2001: unresolved external symbol "public: class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > __cdecl onnx_mlir::PyOMCompileSession::pyGetErrorMessage(void)" (?pyGetErrorMessage@PyOMCompileSession@onnx_mlir@@QEAA?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@XZ)
PyOMCompileExecutionSession.cpp.obj : error LNK2001: unresolved external symbol "public: class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > __cdecl onnx_mlir::PyOMCompileSession::pyGetCompiledFileName(void)" (?pyGetCompiledFileName@PyOMCompileSession@onnx_mlir@@QEAA?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@XZ)
PyOMCompileExecutionSession.cpp.obj : error LNK2001: unresolved external symbol "public: __int64 __cdecl onnx_mlir::PyOMCompileSession::pyCompileFromArray(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,enum onnx_mlir::EmissionTargetType)" (?pyCompileFromArray@PyOMCompileSession@onnx_mlir@@QEAA_JV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@W4EmissionTargetType@2@@Z)
PyOMCompileExecutionSession.cpp.obj : error LNK2001: unresolved external symbol "public: __int64 __cdecl onnx_mlir::PyOMCompileSession::pyCompileFromFile(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >)" (?pyCompileFromFile@PyOMCompileSession@onnx_mlir@@QEAA_JV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z)
Release\lib\PyCompileAndRuntime.cp39-win_amd64.pyd : fatal error LNK1120: 10 unresolved externals

As those files cannot be linked into target_link_libraries, I would like to ask whether this is any other solutions to solve this error? If not, I will just revert to my previous code. Beacuse the reason for me to refactor the code just to reduce some duplicate code and my previous code works well with no warnings or errors. Thanks for the help!

${ONNX_MLIR_SRC_ROOT}/include
$<TARGET_PROPERTY:onnx,INCLUDE_DIRECTORIES>
)
target_link_libraries(PyCompileAndRuntime
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why aren't you linking this against PyCompile and PyRuntime?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because PyCompile and PyRuntime are not normal C++ libraries. Furthermore, they are not even normal shared libraries which means this solution I have tried before does not work. I have also tried another solution to combine two pybind11-wrapped projects. It also does not work either as it is a little bit different from our situation. We need to have two objects of PyCompile and PyRuntime inside the new class and then use the functions inside the objects instead of just calling functions from another pybind11-generated Python binding. Also, I did not get enough information from the llvm-project pybind11_add_module. Maybe I am looking into some wrong places.

Signed-off-by: Jiaqing Chen <jchen501@asu.edu>
@jenkins-droid
Copy link
Collaborator

Can one of the admins verify this patch?

@jenkins-droid
Copy link
Collaborator

Can one of the admins verify this patch?

Copy link
Collaborator

@AlexandreEichenberger AlexandreEichenberger left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks for the great work @Jiaqing-ASU .

Extra redundancy can be removed at some later time in a subsequent PR once we figure how to do it.

@AlexandreEichenberger AlexandreEichenberger merged commit fdbd1f0 into onnx:main Oct 24, 2022
@jenkins-droid
Copy link
Collaborator

Jenkins Linux amd64 Build #8319 [push] Add Python interface for... started at 10:31

@jenkins-droid
Copy link
Collaborator

Jenkins Linux s390x Build #8335 [push] Add Python interface for... started at 11:31

@jenkins-droid
Copy link
Collaborator

Jenkins Linux ppc64le Build #7386 [push] Add Python interface for... started at 11:32

@jenkins-droid
Copy link
Collaborator

Jenkins Linux amd64 Build #8319 [push] Add Python interface for... passed after 1 hr 25 min

@jenkins-droid
Copy link
Collaborator

Jenkins Linux s390x Build #8335 [push] Add Python interface for... passed after 1 hr 32 min

@jenkins-droid
Copy link
Collaborator

Jenkins Linux ppc64le Build #7386 [push] Add Python interface for... passed after 1 hr 40 min

gargaroff pushed a commit to ljfitz/onnx-mlir that referenced this pull request Nov 3, 2022
…pilation and running process (onnx#1690)

* Add compiler interface to python

Signed-off-by: Jiaqing Chen <jchen501@asu.edu>
Co-authored-by: Alexandre Eichenberger <alexe@us.ibm.com>
gargaroff pushed a commit to ljfitz/onnx-mlir that referenced this pull request Nov 8, 2022
…pilation and running process (onnx#1690)

* Add compiler interface to python

Signed-off-by: Jiaqing Chen <jchen501@asu.edu>
Co-authored-by: Alexandre Eichenberger <alexe@us.ibm.com>
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

Successfully merging this pull request may close these issues.

4 participants