-
-
Notifications
You must be signed in to change notification settings - Fork 134
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
WASM: Supporting array passing with explicit shapes #99
WASM: Supporting array passing with explicit shapes #99
Conversation
29be69f
to
b4f01a0
Compare
Corresponding to tests |
This is ready. Please, possibly review and please share feedback. |
You can keep the new tests. |
I think this looks good. Can you polish the history? Remove those "revert" commits. Don't merge, I want to get #97 in first. |
Please, could you possibly share if you mean to remove the word |
Since, the |
Please, could you possibly share if the |
Sure, got it. |
Can you merge with the latest main? |
Got it. I just pushed a commit with this change. |
doubts:
|
This is ready. Please possibly review and please share feedback. |
Thanks! I'll review soon. |
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 think this is fine to merge as is. You can keep those revert commits, I thought you added some stuff in this PR and then reverted it, but you reverted something that was already in master, so that's fine.
With these explicit-shape arrays in, what else is missing in order to do the Mandelbrot example?
I tested the following program mandelbrot
implicit none
integer , parameter :: rk = selected_real_kind (9, 99)
integer , parameter :: i_max = 800
integer , parameter :: j_max = 600
integer , parameter :: n_max = 100
real (rk), parameter :: x_centre = -0.5_rk
real (rk), parameter :: y_centre = 0.0_rk
real (rk), parameter :: width = 4.0_rk
real (rk), parameter :: height = 3.0_rk
real (rk), parameter :: dx_di = width / i_max
real (rk), parameter :: dy_dj = -height / j_max
real (rk), parameter :: x_offset = x_centre - 0.5_rk * (i_max + 1) * dx_di
real (rk), parameter :: y_offset = y_centre - 0.5_rk * (j_max + 1) * dy_dj
integer :: image(i_max, j_max)
integer :: i
integer :: j
integer :: n
real (rk) :: x
real (rk) :: y
real (rk) :: x_0
real (rk) :: y_0
real (rk) :: x_sqr
real (rk) :: y_sqr
do j = 1, j_max
y_0 = y_offset + dy_dj * j
do i = 1, i_max
x_0 = x_offset + dx_di * i
x = 0.0_rk
y = 0.0_rk
n = 0
do
x_sqr = x ** 2
y_sqr = y ** 2
if (x_sqr + y_sqr > 4.0_rk) then
image(i,j) = 255
exit
end if
if (n == n_max) then
image(i,j) = 0
exit
end if
y = y_0 + 2.0_rk * x * y
x = x_0 + x_sqr - y_sqr
n = n + 1
end do
end do
end do
print '(a)', 'P2'
print '(i0, 1x, i0)', i_max, j_max
print '(i0)', 255
do j = 1, j_max
do i = 1, i_max
print '(i0)', image(i,j)
end do
end do
end program mandelbrot This code works in the
|
I also tried with page sizes
|
Excellent! For the The memory size is allocated in JavaScript? Once this runs in an online demo, we can simply allocate enough size to support these small demos. This will be the first step, just print it using print. Then as the next step, we should return the computed image as an array to JavaScript for showing it as an image. |
Got it.
We can do it two/both ways, that is-
Currently, we follow the first way. The memory is created here https://github.com/lfortran/lfortran/blob/main/src/libasr/codegen/wasm_assembler.h#L614 and it is imported into In the above two code lines, we observe that the Explanation: In |
I updated/replaced Also, I made a |
@certik, please, could you possibly share if you mean to support this as/at compile-time or run-time? It seems supporting it at integer function pow(x, n) result(r)
integer, intent(in) :: x, n
integer :: r, i
r = 1
do i = 1 to n
r = r * x
end do
end function |
It seems evaluating I tried supporting Please, could you possibly share if we could/should just import the |
You can import the pow from JavaScript for now |
But it will be slow, so after it works, we'll have to implement our own version. Yes, we need WASM specific runtime library I think. We can probably just implement this in our regular library, and then you call it from the WASM backend, or something like that. |
This
PR
implements the feature described in this comment #98 (comment).HIghlights:
1-D
,2-D
andn-Dimensional
arrays.integration_tests
have been added.