Live data from Hacker News

Fortran on WebAssembly

gws.phd

41–50 of 64 posts

Re: Fortran on WebAssembly

#41
post #7

Earlier quoted context omitted.

> 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 ev…

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). H…

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

#42
post #28

I don't know whether to be impressed or horrified. Maybe both. I would recommend using top-of-tree llvm-project/main sources for building f18; we are a fast-moving project and it would be a waste of time for anybody to debug a problem that has already been fixed, or miss a feature that has already been implemented.

I was unable to understand the llvm source well enough to understand your point. Are they working on a WebAssembly port that will get their intermediate code to a point where Fortran works?

The article uses LLVM Flang from LLVM 18.1.1. pklausler's point is that it is counterproductive and LLVM HEAD should be used instead.

Re: Fortran on WebAssembly

#43
post #4

Weird that it doesn't go into LFortran more, they even have an excellent online and mindblowing WASM example. https://dev.lfortran.org/

> 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 ev…

Also of course LPython

https://lpython.org/

Re: Fortran on WebAssembly

#44
post #24

I’ve been reading these articles for years, but I’ve yet to experience any practical use of webassembly outside of contrived demos. Where do people use all this stuff? Does anyone use it?

WebAssembly is used in the real world and uses are very diverse. I recommend "An Empirical Study of Real-World WebAssembly Binaries". (The paper is from 2021, and it would be great to get an update, but I guess academia does not reward such work because it is not "novel" even if it is clearly valuable.)

https://www.software-lab.org/publications/www2021.pdf

Re: Fortran on WebAssembly

#45
post #24

I’ve been reading these articles for years, but I’ve yet to experience any practical use of webassembly outside of contrived demos. Where do people use all this stuff? Does anyone use it?

If you used Zoom on the Web then you have used WebAssembly without knowing it. The same for a long list of other stuff, big and small, from parts of Wikipedia to games to many other things.

When you use something like the Video element on the Web then it's obvious - you see a video playing - but wasm is just a technical detail that you might not notice as a user. But it often makes things faster or easier to port or to develop, and it is used quite widely (though far less widely than JavaScript, for example).

Re: Fortran on WebAssembly

#46

I worked on compiling FORTRAN at Xilinx 20 years ago. The only thing I remember is that the header file for f2c.h contains a definition of barf: /* f2c.h -- Standard Fortran to C header file / /* barf [ba:rf] 2. "He suggested using FORTRAN, and everybody barfed." ( https://www.netlib.org/clapack/f2c.h )

Does using all-caps FORTRAN say something about me? Fortran looks wrong to me.

Glad it’s not just me.

Re: Fortran on WebAssembly

#47
post #25

Earlier quoted context omitted.

Just curious but what is keeping you from compiling x*3?

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... .

How about cube roots of fractions and rational numbers? (TI and Casio fans will get the deep cut)

Re: Fortran on WebAssembly

#48
post #25

Earlier quoted context omitted.

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... .

How about cube roots of fractions and rational numbers? (TI and Casio fans will get the deep cut)

The LLVM backend just does the usual floating point calculation for those.

Re: Fortran on WebAssembly

#49
post #41
post #7

Earlier quoted context omitted.

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). H…

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?

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

#50
post #42
post #28

Earlier quoted context omitted.

I was unable to understand the llvm source well enough to understand your point. Are they working on a WebAssembly port that will get their intermediate code to a point where Fortran works?

The article uses LLVM Flang from LLVM 18.1.1. pklausler's point is that it is counterproductive and LLVM HEAD should be used instead.

I’m trying to understand why though
Post reply on HN