-
Notifications
You must be signed in to change notification settings - Fork 19
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
Encapsulate surface conditions setting functionality so it can be reused #2855
Conversation
I have previously received unanimous feedback discouraging the use of "hat" characters like |
I guess it is not unanimous anymore! I can get rid of the hats, but I would like to use math notation for math expressions for sure. Isn't |
I got rid of the hats and use More important than the notation is the name of the functions. |
Okay, that's fine. This is not the first time I have heard complaints about Unicode. Nevertheless, it has obvious benefits. So like many choices, there are trade-offs to be considered. Note that Oceananigans makes use of plenty of Unicode, so purity requirements on the whole code base (eg the coupled modeling system) will not be possible to enforce. Generally speaking, I think it's useful to stay away from hard-to-read or hard-to-type characters in "generic" code that is meant to be read or manipulated by a lot of people, like user scripts. For the dark depths of source code, the trade-offs are different...
This function isn't specific to velocities though. Here for example it is actually used for momentum. Also I think one should use either language or math notation, but not mix the two. |
@dennisYatunin can you take a look at the latest version? I changed the names to hopefully be more "correct" --- though I think As for moving these functions to another file, I think that's ok. However, because these functions are only used in one place, I feel its not well-motivated to move them because it will make |
Working on this with @LenkaNovak and @juliasloan25 |
Names seem ok to me, as long as you're only using them in this one file. If you're planning to use them outside of this file (e.g., in ClimaEarth), it might be good to have something less generic. It's hard to do this without being too wordy, but maybe something like Also, why do you need the |
It's our experience that |
I was wrestling with the fact that these functions are not flux-specific. Ok, we'll think about it a bit more and let you know when it's ready. |
I would recommend staying away from design principles like this. In general, Julia's compiler knows what it's doing, including when it comes to inlining of LLVM code. The generation and loading of code take time, and overuse of |
I agree with your theoretical arguments and principles. It's just an immense amount of work to test the impact of every @charleskawczynski didn't you find some performance benefit when using We don't need to have this discussion here... |
@simone-silvestri can you chime in about |
Re the compiler knowing what it's doing: the broad point is that kernel code is not the typical Julia use case, so the default threshold for inlining is different than the threshold we need to apply for kernel code. We can be confident that almost all (or all) of our kernel code should be inlined? So the annotation is conservative. We do want to reduce compile time as much as possible, but we're also willing to pay some extra compile cost compared to tasks like, for example, making plots, to maximize kernel efficiency. I might be wrong about what KernelAbstractions is doing though, and that's why we need annotations extensively in Oceananigans. So if ClimaCore is specifically designed so that users can omit @inline, then perhaps the annotation is just redundant. I'm confused about the downsides cited for kernel code (memory leaks, etc). A memory leak may be a bug not directly related to @inline. Also if the cost of inlining code like what's written here is not justified by the added cost of compilation I think that is surprising. It may hint at other underlying issues. |
Regarding using For the CPU, it could help. There is a complicated entanglement between
I remember running into OOM errors due to aggressive inlining, but not memory leaks. @dennisYatunin, do you remember where this happened? We should open an issue to track if this has happened.
Yes, but this was one of the places where inlining actually broke inference, but it was likely because we weren't broadcasting types well (CliMA/ClimaCore.jl#1636). One reason inlining can help is that it can help the compiler to perform common subexpression elimination (CSE), this is particularly helpful if the elimination includes expensive operations or memory reads. These functions are small, and function call overhead on the CPU is typically cheaper than on the GPU, so I don't think it will have a big impact either way. That said, I don't have a strong preference either way, and I'd rather not put resistance on the choice/preference to use |
Also, I do agree with @dennisYatunin regarding to the variable names, thanks for updating those @glwagner. |
Here's the discussion where Simon claimed that we were seeing memory leaks from GPUCompiler: CliMA/ClimaCore.jl#1462. I've looked into the relevant unit tests with SnoopCompile, and the vast majority of compilation time is spent on codegen (which shows up as empty space in SnoopCompile flame graphs), so I assume that it's at fault here. |
Ok, yeah, I'm not sure if that was conclusive. |
Ok, I'm not fussed to remove the Oceananigans' also uses But despite that the impression has remained that this may not always be strong enough. It's an evolving issue though, I now realize. Perhaps its solved now and the |
There's a final point about CPU --- I think it's probable that we also want to always inline on the CPU. I'm not sure if there's a way to achieve that without using That said, I'm less concerned about CPU performance, provided that it remains useable for prototyping (ie 2x slowdown is probably ok, but 100x is not). |
Looking at build_history, there is not a huge change in performance, so do you guys think this is ready to be merged as is? @glwagner to fix the regression errors, I think you can just increase the number in |
ok! Where is |
here :) |
@charleskawczynski @dennisYatunin does increasing the ref counter make sense here, or is the behavioral change worrying? 🤔 |
The order of operations in the new computation of |
e2c203b
to
be55da5
Compare
be55da5
to
b7ad9ec
Compare
This small PR encapsulates some of the functionality of
atmos_surface_conditions
so that it can be used elsewhere. It also tries to introduce a bit of notation hopefully to make the code a little clearer.With @LenkaNovak and @akshaysridhar