Skip to content

Conversation

@JoMee
Copy link
Contributor

@JoMee JoMee commented Oct 28, 2025

This PR adds the segment splitting as well as the current state of the interpolation scheme.


static KOKKOS_INLINE_FUNCTION
std::array<Segment<Dim,T>, Dim+1>
split(const ippl::Vector<T, Dim>& A,
Copy link
Member

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; } }
Copy link
Member

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];
Copy link
Member

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;
Copy link
Member

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,
Copy link
Member

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;
Copy link
Collaborator

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.

Comment on lines +11 to +12
f(std::integral_constant<int, I>{});
static_for<I+1, End>(std::forward<F>(f));
Copy link
Collaborator

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?

Copy link
Member

@mohsensadr mohsensadr Oct 30, 2025

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; };
Copy link
Collaborator

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.

Comment on lines +40 to +43
const ippl::Vector<T,Dim>& A,
const ippl::Vector<T,Dim>& B,
const ippl::Vector<T,Dim>& origin,
const ippl::Vector<T,Dim>& h)
Copy link
Collaborator

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];
Copy link
Collaborator

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);
Copy link
Collaborator

@s-mayani s-mayani Oct 30, 2025

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;
Copy link
Collaborator

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)
Copy link
Collaborator

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*/)
Copy link
Collaborator

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); };
Copy link
Collaborator

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?

Copy link
Collaborator

@s-mayani s-mayani left a 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants