7 ms·
Lfortran: Modern interactive LLVM-based Fortran compiler
- gcr 3y agoI misread LLVM as LLM and wondered what on earth language models have to do with Fortran compilation. (They don't. LLVM is a compiler framework.) Anyways, great work to the team! It's fun to see such a flurry of articles from the Fortran community today
- certik 3y agoThanks! I know, LLM came much later after LLVM. But if you are interested in LLM that LFortran can compile, check out: https://github.com/certik/fastGPT/ https://github.com/certik/fastGPT/.
- csjh 3y agoWould be cool for there to be a `llama2.f`, like https://github.com/karpathy/llama2.c https://github.com/karpathy/llama2.c, to demo its capabilities
- certik 3y agoYes indeed, we'll do it next (unless somebody beats me to it). First I am focusing on compiling fastGPT with LFortran, we can do it, but have a few workarounds that I want to fix. Then we'll do llama2.
- Alifatisk 3y ago> I misread LLVM as LLM and wondered what on earth language models have to do with Fortran compilation. You gave me a good laugh this evening!
- certik 3y agoTurns out Fortran is a great fit for LLM, I am not joking: https://github.com/certik/fastGPT/ https://github.com/certik/fastGPT/.
- Conscat 3y agoI was talking to someone on Grinder yesterday who made the same mistake. I wonder how common it is to misread "LLVM" as "LLM".
- ruste 3y agoThis is probably fantastic from a maintainability perspective, but I'm curious if some performance is left on the table by using LLVM IR instead of compiling directly to machine code. I know there are a number of optimizations that can be made for Fortran that can't be made for C-like languages and I wonder if some of those C-like assumptions are implicitly encoded in the IR.
- tombert 3y agoAs someone who's only played with Fortran, and never done anything too serious with it, can you explain an optimization that can be done in Fortran that can't be done in a C-like language? I'm not being argumentative, I'm actually really curious.
- jcranmer 3y agoFortran has true multidimensional arrays in a way that C doesn't have--if you know an array is 5x3, you know that A[6, 1] doesn't map to a valid element whereas in C, it does map to a valid element. This turns out to make a lot of loop optimizations easier. (Also, being Fortran, you tend to pass around arrays with size information anyways, which C doesn't do, since you typically just get pointers with C).
- WanderPanda 3y agoIs the size info compile-time or runtime in Fortran?
- certik 3y agoIt can be both. If you know the dimension at compile time, it is compile time, if you don't it will be runtime.
- bogeholm 3y agoHere’s a link to a StackOverflow answer that gives a good example: “Is Fortran easier to optimize than C for heavy calculations?” [0] [0]: https://stackoverflow.com/questions/146159/is-fortran-easier-to-optimize-than-c-for-heavy-calculations#146186 https://stackoverflow.com/questions/146159/is-fortran-easier...
- fanf2 3y agoI wanted to see a comparison with flang, which I thought is the main LLVM Fortran front end.
- certik 3y agoI am the original author of LFortran. What kind of comparison would you like to see? If you have any specific questions, I am happy to answer.
- fanf2 3y agoWhat are the relative strengths and weaknesses? If LFortran is newer, what problems with flang does it aim to address? How should someone choose between them, and how does the decision process change in different circumstances?
- certik 3y agoThere is old Flang, which motivated me to start LFortran. The new Flang, which presumably you are referring to, started possibly in the same month as LFortran, but we didn't know about each other. It's best if you ask Flang developers what they see as the advantages of Flang over LFortran. From my biased perspective, LFortran can run interactively, it is fast to compile the compiler (30s on my laptop) and LFortran compiles your code very quickly (especially with our direct x64 or C backends). It runs in a browser: https://dev.lfortran.org/ https://dev.lfortran.org/. We have many backends (LLVM, C, C++, Julia, WASM, x64). We plan to add Python and Fortran (the latter could be used to modernize your old Fortran code). It is easy to add new backends, and it is also easy to add new frontends, so we have LPython and LFortran as two thin frontends, to our intermediate representation that we call ASR (Abstract Semantic Representation). The internal design is simple, so a small team can develop LCompilers at a fast pace. New contributors without any prior compiler experience get up to speed very quickly (typically a few weeks or even less). We are still in alpha, which means it is expected to break for your code (and when it does, please report all bugs!). To choose between them, I recommend to test them out and pick the one that you like the most, based on your criteria. Note that the most mature and widespread open source Fortran compiler is GFortran.
- sakras 3y agoHow does this compiler compare with Flang? I saw it shouted out on the main page but didn't really see any comparisons for why you'd pick one or the other.
- certik 3y agoIt's hard to have a fair comparison, and both compilers are also moving targets. I tried to do some comparison in a sibling comment: https://news.ycombinator.com/item?id=37300279 https://news.ycombinator.com/item?id=37300279 The best is to mention both (as well as GFortran), and users can decide. For LPython (https://lpython.org/ https://lpython.org/) we list all of the about 30 Python compilers at the webpage, but beyond that it's very hard to have a meaningful comparison.
- slavapestov 3y ago> LFortran is structured around two independent modules, AST (Abstract Syntax Tree) and ASR (Abstract Semantic Representation), both of which are standalone (completely independent of the rest of LFortran) and users are encouraged to use them independently for other applications and build tools on top. Modern frontend architecture comes to Fortran! Awesome.
- pseudosavant 3y agoWas I the only one hoping that Lfortran was something for music synthesis (LFOs...) using Fortran? I can't not see LFO - like that keming joke.
- dang 3y agoRelated ongoing thread: Fortran - https://news.ycombinator.com/item?id=37291504 https://news.ycombinator.com/item?id=37291504 - Aug 2023 (193 comments) (current thread is better because less generic)
- cjohnson318 3y agoIs this the same outfit that did LPython? It looks like the same/similar web design.
- certik 3y agoYes, both LPython and LFortran are our two thin frontends to ASR (Abstract Semantic Representation). Not just the website is reused, but the internals are reused, so LPython runs your code at exactly the same speed as LFortran would, since ASR and all optimizations and backends are shared.
- cjohnson318 3y agoCool cool cool, I just wanted to make sure I wasn't hallucinating. I'll try out a Hello World!
- certik 3y agoAwesome! Report all bugs. :)
- cjohnson318 3y ago10-4 boss.
- KingLancelot 3y ago[dead]
- throw10920 3y agoIt's a little bit embarrassing that a Fortran compiler provides a shell for interactive use, yet the Rust project, with at least two orders of magnitude more development effort, does not.
- certik 3y agoLFortran error messages style got inspired by Rust, and the Fortran Package Manager got inspired by Cargo. And in return Rust can get inspired by LFortran to do the interactive prompt. :) In all seriousness though, Rust got many things right and showed how a modern language, compiler and a package manager should behave. I think it genuinely moved the state-of-the-art. And we are trying hard to improve on the state-of-the-art as well. I think a modern compiler should compile fast in Debug mode, and generate high performance code in Release mode. And it should compile to a binary as well as work interactively. Etc.
- Vecr 3y agoRust used to have an interactive prompt of sorts with MIRI, I'm not sure if that's still possible. I don't think I've heard anyone talk about it for 5 years.
- 1vuio0pswjnm7 3y agoWhen installing clang I am amazed at the size of some of the LLVM shared libraries. Gigantic.
- j_not_j 3y agoIs/will OpenMP be supported?