9 ms·
Fortran on WebAssembly
- Olesya000 2y ago[dead]
- math_dandy 2y agoI love the "simplest nontrivial example" approach to exposition. I think I learned a lot from the article because it was grounded in the concrete problem "call a BLAS function from Javascript". Great post!
- georgestagg 2y agoThanks! There’s a series of books I really like, The Theoretical Minimum[1], that also takes that kind of approach but for teaching physics. [1] https://en.m.wikipedia.org/wiki/The_Theoretical_Minimum https://en.m.wikipedia.org/wiki/The_Theoretical_Minimum
- certik 2y agoYes, I also like The Theoretical Minimum. Ha, I didn't realize there is more than one book! I think I only have the classical mechanics book. Need to buy the other ones. I tried to organize many physics subjects in a similar manner, with many worked out examples (minimal, but non-trivial/complete): https://www.theoretical-physics.com/dev/index.html https://www.theoretical-physics.com/dev/index.html
- droelf 2y agoWeird that it doesn't go into LFortran more, they even have an excellent online and mindblowing WASM example. https://dev.lfortran.org/ https://dev.lfortran.org/
- andsoitis 2y ago> 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 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.
- Onavo 2y agoAlso of course LPython https://lpython.org/ https://lpython.org/
- certik 2y agoThe author of LFortran here. The demo at https://dev.lfortran.org 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!
- georgestagg 2y ago
- pklausler 2y agoI 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.
- tomcam 2y agoI 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?
- pklausler 2y agoI meant that we are actively developing a new implementation of the Fortran language itself here. We are still adding features and fixing bugs. Fortran code that compiles and runs today with llvm-project/main HEAD may well not compile or not run with older release branches.
- sanxiyn 2y agoThe article uses LLVM Flang from LLVM 18.1.1. pklausler's point is that it is counterproductive and LLVM HEAD should be used instead.
- tomcam 2y agoI’m trying to understand why though
- pjmlp 2y agoFortran on .NET and Java, https://www.silverfrost.com/14/ftn95/ftn95_fortran_95_for_microsoft_dotnet_features.aspx https://www.silverfrost.com/14/ftn95/ftn95_fortran_95_for_mi... https://dl.acm.org/doi/10.1145/376656.376833 https://dl.acm.org/doi/10.1145/376656.376833
- coldcode 2y agoI wish I had kept my Fortran 78 code from 1981/82 to see if I could get it to run on this. It was a Jovial programming language source code formatter. Not exactly what you should use Fortran for, but that's the only choice I had.
- tomcam 2y agoDid you work at Hughes in Orange County?
- wch 2y agoA little context: this dive into Fortran is part of the excellent work George has been doing on WebR, to get R running in the browser. The R sources contain a fair bit of Fortran code, and I believe WebR originally used f2c to compile the Fortran to C first, before compiling that to wasm. With the patches to LLVM Flang, WebR can be built with a real Fortran compiler. I think George didn't want to say it directly in the blog post, but he has said that he's hoping that Flang would take his patches or implement better ones. That would be a win-win -- these patches wouldn't need to be maintained separately, and since unmodified Flang would be able to compile to wasm, it would benefit other projects out there that use Fortran. https://docs.r-wasm.org/webr/latest/ https://docs.r-wasm.org/webr/latest/
- pklausler 2y agoPull requests are always welcome (https://github.com/llvm/llvm-project https://github.com/llvm/llvm-project), and one can contact the general LLVM Fortran development community (https://discourse.llvm.org/c/subprojects/flang/33 https://discourse.llvm.org/c/subprojects/flang/33) for help. I am focused on things needed to complete development for Nvidia's Fortran product and don't have any time left for things like this, myself.
- QuantumG 2y agoSource to source, F77 to JavaScript is already pretty good but WASM is better.
- 0cf8612b2e1e 2y agoI am pretty ignorant of Web Assembly development. Does Web Assembly have anything to offer me today as a consumer? Or is all of this still setting the groundwork for a future where programs are truly portable? I have heard some rumblings that the WA machinery makes it easier to restrict access (network, files) but I do not know if those are theoretical or implemented today.
- kevingadd 2y agoAs a developer or someone shipping products, if you want robust sandboxing, WASM is probably the best option available to you right now. And there are ways to deploy it or cross-compile it for most targets.
- ngcc_hk 2y agoAny good pointer to this direction?
- kevingadd 2y agohttps://github.com/WebAssembly/wabt/blob/main/wasm2c/README.md https://github.com/WebAssembly/wabt/blob/main/wasm2c/README.... is a straightforward way to take an untrusted application (compiled already to wasm) and turn it into C that you can embed into your application or compile to a linkable DLL. I believe this approach has been used to sandbox untrusted libraries in production by Mozilla: https://hacks.mozilla.org/2021/12/webassembly-and-back-again-fine-grained-sandboxing-in-firefox-95/ https://hacks.mozilla.org/2021/12/webassembly-and-back-again...
- norman784 2y agoBasically Wasm is a virtual machine, is is very similar to JVM that is portable, but the key difference is that Wasm does not have any std nor expose any IO function, so you can build your own host (the VM) that expose functions that can be imported from the Wasm binary, that means that the Wasm binary can have access to the external world only through these functions. Also I would say an advantage is that the binary format is not proprietary and there's a spec, so anyone could implement their own Wasm VM. But right now is not in a good place yet, is too early and there are a lot of new functionality that is being standardized by a group (similar to W3C) and the process is very slow.
- ur-whale 2y agoThe translator gets translated.
- bighoki2885000 2y ago[dead]
- tomasreimers 2y agoI remember when I was working on https://medium.com/@tomasreimers/compiling-tensorflow-for-the-browser-f3387b8e1e1c https://medium.com/@tomasreimers/compiling-tensorflow-for-th... I thanked my lucky stars that TF used Eigen and not one of the popular math libraries (BLAS, Lapack) written in fortran b/c that would have been A LOT more work...
- mhh__ 2y agoIs there a somewhat "production"-ready ecosystem for linear algebra in javascript? Upon googling I often find some ~decade old port of one of the old familiars to javascript (e.g. via emscripten), wondering if I'm missing something.
- KRAKRISMOTT 2y agoDo we have a BLAS equivalent on WebGPU or WebNN?
- ein0p 2y agoI’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?
- rad_gruchalski 2y agoEnvoy proxy uses wasm filters, thus Istio uses wasm filters. Everyone who uses Istio in non-ambient-mesh uses them. They can write their own in a language of their choice.
- csjh 2y agoCloudflare workers use them for portability/v8 isolate compatibility/speed/isolation, Figma uses for the main editor, a bunch of Web3 stuff uses them for ???
- georgestagg 2y agoWebAssembly is generally most useful when you want to write high performance web applications using languages like C, C++ or Rust. WebAssembly sits in the background quietly powering the web-based versions of products like Adobe Photoshop, AutoCAD, Figma, Canva, and likely others. By using Wasm components combined with other browser technologies such as HTML canvas and webGL, app performance and responsiveness can be improved. WebAssembly also powers the Pyodide and webR projects, enabling Python and R code to run in a browser without a supporting computational server. Where I’ve seen this used most effectively so far is in teaching materials, particularly for teaching data science, where interactive R and Python examples can be embedded directly into teaching materials without the educator having to worry about the time or expense to deploy a powerful backend service to evaluate learner’s code.
- homerowilson 2y agoAs an educator, one great use for me is classroom use. Students can run R/Python/Fortran in the browser on any OS without installing any software: https://docs.r-wasm.org/webr/latest/ https://docs.r-wasm.org/webr/latest/ https://github.com/jupyterlite/jupyterlite https://github.com/jupyterlite/jupyterlite https://dev.lfortran.org/ https://dev.lfortran.org/ There are rough edges to be sure, but the potential is great in education I think.
- amirhirsch 2y agoI 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 https://www.netlib.org/clapack/f2c.h)
- amirhirsch 2y agoDoes using all-caps FORTRAN say something about me? Fortran looks wrong to me.
- bighoki2885000 2y ago[dead]
- bighoki2885000 2y ago[dead]
- bighoki2885000 2y ago[dead]
- bighoki2885000 2y ago[dead]
- bighoki2885000 2y ago[dead]
- bighoki2885000 2y ago[dead]
- bighoki2885000 2y ago[dead]
- bighoki2885000 2y ago[dead]
- bighoki2885000 2y ago[dead]
- bighoki2885000 2y ago[dead]