feat: introduce array_passed_in_function_call pass - #6363
Conversation
|
Important clarification: The above transformation should only happen when However in LFortran we run the array data pass that transforms This is important for the example here: https://github.com/lfortran/lfortran/pull/6363/files#r1962325268. |
b1048bb to
b4324e4
Compare
|
|
|
Phew! This segfault is the |
|
MRE: module cobyla_mod2
contains
subroutine cobylb(amat)
real, intent(in) :: amat(:, :) ! AMAT(N, M_LCON
end subroutine
subroutine cobyla()
implicit none
real, allocatable :: amat(:, :)
character(len=1024) :: str
call get_lincon(amat)
print *, "before: ", ubound(amat, 1), ubound(amat, 2)
str = " "
print *, trim(str)
print *, "after: ", ubound(amat, 1), ubound(amat, 2)
call cobylb(amat)
end subroutine cobyla
subroutine get_lincon(amat)
! Outputs
real, intent(out), allocatable :: amat(:, :)
integer, allocatable :: ixu(:)
real :: idmat(9, 9)
allocate(ixu(40), amat(9, 9))
amat = reshape(shape=[9, 9], source=[idmat(:, ixu)])
end subroutine get_lincon
end module cobyla_mod2
program cobyla_exmp
use cobyla_mod2, only : cobyla
implicit none
call cobyla()
end program cobyla_exmpI think we can shrink it further more % lfortran b.f90
before: 9 9
after: 4935887 4914972
% gfortran b.f90 && ./a.out
before: 9 9
after: 9 9 |
|
When I comment the trim statement, I get the same issue. So I don't think this is an issue with trim. $ lfortran a.f90
before: 9 9
after: 123 202
$ gfortran a.f90 && ./a.out
before: 9 9
after: 9 9Shorter MRE: module cobyla_mod2
contains
subroutine cobyla()
implicit none
real, allocatable :: amat(:, :)
call get_lincon(amat)
print *, "before: ", ubound(amat, 1), ubound(amat, 2)
print *, "after: ", ubound(amat, 1), ubound(amat, 2)
end subroutine cobyla
subroutine get_lincon(amat)
! Outputs
real, intent(out), allocatable :: amat(:, :)
integer, allocatable :: ixu(:)
real :: idmat(9, 9)
allocate(ixu(40), amat(9, 9))
amat = reshape(shape=[9, 9], source=[idmat(:, ixu)])
end subroutine get_lincon
end module cobyla_mod2
program cobyla_exmp
use cobyla_mod2, only : cobyla
implicit none
call cobyla()
end program cobyla_exmpHowever, reshape might be causing some issue... |
|
This MRE is tricky, not sure why this is happening. |
|
This PR exposes it, bug is present in latest main as well. |
|
opened issue at: #6377 |
|
#6378 will fix the issue so waiting for it to be merged. |
b4324e4 to
97052c4
Compare
97052c4 to
8640a10
Compare
|
Thanks @assem2002! On rebasing main after #6378 is merged, we compile PRIMA, let's wait for CI to run. |
|
One more rebase. |
certik
left a comment
There was a problem hiding this comment.
Great job. I think this looks good.
Let's resolve the conflicts.
Before we merge, let's test the performance, to ensure we didn't slow down runtime on existing codes.
|
Here is the SNAP benchmark on my Apple M4, using 169a921 in snap and this PR: And master (11a9330): So the Release mode has no slowdown. Why is the Debug time faster in this PR? The difference is small, but I would think this PR shouldn't make things faster. But it's good, no slowdown. Let's check one more code. |
|
dftatom, LFortran master; Debug: Release: This PR, Debug: Release: |
|
Ok, I tried dftatom and SNAP and I don't see any significant slowdown in either code, in neither Debug nor Release modes. So I think we are in good shape. Let's resolve the conflicts now. |
|
I resolved the conflicts and put in a merge commit, so that we don't lose the benchmarks and the commits that I tested. |
|
Tests pass, I am going to merge it. |
|
Thanks for wrapping this PR! Much appreciated! |
Fixes #6329. Fixes #6214.
One integration test fails due to divergence. I'll check it tomorrow morning.
With this PR we transform:
To