Comments (9)
Definitely. @chelini is also helping look at this so looping him in. There's two approaches for doing this and its unclear which is better (each with separate set of tradeoffs).
The first approach is to modify the for loop parser (https://github.com/wsmoses/MLIR-GPU/blob/97527f81df6aab1120036572e2c727c0892e7ef3/mlir/tools/mlir-clang/Lib/clang-mlir.cc#L313) to recognize scop markings and assume all relevant loads are affine / etc.
The second approach is to lower all the code in a generic way (e.g. lower for as is right now), then in MLIR recognize that the operations are affine. Last week I finished mem2reg (ensuring all induction variables are nicely represented/etc) and started importing the "deduce structured loops from CFG loop" (https://github.com/wsmoses/MLIR-GPU/blob/71aa0d71b3e10403f01d9b005cff5200cb63f8fc/mlir/lib/Transforms/LoopRestructure.cpp#L92). It now needs to generate the corresponding MLIR out of the deduced loop.
First approach lets the compiler make assumptions about input code that might not otherwise be available, whereas the latter approach could automatically deduce affine out of generic unmarked code, proving it legal.
@chelini has started looking at the first approach so to avoid duplicated work, would you be interested in looking at the second? If not we can subdivide the first approach.
Also quick update the current (non-affine) parsing is able to parse the polybench tests I've tried and half of GPU rodinia codes (of course emitting non-affine but generic MLIR).
Also cc'ing @ftynse
from polygeist.
Hi Billy @wsmoses , this is related to what I want to have in the C-to-mlir tool, maybe I could help with this.
If I understand correctly, this issue is about parsing C code into MLIR Affine if possible. If so, the first step possibly could be locating #pragma scop
in the code and then try to translate its contents into Affine. Pls let me know if you have any suggestions :)
from polygeist.
Thank you @wsmoses for your explanation :)
Since the first approach is under development, maybe it is better to leave it to @chelini . I would be happy to help with any testing involved.
For the second approach, I think it indeed sounds better for the future. I could help with this, and the LoopRestruture
pass you mentioned seems to be a good start. If I understand correctly, this pass helps finding loop strutures, and the thing to do is to check whether a found loop satisfies affine constraints. It won't be very difficult to check every loop bound and load/store operation to see if it uses affine expressions. I think we could borrow some ideas from Polly as well: https://polly.llvm.org/doxygen/ScopDetection_8cpp_source.html
I need to finish settling imperfectly nested loop first in my project (kumasento/polymer#5) and then I will get back to helping with this.
from polygeist.
Sounds good to me! Let me know when you're able and we can chat more about the intricacies of option 2.
from polygeist.
cc'ing @vchuravy here since he mentioned potentially needing raising pass for Julia-MLIR
from polygeist.
Would be happy enough with a Std->SCF
pass, like the one we prototyped ages ago. x-ef: https://llvm.discourse.group/t/rfc-working-with-cfg-loops/564?u=vchuravy
from polygeist.
More than likely, I imagine it will be easier and best implemented as Blocks => SCF, and then a SCF=> Affine.
from polygeist.
More than likely, I imagine it will be easier and best implemented as Blocks => SCF, and then a SCF=> Affine.
I reckon it is indeed natural to raise to SCF first and then Affine. Thank you for pointing this out :)
from polygeist.
This is now mostly done, with the exception of raising to affine.for (currently we piggyback on emitting affine.for in scop). Raising affine.if, load, store, etc is done however!
from polygeist.
Related Issues (20)
- [BUG] type-related(size_t or int) crash in simple matrix multiply example
- Add ISL support for polymer HOT 4
- Cgeist outputs something strange HOT 6
- How to run PolyBench/C benchmarks with polyhedral pluto optimization using Polygeist? HOT 3
- [Bug] Incorrect scf.for code is generated
- Sign extension not properly propagated to users HOT 2
- declared char constants emit higher bit-width MLIR constants HOT 3
- linker error with cgeist on C++ code HOT 2
- make[1]: *** No rule to make target 'install'. Stop. make: *** [Makefile:555: install-recursive] Error 1 CMake Error at tools/polymer/CMakeLists.txt:28 (execute_process): execute_process failed command indexes: 1: "Child return code: 2" HOT 1
- support for Cuda 12.1 HOT 11
- Incorrect execution result of running CUDA to OpenMP compilation? HOT 1
- Error compiling code with Polygeist: 'affine.for' op operand cannot be used as a symbol
- [bug] Operations such as "|=", "&=" and "^=" lack necessary implicit type conversions
- opaque attribute handling issues
- error when trying to lower .cu file, should I report this here or on LLVM repo issues?
- Problems about fp_16 in CUDA, as half, __hmul.......etc HOT 1
- Is it possible to take MLIR generated by CUDA-to-CPU flow to the cpu-openmp executable? HOT 1
- Add Support for Additional Math Operations in Polygeist
- gitignore bug
- Polymer with -reg2mem -pluto-opt generates IR with out-of-bounds accesses for imperfectly nested loops
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from polygeist.