From: Daniel Arndt Date: Wed, 5 Mar 2025 03:51:20 +0000 (+0000) Subject: Use a functor X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8798aa101e5fc58135034d5a89d727ca78063197;p=dealii.git Use a functor --- diff --git a/tests/matrix_free_kokkos/evaluate_2d_shape.cc b/tests/matrix_free_kokkos/evaluate_2d_shape.cc index e82a4fea4f..93b3978719 100644 --- a/tests/matrix_free_kokkos/evaluate_2d_shape.cc +++ b/tests/matrix_free_kokkos/evaluate_2d_shape.cc @@ -33,51 +33,55 @@ using TeamHandle = Kokkos::TeamPolicy< MemorySpace::Default::kokkos_space::execution_space>::member_type; +// FIXME Inlining the functor creates "invalid device code" errors template -DEAL_II_HOST_DEVICE void -evaluate_tensor_product( - const TeamHandle &team_member, - Kokkos::View shape_values, - Kokkos::View shape_gradients, - Kokkos::View co_shape_gradients, - Kokkos::View dst, - Kokkos::View src, - Kokkos::View tmp) +struct EvaluateTensorProduct { - Kokkos::View< - double *, - MemorySpace::Default::kokkos_space::execution_space::scratch_memory_space, - Kokkos::MemoryTraits> - dummy_scratch(team_member.team_shmem(), 0); - - Portable::internal::EvaluatorTensorProduct< - Portable::internal::evaluate_general, - 2, - M, - N, - double> - evaluator(team_member, - shape_values, - shape_gradients, - co_shape_gradients, - dummy_scratch); - - constexpr int d0 = dof_to_quad ? 0 : 1; - constexpr int d1 = dof_to_quad ? 1 : 0; - - if (type == 0) - { - evaluator.template values(src, tmp); - team_member.team_barrier(); - evaluator.template values(tmp, dst); - } - if (type == 1) - { - evaluator.template gradients(src, tmp); - team_member.team_barrier(); - evaluator.template gradients(tmp, dst); - } -} + DEAL_II_HOST_DEVICE void + operator()(const TeamHandle &team_member) const + { + Kokkos::View< + double *, + MemorySpace::Default::kokkos_space::execution_space::scratch_memory_space, + Kokkos::MemoryTraits> + dummy_scratch(team_member.team_shmem(), 0); + + Portable::internal::EvaluatorTensorProduct< + Portable::internal::evaluate_general, + 2, + M, + N, + double> + evaluator(team_member, + shape_values, + shape_gradients, + co_shape_gradients, + dummy_scratch); + + constexpr int d0 = dof_to_quad ? 0 : 1; + constexpr int d1 = dof_to_quad ? 1 : 0; + + if (type == 0) + { + evaluator.template values(src, tmp); + team_member.team_barrier(); + evaluator.template values(tmp, dst); + } + if (type == 1) + { + evaluator.template gradients(src, tmp); + team_member.team_barrier(); + evaluator.template gradients(tmp, dst); + } + } + + Kokkos::View shape_values; + Kokkos::View shape_gradients; + Kokkos::View co_shape_gradients; + Kokkos::View dst; + Kokkos::View src; + Kokkos::View tmp; +}; template void @@ -170,16 +174,9 @@ test() MemorySpace::Default::kokkos_space::execution_space exec; Kokkos::TeamPolicy team_policy(exec, 1, Kokkos::AUTO); - Kokkos::parallel_for( - team_policy, KOKKOS_LAMBDA(const TeamHandle &team_member) { - evaluate_tensor_product(team_member, - shape_values, - shape_gradients, - co_shape_gradients, - y_dev, - x_dev, - tmp_dev); - }); + EvaluateTensorProduct functor_to_dof{ + shape_values, shape_gradients, co_shape_gradients, y_dev, x_dev, tmp_dev}; + Kokkos::parallel_for(team_policy, functor_to_dof); // Check the results on the host Kokkos::deep_copy(y_host, y_dev); @@ -208,16 +205,9 @@ test() Kokkos::deep_copy(x_dev, x_host); // Launch the kernel - Kokkos::parallel_for( - team_policy, KOKKOS_LAMBDA(const TeamHandle &team_member) { - evaluate_tensor_product(team_member, - shape_values, - shape_gradients, - co_shape_gradients, - x_dev, - y_dev, - tmp_dev); - }); + EvaluateTensorProduct functor_to_quad{ + shape_values, shape_gradients, co_shape_gradients, x_dev, y_dev, tmp_dev}; + Kokkos::parallel_for(team_policy, functor_to_quad); // Check the results on the host Kokkos::deep_copy(x_host, x_dev);