You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
LFortran supports optimization passes like loop_unroll, fma, etc. which are already supported in libasr. We should update LPython to make use of these optimization passes.
LPython already uses the passes which you have mentioned. The interface to input the list of passes is exactly the same for LPython and LFortran. Use command line argument, —pass.
The exception you get is outdated, because this is what I get if I pass an unsupported pass,
(lp) 16:51:47:~/lpython_project/lpython % lpython --pass=fma1 --show-asr tests/expr16.py
fma1 isn't supported yet. Only the following passes are supported:- arr_slicearray_opclass_constructordead_code_removaldiv_to_muldo_loopsflip_signfmaforallglobal_stmtsimplied_do_loopsinline_function_callsloop_unrollloop_vectoriseprint_arrselect_casesign_from_valueunused_functions
Now, to generalise these utility functions for LCompilers there are two options with us,
Compile modules in every LCompiler - On the basis of my understanding, LPython as of now re-compiles a module every time we import it. Or in other words there are no .mod files generated for intrinsic modules while building LPython. On the contrary, when we build LFortran then all the intrinsic modules are pre-compiled and saved into .mod files. Whenever we use them the .mod file is deserialised and inserted into the global scope of ASR. So, either make LPython work in a similar fashion so that we can write the fallback implementations of each of these optimisations in a python module, save it in a .mod file and re-use them in whatever way we want.
Insert fallback implementations directly in the ASR - So, I added loop_vectorise implementation recently into LPython. In this we don't attempt to load it from a python module but we ourselves create a fallback implementation with the help of ASR APIs and insert it into the global scope. We can follow this approach in all the LCompilers as well.
ASR::symbol_t *v = insert_fallback_vector_copy(al, unit, global_scope,
types,
"vector_copy_");
I am fine either of the approaches. We just have to follow a single approach across all the LCompilers because libasr is a shared portion of the code and once an ASR is generated you never know from which language it was created (unless you are willing to use hackish string checks).
Personal opinion - I would like to follow point 2 as I already did with loop_vectorise (after discussing with @certik) because it provides us flexibility and scalability for a variety of type combinations (infinite in theory). The first approach would require us to write fallback implementations for a very large number of type combinations and that too for each of the optimisations we want to add which is ad-hoc I believe.
I and @certik discussed this yesterday. We arrived at the conclusion to use idea in point number 2 of #723 (comment). The reason to go for this approach is because of the scalability advantage it provides which is a major overhead if we implement all the fallback implementations of optimisations manually by writing modules, etc. In addition, the ASR remains compact because we generate fallback implementations only for those combination of types which are in the user code (and not for every combination of types beforehand).
In future, we will abstract the code in order to generate subroutines, functions using ASR APIs easier.
Activity
certik commentedon Jul 2, 2022
The new pass manager will allow it, we just have to integrate it.
czgdp1807 commentedon Jul 2, 2022
LPython already uses the passes which you have mentioned. The interface to input the list of passes is exactly the same for LPython and LFortran. Use command line argument,
—pass.czgdp1807 commentedon Jul 2, 2022
In addition also see,
asr_to_llvm.cppin both the compilers. They both call the pass manager to apply same set of passes.Smit-create commentedon Jul 2, 2022
On the main branch, I get:
On updating the
bin/lpythonto use fma, I get:czgdp1807 commentedon Jul 2, 2022
Here's what I get,
Commit on
mainbranch - acac3baczgdp1807 commentedon Jul 2, 2022
The exception you get is outdated, because this is what I get if I pass an unsupported pass,
Smit-create commentedon Jul 2, 2022
Oh, I see. I forgot to fetch the latest main. But still there is an exception:
Thirumalai-Shaktivel commentedon Jul 2, 2022
Hi @Smit-create, I was also getting the same message as yours.
So, after updating the lpython main branch using
I got the output similar to @czgdp1807.
Smit-create commentedon Jul 2, 2022
Does this error have a dependency on this file? https://gitlab.com/lfortran/lfortran/-/blob/master/src/runtime/builtin/lfortran_intrinsic_optimization.f90 I don't have that locally, so that might be the reason for this failure?
czgdp1807 commentedon Jul 2, 2022
The error you are getting is because the following function is tuned for LFortran,
https://github.com/lfortran/lfortran/blob/ecd48b8676f50372c60f3d846b54bce648472802/src/libasr/pass/pass_utils.h#L56-L59
which is called from the below line,
https://github.com/lfortran/lfortran/blob/ecd48b8676f50372c60f3d846b54bce648472802/src/libasr/pass/fma.cpp#L119-L121
Now, to generalise these utility functions for LCompilers there are two options with us,
.modfiles generated for intrinsic modules while building LPython. On the contrary, when we build LFortran then all the intrinsic modules are pre-compiled and saved into.modfiles. Whenever we use them the.modfile is deserialised and inserted into the global scope of ASR. So, either make LPython work in a similar fashion so that we can write the fallback implementations of each of these optimisations in a python module, save it in a.modfile and re-use them in whatever way we want.lpython/src/lpython/semantics/python_ast_to_asr.cpp
Lines 126 to 127 in acac3ba
loop_vectoriseimplementation recently into LPython. In this we don't attempt to load it from a python module but we ourselves create a fallback implementation with the help of ASR APIs and insert it into the global scope. We can follow this approach in all the LCompilers as well.lpython/src/libasr/pass/pass_utils.cpp
Lines 479 to 481 in acac3ba
The above function is called in
get_vector_copyas follows,lpython/src/libasr/pass/pass_utils.cpp
Lines 537 to 547 in acac3ba
I am fine either of the approaches. We just have to follow a single approach across all the LCompilers because
libasris a shared portion of the code and once an ASR is generated you never know from which language it was created (unless you are willing to use hackish string checks).Personal opinion - I would like to follow point 2 as I already did with
loop_vectorise(after discussing with @certik) because it provides us flexibility and scalability for a variety of type combinations (infinite in theory). The first approach would require us to write fallback implementations for a very large number of type combinations and that too for each of the optimisations we want to add which is ad-hoc I believe.certik commentedon Jul 11, 2022
Let's brainstorm this more. We want to be able to reuse these passes for all frontends.
czgdp1807 commentedon Jul 12, 2022
I and @certik discussed this yesterday. We arrived at the conclusion to use idea in point number 2 of #723 (comment). The reason to go for this approach is because of the scalability advantage it provides which is a major overhead if we implement all the fallback implementations of optimisations manually by writing modules, etc. In addition, the ASR remains compact because we generate fallback implementations only for those combination of types which are in the user code (and not for every combination of types beforehand).
In future, we will abstract the code in order to generate subroutines, functions using ASR APIs easier.