News for hackers. Stuff that matters.
Re:Fortran on WebAssembly by droelf on Friday April 05, 2024 @01:45PM (#39945117)
Weird that it doesn't go into LFortran more, they even have an excellent online and mindblowing WASM example. https://dev.lfortran.org/
Re:Fortran on WebAssembly by andsoitis on Friday April 05, 2024 @01:51PM (#39945184)
> Weird that it doesn't go into LFortran more, they even have an excellent online and mindblowing WASM example.

They write: The LFortran compiler has made great strides over the last few years. In 2020, it was missing a lot of features and only supported a very small subset of Fortran. Now it now supports a much wider range of language features and can be used to compile a reasonable amount of Fortran code. It can even compile to WebAssembly out of the box!

However, there are still some barriers that make using LFortran a little rough. The project is currently considered to be in alpha phase and the developers state that issues compiling real-world code are expected. While it can successfully compile some projects, such as MINPACK, the full Fortran specification is not yet supported and so many larger projects still cannot be compiled.

The LFortran developers are targeting full support for Fortran 2018, and its standout feature is an interactive Jupyter-like Fortran REPL. With a few more years of development, I expect that LFortran will be an excellent choice for compiling Fortran code for WebAssembly.

and

Check out the LFortran demo at https://dev.lfortran.org. While extremely impressive, note that the first thing I tried was changing x * 2 to x * 3 and saw that such a change is currently not supported by the code generator.

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.
Re:Fortran on WebAssembly by Onavo on Friday April 05, 2024 @06:48PM (#39948210)
Also of course LPython

https://lpython.org/