-
Notifications
You must be signed in to change notification settings - Fork 31
Interpolate Current #437
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: master
Are you sure you want to change the base?
Interpolate Current #437
Conversation
|
|
||
| static KOKKOS_INLINE_FUNCTION | ||
| std::array<Segment<Dim,T>, Dim+1> | ||
| split(const ippl::Vector<T, Dim>& A, |
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.
Isn't here the templates of GridPathSegmenter missing?
Shouldn't it be
GridPathSegmenter<Dim,T,Rule>::split(
instead?
In the implementation .hpp file, you have
template<unsigned Dim, typename T, typename Rule>
KOKKOS_INLINE_FUNCTION
std::array<Segment<Dim,T>, Dim+1>
GridPathSegmenter<Dim,T,Rule>::split(
|
|
||
| template<typename T> | ||
| KOKKOS_INLINE_FUNCTION | ||
| void sort2(T& a, T& b) { if (a > b) { T t=a; a=b; b=t; } } |
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.
would it make sense to allow compile-time evaluation with constexpr? same for sort3, and lerp_point?
| void make_endpoints_fixed(const CutTimes<Dim,T>& cuts, | ||
| std::array<T,Dim+2>& Tcuts /*out*/) | ||
| { | ||
| T t0 = cuts.t[0]; |
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.
what if Dim==1? If that's never the case, then consider having a check. Because with Dim=1, I think the else in line 82 would be out of bound.
| const NedelecSpace& space, | ||
| policy_type iteration_policy) | ||
| { | ||
| using T = Mesh::value_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.
Shouldn't it be?
using T = typename Mesh::value_type;
| const auto h = mesh.getMeshSpacing(); | ||
| constexpr unsigned Dim = Mesh::Dimension; | ||
|
|
||
| Kokkos::parallel_for("assemble_current_whitney1_make_segments", iteration_policy, |
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 we sure that h, origin, etc used in the Kokkos loop are not references to host-only memory?
Also, there are too many empty lines here somehow.
|
|
||
| template<unsigned Dim, typename T> | ||
| struct Segment { | ||
| ippl::Vector<T,Dim> p0, p1; |
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.
Since you're in namespace ippl, you don't need to specify ippl:: each time for the Vector<T,Dim> type. Comment applies to all instances of this in the file.
| f(std::integral_constant<int, I>{}); | ||
| static_for<I+1, End>(std::forward<F>(f)); |
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.
Will these std:: functions work on GPU? Or does it not matter since it's marked constexpr?
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 also don't think that standard C++'s STL, <cmath>, <algorithm>, etc run on the GPUs, unless proven otherwise :) One has to be very careful, and double check CUDA's manual for each of them.
I see your point on constexpr, that it pushes the compiler to compute the expressions on the host at compile time, and therefore does not compute it on GPU, so it may not cause any problem as it is not deployed on the GPU. But is that for sure? I see comments saying that expressions marked with constexpr maybe are computed at compile time depending on compiler being able to find all the known values at the compiled time or not. Otherwise, it is a runtime calculation regardless of having constexpr.
If this code is supposed to run on the host only, then why do we have KOKKOS_INLINE_FUNCTION?
|
|
||
| // ---------- per-axis cut times (for DefaultCellCrossingRule) ---------- | ||
| template<unsigned Dim, typename T> | ||
| struct CutTimes { std::array<T,Dim> t; }; |
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.
Is this array only going to be accessed on host? I don't think std::array is accessible within Kokkos kernels on device. One would need to use: https://kokkos.org/kokkos-core-wiki/API/core/stl-compat/Array.html, or ippl Vectors.
| const ippl::Vector<T,Dim>& A, | ||
| const ippl::Vector<T,Dim>& B, | ||
| const ippl::Vector<T,Dim>& origin, | ||
| const ippl::Vector<T,Dim>& h) |
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.
again, since we are in the ippl namespace, no need for ippl::
|
|
||
| auto axis_cut = [&](auto Ax) { | ||
| constexpr int a = Ax; | ||
| const T d = B[a] - A[a]; |
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.
Maybe rename d to dist to avoid confusion with d = Dim (which is the case in many places in ippl)?
|
|
||
| const T nA = (A[a] - origin[a]) / h[a]; // in cell units | ||
| // nearest plane index in direction toward B; bias off-plane a hair | ||
| const T k = (d > 0) ? std::ceil(nA - eps1) : std::floor(nA + eps1); |
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.
std::ceil and std::floor should be replaced by Kokkos::ceil and Kokkos::floor.
| const T pa = origin[a] + k * h[a]; | ||
| const T t = (pa - A[a]) / d; | ||
|
|
||
| if (t > eps1 && t < one - eps1) cuts.t[a] = t; |
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.
add a comment explaining why we need this here
| const ippl::Vector<T,Dim>& h) | ||
| { | ||
| CutTimes<Dim,T> cuts; | ||
| for (unsigned a=0; a<Dim; ++a) cuts.t[a] = (T)2; // sentinel (>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.
maybe make this comment more explicit (e.g. "initialize to 2 since value >1 means no crossing")
| template<unsigned Dim, typename T> | ||
| KOKKOS_INLINE_FUNCTION | ||
| void make_endpoints_fixed(const CutTimes<Dim,T>& cuts, | ||
| std::array<T,Dim+2>& Tcuts /*out*/) |
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.
same comment as before for std::array
| } | ||
|
|
||
| const T one = (T)1; | ||
| auto clamp_or_one = [&](T v)->T { return (v >= (T)1.5) ? one : (v < one ? v : one); }; |
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.
Isn't this effectively the same as just doing (v >= 1) ? one: v?
s-mayani
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.
Have reviewed the grid path segmenter, and the preliminary structure of the current projecter looks good.
This PR adds the segment splitting as well as the current state of the interpolation scheme.