-
Notifications
You must be signed in to change notification settings - Fork 40
Pack on virtual fields #1322
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
base: develop
Are you sure you want to change the base?
Pack on virtual fields #1322
Conversation
Yurlungur
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is very cool and I like it a lot. It definitely needs a bit of documentation though. Though I suppose we also don't have documentation for type-based variables, which is sorely needed...
src/pack/pack_utils.hpp
Outdated
| template <typename T, int... tuv> | ||
| struct TUV_t<T, tuv...> : impl::TUV_t<T, TopologicalElement::CC, tuv...> {}; | ||
|
|
||
| template <typename T, TopologicalElement te, int... tuv> | ||
| struct TUV_t<T, te, tuv...> : impl::TUV_t<T, te, tuv...> {}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
with the variadics is this going to get correctly resolved?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think so, since the TE & ints are different types. Happy to add some static asserts like this to the unit tests to demonstrate. Unless there is a different edge case you're thinking of?
| // Concept to state that a typed-field is dependent on other | ||
| // fields, and is not itself an actual indexable field. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should the concepts stuff be in concepts_lite or should it be here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seemed specialized enough to the pack types that I put it here, but if the convention is to have all concepts in concepts_lite I'm happy to move it
| template <typename, typename, typename...> | ||
| struct UnionTypeLists {}; | ||
|
|
||
| template <typename... Ts> | ||
| struct UnionTypeLists<TypeList<Ts...>, TypeList<>> { | ||
| using type = TypeList<Ts...>; | ||
| }; | ||
|
|
||
| template <typename... Ts, typename V, typename... Vs> | ||
| struct UnionTypeLists<TypeList<Ts...>, TypeList<V, Vs...>> { | ||
| using TL = TypeList<Ts...>; | ||
| using type = std::conditional_t< | ||
| TL::template IsIn<V>(), TL, | ||
| typename UnionTypeLists<TypeList<Ts..., V>, TypeList<Vs...>>::type>; | ||
| }; | ||
|
|
||
| template <typename T, typename U, typename V, typename... Args> | ||
| struct UnionTypeLists<T, U, V, Args...> { | ||
| using type = typename UnionTypeLists<typename UnionTypeLists<T, U>::type, V>::type; | ||
| }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm surprised there isn't functionality for this in the standard
src/pack/pack_utils.hpp
Outdated
| // Get a TypeList of all the non-dependent variables that make up the requested types. | ||
| template <typename... Ts> | ||
| using all_dependent_variables_t = decltype(impl::AllDependentVariables::get(Ts()...)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The name and the comment disagree. Is this all dependent variables or all independent variables?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The types should be renamed. It is all the independent variables pulled out from the dependent variables
|
Also changelog and mark non-wip :) |
Happy to add both in this PR. |
|
This is very cool! I am wondering though about how complex the template stuff needs to be. Why can't we just do something like class my_derived_var_t : public variable_names::dependent_var_base_t<...> {
...
template <class pack_t>
KOKKOS_INLINE_FUNCTION
Real evaluate(const pack_t &pack, int b, TopologicalElemet te, int k, int j, int i) {
return pack(b, var1_t(), te, k, j, i) + pack(b, var2_t(), te, k, j, i);
}
};and template <class TIn, REQUIRES(IncludesType<TIn, Ts...>::value && std::is_base_of_v<dependent_var_base_t, TIn>)>
KOKKOS_INLINE_FUNCTION Real operator()(const int b, const TE el, const TIn &t,
const int k, const int j, const int i) const {
return t.evaluate(*this, b, te, k, j, i);
}I think there are obviously some circular dependencies that could crop up here (e.g. |
That is much simpler and I think would work just fine. My thought was that it would be nice to make it easy to unit test the |
|
I just got the chance to look at this PR. Quite of few of our targeted use cases would involve either stencil based ops and/or other information (say an adiabatic index). How big of a lift do you think this would be (asking from the point of view whether we should get this interface in as is [pending review comments] or spend "just a little" more time on getting a more flexible version in first place). |
I think luke's suggestion would be pretty easy to implement and would be a better starting place for this kind of feature. |
2786e1e to
b071c5a
Compare
PR Summary
This PR allows for type-based packs to pack "virtual" fields that don't exist in memory, but can be evaluated from their own set of dependent variables in the pack by calling a provided
evaluatefunction.This seems related to #1228, but doesn't provide that capability for outputs as mentioned for ADIOS2.
Also adds
SubPacksto provide stencil (0, 1, 2, & 3D) views into a pack centered on a meshblock and ijk index. This can simplify the need to pass around extra indices in theevaluatefunctions for virtual fields.PR Checklist