-
Notifications
You must be signed in to change notification settings - Fork 32
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
WIP: Piecewise cubic monotone interpolation #874
base: develop
Are you sure you want to change the base?
WIP: Piecewise cubic monotone interpolation #874
Conversation
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 neat! Two quick thoughts now (mostly because I saw the include guard and got to thinking about that more generally)
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 this is useful overall... I assuem a fleshed out PR would have tests. My one big concern is you show using it for both std::vector
and a kokkos view... those types have different kinds of semantics: vectors are value semantics and views reference semantics. I worry that could get one in to trouble... but maybe it's fine.
private: | ||
Real x_min_{}; | ||
Real x_max_{}; // x_min and x_max are the min and max of x_vec_ | ||
VectorContainer x_vec_{}; |
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.
Are these assumed to have reference semantics?
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 don't think so... Can you provide an example of how this could cause trouble?
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.
you're constructing x_vec_
by copy when you call the interpolator, so you're copying around the data unless VectorContainer
has refernece semantics. That may be a feature or a bug. If VectoContainer
is always a Kokkos::View
, then we're fine though.
// to avoid branchy code, do a linear search for the segment I_i | ||
// where x_{i} <= x < x_{i+1}. |
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.
Linear search seems like a bad idea IMO. Probably better to just branch.
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 can replace this with a binary search.
src/utils/interpolate.hpp
Outdated
template <> | ||
auto MonotoneInterpolator<PinnedArray1D<Real>>::ConstructVectorContainer(size_t size) | ||
-> PinnedArray1D<Real> { | ||
return PinnedArray1D<Real>("d", size); | ||
} |
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 wonder if this can be generalized using @lroberts36 concepts so all view types could be specialized for at once.
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.
That would definitely be nice to have.
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.
Currently PinnedArray1D
is a typedef for SharedHostPinnedSpace
in Kokkos 4, so this adds a requirement for Kokkos 4 if we have to explicitly specialize for common vector containers/views.
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 this should just work, but Luke should comment
template<typename VectorContainer, class = ENABLEIF(implements<kokkos_view(VectorContainer)>::value)>
auto MonotoneInterpolator<VectorContainer>::ConstructVectorContainer(size_t size) {
return VectorContainer("d", size);
}
you'll need to include utils/concepts_lite.hpp
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 that should work, but it is probably more consistent to use REQUIRES
instead
template<typename VectorContainer, REQUIRES(implements<kokkos_view(VectorContainer)>::value)>
auto MonotoneInterpolator<VectorContainer>::ConstructVectorContainer(size_t size) {
return VectorContainer("d", size);
}
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 can't get this to compile on my machine. I don't fully understand concepts, so I'm not sure why it's complaining:
/Users/benwibking/parthenon/src/utils/interpolate.hpp:54:45: error: nested name specifier 'MonotoneInterpolator<VectorContainer>::' for declaration does not refer into a class, class template or class template partial specialization
auto MonotoneInterpolator<VectorContainer>::ConstructVectorContainer(size_t size) {
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@Yurlungur Yes, planning to add tests. |
Co-authored-by: Jonah Miller <DrLoco3000@gmail.com>
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.
Tests look good, but it would be good to also test on device if you plan to use this tool on GPUs.
private: | ||
Real x_min_{}; | ||
Real x_max_{}; // x_min and x_max are the min and max of x_vec_ | ||
VectorContainer x_vec_{}; |
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.
you're constructing x_vec_
by copy when you call the interpolator, so you're copying around the data unless VectorContainer
has refernece semantics. That may be a feature or a bug. If VectoContainer
is always a Kokkos::View
, then we're fine though.
PR Summary
Adds monotone interpolation using cubic Hermite polynomials that can be used on device. However, the
MonotoneInterpolator
itself must be constructed on the host, with the contents of the views passed to it accessible from both host and device (if used).This depends on Kokkos 4 support in order to use
SharedHostPinnedSpace
(kokkos/kokkos#5405).Reference: "Monotone piecewise cubic interpolation," SIAM J. Numer. Anal., Vol. 17, No. 2, April 1980. https://doi.org/10.1137/0717021
PR Checklist