Skip to content
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

Add a batched operator() to SplineEvaluator without the coordinates argument #684

Open
EmilyBourne opened this issue Nov 12, 2024 · 1 comment · May be fixed by #685
Open

Add a batched operator() to SplineEvaluator without the coordinates argument #684

EmilyBourne opened this issue Nov 12, 2024 · 1 comment · May be fixed by #685
Assignees

Comments

@EmilyBourne
Copy link
Collaborator

The batched operator() in SplineEvaluator takes the coordinates for the evaluation as argument:

template <class Layout1, class Layout2, class Layout3, class... CoordsDims>
void operator()(
ddc::ChunkSpan<double, batched_evaluation_domain_type, Layout1, memory_space> const
spline_eval,
ddc::ChunkSpan<
ddc::Coordinate<CoordsDims...> const,
batched_evaluation_domain_type,
Layout2,
memory_space> const coords_eval,
ddc::ChunkSpan<double const, batched_spline_domain_type, Layout3, memory_space> const
spline_coef) const

This is useful for example for the Semi-Lagrangian scheme. However it is more common to use the operator() to evaluate the spline at the coordinates associated with the function. It is therefore common to call the function with the following code:

ddc::ChunkSpan<double const, batched_spline_domain_type> const spline_coef(...);
ddc::Chunk<double, batched_evaluation_domain_type> const spline_eval(eval_domain);
ddc::Chunk<ddc::Coordinate<CoordsDims...>, batched_evaluation_domain_type> coords_eval_alloc(
        eval_domain);
ddc::ChunkSpan<ddc::Coordinate<CoordsDims...>, batched_evaluation_domain_type> coords_eval
        = coords_eval_alloc.span_view();
ddc::parallel_for_each(
        eval_domain,
        KOKKOS_LAMBDA(batched_evaluation_element_type idx) {
            coords_eval(idx) = ddc::coordinate(idx);
        });
spline_evaluator(spline_eval.span_view(), coords_eval.span_cview(), spline_coef);

The lines:

ddc::Chunk<ddc::Coordinate<CoordsDims...>, batched_evaluation_domain_type> coords_eval_alloc(
        eval_domain);
ddc::ChunkSpan<ddc::Coordinate<CoordsDims...>, batched_evaluation_domain_type> coords_eval
        = coords_eval_alloc.span_view();
ddc::parallel_for_each(
        eval_domain,
        KOKKOS_LAMBDA(batched_evaluation_element_type idx) {
            coords_eval(idx) = ddc::coordinate(idx);
        });

lead to excessive code repetition and unnecessary memory allocation.

The addition of a new operator() defined as:

 template <class Layout1, class Layout2> 
 void operator()( 
         ddc::ChunkSpan<double, batched_evaluation_domain_type, Layout1, memory_space> const 
                 spline_eval, 
         ddc::ChunkSpan<double const, batched_spline_domain_type, Layout2, memory_space> const 
                 spline_coef) const 

would avoid this.

@tpadioleau
Copy link
Member

Seems reasonable yes

@EmilyBourne EmilyBourne self-assigned this Nov 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants