-
Notifications
You must be signed in to change notification settings - Fork 171
--jit
option to execute without creation of executable file
#2564
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
Conversation
Both of the failing workflows are WASM related. One of them says |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, I think we should test this, try resolving my review above, later we will figure out how to test this.
src/bin/lpython.cpp
Outdated
} catch (LCompilers::LCompilersException&) {} | ||
auto llvm_end = std::chrono::high_resolution_clock::now(); | ||
times.push_back(std::make_pair("LLVM to binary", std::chrono::duration<double, std::milli>(llvm_end - llvm_start).count())); | ||
print_time_report(times, time_report); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's do this only for LLVM backend.
This seems duplicated, try utilising or simplifying the function: compile_python_to_object_file
Please mark this PR ready for review once it is ready. |
src/bin/lpython.cpp
Outdated
if (to_jit) { | ||
compiler_options.emit_debug_info = false; | ||
compiler_options.emit_debug_line_column = false; | ||
compiler_options.generate_object_code = false; | ||
return execute_python_using_jit(arg_file, runtime_library_dir, | ||
lpython_pass_manager, compiler_options, time_report); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One of them says error: use of undeclared identifier 'execute_python_using_jit'. Even though it is declared and defined in the preceding lines.
This should be wrapped inside #ifdef HAVE_LFORTRAN_LLVM
#endif
. Hopefully, it should fix the CI failure.
@Thirumalai-Shaktivel, Regarding testing out this feature. I was thinking to add the following run_test(
f"{filename} JIT",
"llvm",
"lpython --jit {infile}",
filename,
update_reference) after llvm test at run_tests.py. But I get
when I run it. I do not properly understand the methodology used to test existing features. Suggestion and guidance would be helpful here. |
I think we need to test this using |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The implementation looks good so far.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good! Thanks for this! Now, you just need to add an integration test for this. You can leverage the existing EXTRA_ARGS
support. For example:
diff --git a/integration_tests/CMakeLists.txt b/integration_tests/CMakeLists.txt
index 44b703eae..1db5d10b8 100644
--- a/integration_tests/CMakeLists.txt
+++ b/integration_tests/CMakeLists.txt
@@ -313,11 +313,10 @@ endmacro(RUN_UTIL)
macro(RUN)
set(options FAIL NOFAST NOMOD ENABLE_CPYTHON LINK_NUMPY NO_WARNINGS)
set(oneValueArgs NAME IMPORT_PATH COPY_TO_BIN REQ_PY_VER)
- set(multiValueArgs LABELS EXTRAFILES)
+ set(multiValueArgs LABELS EXTRAFILES EXTRA_ARGS)
cmake_parse_arguments(RUN "${options}" "${oneValueArgs}"
"${multiValueArgs}" ${ARGN} )
- set(RUN_EXTRA_ARGS "")
set(RUN_FILE_NAME ${RUN_NAME})
if (RUN_LINK_NUMPY)
@@ -826,3 +825,6 @@ COMPILE(NAME import_order_01 LABELS cpython llvm c) # any
# LPython emulation mode
RUN(NAME lpython_emulation_01 LABELS cpython NOMOD)
+
+RUN(NAME jit_01 LABELS cpython llvm
+ EXTRA_ARGS --jit)
We need an integration test for this. Please mark this as "Ready for review" when ready. Thanks for working on this! I appreciate it. |
We expect
to fail (i.e. exit with non-zero code). What should I do here? When the exit code is supposed to be non-zero?
fails because it has an external dependency. I believe we should skip these tests under JIT.
EDITED: I would also want to add that |
integration_tests/CMakeLists.txt
Outdated
# unset(RUN_EXTRA_ARGS) | ||
# set(RUN_EXTRA_ARGS --jit) | ||
# set(RUN_NAME "${RUN_NAME}_JIT") | ||
# RUN_UTIL(RUN_FAIL RUN_NAME RUN_FILE_NAME RUN_LABELS RUN_EXTRAFILES RUN_NOMOD RUN_EXTRA_ARGS RUN_COPY_TO_BIN) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't intend to push this. I was testing stuff out in my local computer, I should have removed this before pushing. Sorry. Will remove it in the next commit.
@Thirumalai-Shaktivel, @Shaikh-Ubaid Look at #2595. If you could verify that they are definitely memory-related bugs it would be helpful. I did not look at the AST and ASR. I will investigate them tomorrow. |
Please mark it as "Ready for review" when ready. |
I believe this PR is ready for review/merge. CC: @Shaikh-Ubaid I will explain some aspects of the modifications I have made to run the tests:
There are only 2 tests that fail. They fail due to segfault. And related to #2595. They are not caused by any new bug I have introduced. My code happens to trigger it. I tried investigating the segfault, but have not found its cause yet. It is very difficult to debug the LLVM IR directly. Presently I am trying to do that. Also fixing them should not be part of this PR. Also, the Windows CI is not running to completion. Please read this comment I made in the zulip chat. |
@Vipul-Cariappa From a high level it looks good. I will review it thoroughly tomorrow.
We will need the CI to be green to merge this. So, we either need to get the two failing tests to work or we need to completely skip running these two tests with |
Thanks! The advantages of this approach:
Disadvantages:
The handling of shared libraries is something we will need for interactive mode as well, so I think we need this. The current implementation works for Conda, but it will fail for, say, Ubuntu, which uses a To finish this, let's get all tests passing, and then let's polish the implementation, so that we can merge it. Then we can improve upon it. |
I am trying to debug and fix #2595. It would be better to fix the issues and then merge this PR. Skipping the failing tests will require quite a lot of modifications to the |
Ready for review. @Shaikh-Ubaid @certik |
@Vipul-Cariappa Can you rebase the branch on top of latest |
remove the try catch block around the execution of global_init & global_stmts
…t` to `compile_python_using_llvm` removed duplicated code
Co-authored-by: Shaikh Ubaid <[email protected]>
Co-authored-by: Shaikh Ubaid <[email protected]>
…lers#2564) * Add --jit option to execute without creation of executable file * execute global_init & global_stmts after checking their existence remove the try catch block around the execution of global_init & global_stmts * CI fix & raise error for non-llvm backend with jit * combined `compile_python_to_object_file` and `execute_python_using_jit` to `compile_python_using_llvm` removed duplicated code * Add testing mechanism * Testing with cpython and symengine * skipping jit tests with external dependency * skipping testing JIT that depend on syms or cpython * support to use cpython and symengine with JIT * Trigger CI/CD * windows fix * WASM ci fix * allow few tests to fail under `--jit` * fix for lcompilers#2595 * factored out loading cpython and symengine libraries * wasm related fix * windows ci fix * windows ci fix * windows ci fix * updated for consistency Co-authored-by: Shaikh Ubaid <[email protected]> * updated for consistency * Apply suggestions from code review Co-authored-by: Shaikh Ubaid <[email protected]> --------- Co-authored-by: Shaikh Ubaid <[email protected]>
…lers#2564) * Add --jit option to execute without creation of executable file * execute global_init & global_stmts after checking their existence remove the try catch block around the execution of global_init & global_stmts * CI fix & raise error for non-llvm backend with jit * combined `compile_python_to_object_file` and `execute_python_using_jit` to `compile_python_using_llvm` removed duplicated code * Add testing mechanism * Testing with cpython and symengine * skipping jit tests with external dependency * skipping testing JIT that depend on syms or cpython * support to use cpython and symengine with JIT * Trigger CI/CD * windows fix * WASM ci fix * allow few tests to fail under `--jit` * fix for lcompilers#2595 * factored out loading cpython and symengine libraries * wasm related fix * windows ci fix * windows ci fix * windows ci fix * updated for consistency Co-authored-by: Shaikh Ubaid <[email protected]> * updated for consistency * Apply suggestions from code review Co-authored-by: Shaikh Ubaid <[email protected]> --------- Co-authored-by: Shaikh Ubaid <[email protected]>
Using LLVM JIT.
Fixes #2563.
Example:
With
--jit
flag❯ time ./src/bin/lpython --jit ./examples/expr2.py 25 ./src/bin/lpython --jit ./examples/expr2.py 0.01s user 0.00s system 97% cpu 0.013 total
Without
❯ time ./src/bin/lpython ./examples/expr2.py 25 ./src/bin/lpython ./examples/expr2.py 0.02s user 0.01s system 99% cpu 0.037 total