News for hackers. Stuff that matters.
Re:Fortran on WebAssembly by certik on Friday April 05, 2024 @02:06PM (#39945300)
The author of LFortran here.

The demo at https://dev.lfortran.org uses our direct WASM backend that does not use LLVM. It is currently more limited, and indeed, we currently do not support the cubic power x**3 there, only square power x**2. Our most advanced backend is LLVM, and that of course supports x**3 and a very wide subset of Fortran (such as 60% of all SciPy packages fully compile and all SciPy tests pass). However, LLVM is huge and relatively slow, so we do not use LLVM in the online demo, which runs the compiler itself in the browser.

For offline LLVM based WASM compilation I think LFortran is ready be tried. We'll be happy to help!

Re:Fortran on WebAssembly by superjan on Friday April 05, 2024 @03:19PM (#39946037)
Just curious but what is keeping you from compiling x*3?
Re:Fortran on WebAssembly by certik on Friday April 05, 2024 @04:50PM (#39947054)
Nothing, we can compile x*3. We can't compile x**3, because we do not have a runtime library setup for WASM yet (Flang above had the same issue) and WASM can do x**2, but arbitrary power, such as x**3, requires a runtime power function that we haven't implemented yet. If you want to help, you can fix it probably quite easily right here: https://github.com/lfortran/lfortran/blob/69d488b1d1fd26b163....
Re:Fortran on WebAssembly by selimthegrim on Friday April 05, 2024 @08:49PM (#39949002)
How about cube roots of fractions and rational numbers? (TI and Casio fans will get the deep cut)
Re:Fortran on WebAssembly by certik on Friday April 05, 2024 @09:58PM (#39949370)
The LLVM backend just does the usual floating point calculation for those.
Re:Fortran on WebAssembly by georgestagg on Friday April 05, 2024 @02:27PM (#39945498)
I’ll definitely be trying out more of LFortran in the future.

For this post I really wanted to go deeper into the approach we’ve taken with flang, but I can see that LFortran is also a very strong choice here for running Fortran on Wasm.

Re:Fortran on WebAssembly by certik on Friday April 05, 2024 @04:54PM (#39947088)
Thanks. Please report all bugs that you find. I talked to my collaborators, we'll try to get some simple demo of Fortran->LLVM->WASM working soon, we need to figure out the runtime library issue (like you did), hook it into the driver, etc. I was in fact thinking about exactly this just last week, to easily distribute my simple computational codes online via static pages.

I think exactly the approach that you took with Flang should work with LFortran also.

Re:Fortran on WebAssembly by forgotpwd16 on Friday April 05, 2024 @02:40PM (#39945618)
Grats for the amazing work! LFortran is very cool project.
Re:Fortran on WebAssembly by certik on Friday April 05, 2024 @04:55PM (#39947094)
Thank you!
Re:Fortran on WebAssembly by floxy on Friday April 05, 2024 @06:33PM (#39948097)
Wow, this looks great. Seems like there is a mini-renaissance of Fortran that I've been seeing lately. I see from the main page:

"LLVM makes it possible to run LFortran on diverse hardware and take advantage of native Fortran language constructs (such as do concurrent) on multi-core CPUs and GPUs."

...is LFortran close to using coarrays, etc, and farming it out as appropriate to the GPU cores?

Re:Fortran on WebAssembly by certik on Friday April 05, 2024 @10:05PM (#39949410)
We are progressing. We'll tackle parallel loops very soon, and get some GPU offloading working. Our main focus is still on just compiling Fortran codes via LLVM. Once we can compile most codes, we'll focus on the various other backends, including GPU, running in the browser and Jupyter.