-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Index sets and constant propagation on Array shapes #43642
Comments
Isn't the proper way to do this just to make a new |
It would defeat the purpose if it doesn't apply to a standard user code. That could be for prototyping but it doesn't solve the real issue. |
It would, at the very least let you know what the effect on compile time was. |
I believe the start of this is #43487 (although I'm not sure if it calculates total shape; it seems like it might just be |
@pchintalapudi and I were discussing this. The reason we are doing it on the LLVM level is that we didn't want to introduce a new lattice type. Effectively the specialness of |
I think particularly for TPUs
What's the downside of having a new lattice type? If we have #40992 then things like that could be explored in user-space. Is that where #42596 gets us @aviatesk ?
|
#43487 calculates and pushes individual dimensions of non-escaping array allocations as well as the overall array length to consumers of those values, in addition to a few other array struct fields (maxsize and offset for 1d arrays). There are also a couple of codegen enhancements in that PR to avoid generating any of those accesses for 2d and 3d arrays. However, all of them run after the Julia-level optimization passes and strictly operate on LLVM IR, so the PR won't help inference prior to codegen, nor will it enhance compilation of targets that don't pass through the Julia-LLVM optimization pipeline. |
This would be helpful for escape analysis:
In dex, index sets go much much further than having concrete shape information for static arrays in the type, so not just analogous to StaticArrays.jl. See more here: https://www.youtube.com/watch?v=npDCCVIaSVQ&t=2588s |
Has anyone proposed types for index sets yet? Even if |
@Tokazama Can Julia's type system can express index sets (and if it can, without heavy specialization cost)? ...Dex has a very particular design that relies on function types, sum types and the duality between memoized functions and arrays, among other things. It also does algebraic code rewriting. Check out the examples here: https://discourse.julialang.org/t/is-it-ever-logical-to-have-arrays-without-indexing-diag-a-seems-to-be-such-a-case-logical-conclusion-of-generic-programming/81471/5 In particular
also
|
I'm doing my best to understand the documentation for Dex (still not confident I'm understanding everything I read) but it really seems like what we've been working towards for a while in ArrayInterface already. The whole point of It appears Dex has stuff formally converted to index types with In summary, I think we can have robust index types and if I've correctly understood the Dex prelude and tutorial we already have the basic building blocks. We just need to fill in the gaps with some types and think about a clean user interface. |
Not Tilde so much, but MeasureTheory uses Static.jl quite a bit. I could go into this, but a lot of it is off-topic from the OP. It seems like we're basically talking about One place I see this coming up... Say I have a vector, and I want to say "give me something to hold a vector of these". If the size is known statically, I might want this represented using |
@Tokazama Great! Hopefully we can see some settling in of those ideas. By the way, if you ever have any questions, feel free to ask the Dougal or Adam. They are super responsive on twitter (https://twitter.com/apaszke https://twitter.com/DougalMaclaurin) and github discussions @cscherrer yea but I think this is far more general than sized arrays. It can express statically known or unknown sizes, statically sized named dims (with the names in the type, so type checked table ops ) , dims indexed by other arrays, static jagged, nested etc Generator type things of all of the above but expressed in the type domain. I'm not sure how they can get away without tons and tons of codegen..I think they just know more about the possible codepaths?
Exactly! Despite all this abstraction, they claim that knowing the structure in the type allows the compiler to represent all that as a dense contiguous memory region Edit: it's also not just the array shape, but the array shape is defined by the indices which are in the type |
It's not too uncommon for type computations to be determined by the size of arrays. One case is ForwardDiff chunksize computations. Another are the algorithm defaults in DifferentialEquations.jl. While these do not necessarily effect runtime performance because the computations lie behind function barriers, they seem to greatly effect compile-time performance and thus were the impetus for compile-time features such as #43370.
Such usage of max_methods=1 and function barriers could be completed eliminated if constant propagation could perform shape inference, moving chunk size computations to compile time. Even further, it has been shown that having index set information as part of the type can be very powerful for optimizations, parallelization, and automatic differentiation (https://arxiv.org/abs/2104.05372). That said, extending the type parameters of an Array would be breaking and thus require a v2.0, while adding constant propagation to array shape calculations would not necessarily be and thus I would probably be leaning towards the latter. Of course, it could be possible that shape calculations are so much more expensive that it actually hurts the compile time in that case as well.
But there's probably some other places where shape inference could help improve GC performance, make odd compilation targets easier for shape-inferable code (like static compilation), etc. so I was curious to see whether this would/could be something done as part of the language itself or whether this would be left to AbstractInterpreter plugins.
The text was updated successfully, but these errors were encountered: