-
Notifications
You must be signed in to change notification settings - Fork 195
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
Defines many identity's to avoid recursion when compiling AbstractOperations #1595
Conversation
Awesome! Hopefully. If I may ask, what's the rationale, here? Sorry but I didn't understand the changes very much... |
More or less the problem is that we can't pipe a computation recursively through
|
All of that said I'm not sure it works. Trying to figure that out. The fact that tests pass is good (at least the changes didn't break anything). |
Close but no cigar I think because I was wrong about how closures work: using Oceananigans
using Oceananigans.AbstractOperations
using Oceananigans.Fields
grid = RegularRectilinearGrid(size=(1, 1, 1), extent=(1, 1, 1))
model = IncompressibleModel(architecture=GPU(), grid=grid)
u, v, w = model.velocities
op = u + v - w but julia> op.a.▶op === op.▶op
true in other words, the I think we are close though... might just need some |
Things like this work now... julia> op = u + v - w
julia> compute!(ComputedField(op)) There's a lot of julia> op = u + v - w
BinaryOperation at (Face, Center, Center)
├── grid: RegularRectilinearGrid{Float64, Periodic, Periodic, Bounded}(Nx=1, Ny=1, Nz=1)
│ └── domain: x ∈ [0.0, 1.0], y ∈ [0.0, 1.0], z ∈ [-1.0, 0.0]
└── tree:
- at (Face, Center, Center) via identity6
├── + at (Face, Center, Center) via identity3
│ ├── Field located at (Face, Center, Center)
│ └── Field located at (Center, Face, Center)
└── Field located at (Center, Center, Face) |
Thanks for the explanation. I'm kinda lost (especially with the last commit haha) but paying attention and crossing my fingers 👍 |
If you have specific questions I would love to answer them! |
It looks like this PR fixes some issues with complex AbstractOperations, but it does not allow us to use AveragedField on the GPU. I think a possible avenue to explore could maybe be to Adapt an AveragedField by wrapping the underlying, |
Thanks, @glwagner, that's awesome news! Just for clarity, what issues does it fix? Can we now calculate |
This PR defines multiple, identical functions called The interpolation operator is selected by a function This solves a specific problem that we speculated was plaguing abstract operations on #1241 (and proposed as a solution there). Specifically, abstraction operations that failed to compile due to a recursive call to This hack doesn't allow us to execute arbitrarily complex abstract operations on the GPU. I don't think we can guarantee execution of arbitrary code in general. In this case, there are other issues that compiler might encounter that are not related to recursive calls to There may be other problems that we haven't uncovered. An important additional case that doesn't work right now is operations that have embedded But this idealization doesn't hold for Oceananigans.jl/src/Fields/averaged_field.jl Lines 94 to 96 in 98cd4f7
Peeking at the broadcasting code used by julia Base gives a hint. Broadcasting has to solve the same problem: we have to be able to make computations between arrays of size (Nx, Ny, 1) and (Nx, Ny, Nz), for example. In this case, the indices of the first array are "extruded" into the third dimension. There are some shenanigans in |
Alright, thanks, that makes a lot of sense! Very nice explanation. So, if I understand correctly, in practical terms the result of this PR is that some abstract operations that didn't compile before (the ones where recursive calls to |
Yes, I think so. I didn't test many, but I did confirm that The error we were previously receiving was "dynamic function invocation error". This is often a type inference problem: if the julia compiler cannot infer types probably, then the resulting julia code cannot be translated into CUDA. Thus the kernel still contains "dynamic julia functions". This is the same error we get when trying to compile operations containing We received other independent errors from seemingly more complicated operations such as "device kernel image is invalid", and "entry function uses too much parameter space". I think solving these might require contributions / modifications to |
This might resolve #1241 ...
cc @ali-ramadhan @tomchor