From: Peter Munch Date: Fri, 27 Oct 2023 15:23:30 +0000 (+0200) Subject: Use EvaluationFlags inside CUDAWrapper::FEEvaluation X-Git-Tag: relicensing~347^2 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F16203%2Fhead;p=dealii.git Use EvaluationFlags inside CUDAWrapper::FEEvaluation --- diff --git a/doc/news/changes/incompatibilities/20231027Munch b/doc/news/changes/incompatibilities/20231027Munch new file mode 100644 index 0000000000..0b996f7585 --- /dev/null +++ b/doc/news/changes/incompatibilities/20231027Munch @@ -0,0 +1,6 @@ +Removed: The functions evaluate() and integrate() of +CUDAWrappers::FEEvaluation that take Bools have been +deprecated and replaced by versions that take +EvaluationFlags. +
+(Peter Munch, 2023/10/27) diff --git a/examples/step-64/step-64.cc b/examples/step-64/step-64.cc index 5b14e2b24c..4678f23cea 100644 --- a/examples/step-64/step-64.cc +++ b/examples/step-64/step-64.cc @@ -221,10 +221,10 @@ namespace Step64 CUDAWrappers::FEEvaluation fe_eval(gpu_data, shared_data); fe_eval.read_dof_values(src); - fe_eval.evaluate(true, true); + fe_eval.evaluate(EvaluationFlags::values | EvaluationFlags::gradients); fe_eval.apply_for_each_quad_point( HelmholtzOperatorQuad(gpu_data, coef, cell)); - fe_eval.integrate(true, true); + fe_eval.integrate(EvaluationFlags::values | EvaluationFlags::gradients); fe_eval.distribute_local_to_global(dst); } diff --git a/include/deal.II/matrix_free/cuda_fe_evaluation.h b/include/deal.II/matrix_free/cuda_fe_evaluation.h index 060fba7c4d..f8779fce0b 100644 --- a/include/deal.II/matrix_free/cuda_fe_evaluation.h +++ b/include/deal.II/matrix_free/cuda_fe_evaluation.h @@ -29,6 +29,7 @@ #include #include #include +#include #include @@ -143,6 +144,19 @@ namespace CUDAWrappers * @p get_value() or @p get_gradient() give useful information. */ DEAL_II_HOST_DEVICE void + evaluate(const EvaluationFlags::EvaluationFlags evaluate_flag); + + /** + * Evaluate the function values and the gradients of the FE function given + * at the DoF values in the input vector at the quadrature points on the + * unit cell. The function arguments specify which parts shall actually be + * computed. This function needs to be called before the functions + * @p get_value() or @p get_gradient() give useful information. + */ + DEAL_II_DEPRECATED_EARLY_WITH_COMMENT( + "Use the version taking EvaluationFlags.") + DEAL_II_HOST_DEVICE + void evaluate(const bool evaluate_val, const bool evaluate_grad); /** @@ -153,6 +167,19 @@ namespace CUDAWrappers * of the values or the gradients. */ DEAL_II_HOST_DEVICE void + integrate(const EvaluationFlags::EvaluationFlags integration_flag); + + /** + * This function takes the values and/or gradients that are stored on + * quadrature points, tests them by all the basis functions/gradients on + * the cell and performs the cell integration. The two function arguments + * @p integrate_val and @p integrate_grad are used to enable/disable some + * of the values or the gradients. + */ + DEAL_II_DEPRECATED_EARLY_WITH_COMMENT( + "Use the version taking EvaluationFlags.") + DEAL_II_HOST_DEVICE + void integrate(const bool integrate_val, const bool integrate_grad); /** @@ -312,8 +339,7 @@ namespace CUDAWrappers typename Number> DEAL_II_HOST_DEVICE void FEEvaluation::evaluate( - const bool evaluate_val, - const bool evaluate_grad) + const EvaluationFlags::EvaluationFlags evaluate_flag) { // First evaluate the gradients because it requires values that will be // changed if evaluate_val is true @@ -327,19 +353,21 @@ namespace CUDAWrappers data->shape_values, data->shape_gradients, data->co_shape_gradients); - if (evaluate_val == true && evaluate_grad == true) + + if ((evaluate_flag & EvaluationFlags::values) && + (evaluate_flag & EvaluationFlags::gradients)) { evaluator_tensor_product.value_and_gradient_at_quad_pts( shared_data->values, shared_data->gradients); shared_data->team_member.team_barrier(); } - else if (evaluate_grad == true) + else if (evaluate_flag & EvaluationFlags::gradients) { evaluator_tensor_product.gradient_at_quad_pts(shared_data->values, shared_data->gradients); shared_data->team_member.team_barrier(); } - else if (evaluate_val == true) + else if (evaluate_flag & EvaluationFlags::values) { evaluator_tensor_product.value_at_quad_pts(shared_data->values); shared_data->team_member.team_barrier(); @@ -348,6 +376,23 @@ namespace CUDAWrappers + template + DEAL_II_HOST_DEVICE void + FEEvaluation::evaluate( + const bool evaluate_val, + const bool evaluate_grad) + { + evaluate( + (evaluate_val ? EvaluationFlags::values : EvaluationFlags::nothing) | + (evaluate_grad ? EvaluationFlags::gradients : EvaluationFlags::nothing)); + } + + + template DEAL_II_HOST_DEVICE void FEEvaluation::integrate( - const bool integrate_val, - const bool integrate_grad) + const EvaluationFlags::EvaluationFlags integration_flag) { internal::EvaluatorTensorProduct< internal::EvaluatorVariant::evaluate_general, @@ -368,17 +412,19 @@ namespace CUDAWrappers data->shape_values, data->shape_gradients, data->co_shape_gradients); - if (integrate_val == true && integrate_grad == true) + + if ((integration_flag & EvaluationFlags::values) && + (integration_flag & EvaluationFlags::gradients)) { evaluator_tensor_product.integrate_value_and_gradient( shared_data->values, shared_data->gradients); } - else if (integrate_val == true) + else if (integration_flag & EvaluationFlags::gradients) { evaluator_tensor_product.integrate_value(shared_data->values); shared_data->team_member.team_barrier(); } - else if (integrate_grad == true) + else if (integration_flag & EvaluationFlags::values) { evaluator_tensor_product.template integrate_gradient( shared_data->values, shared_data->gradients); @@ -388,6 +434,23 @@ namespace CUDAWrappers + template + DEAL_II_HOST_DEVICE void + FEEvaluation::integrate( + const bool integrate_val, + const bool integrate_grad) + { + integrate( + (integrate_val ? EvaluationFlags::values : EvaluationFlags::nothing) | + (integrate_grad ? EvaluationFlags::gradients : EvaluationFlags::nothing)); + } + + + template (static_cast(f1) | @@ -84,7 +84,7 @@ namespace EvaluationFlags * * @ref EvaluationFlags */ - inline EvaluationFlags & + DEAL_II_HOST_DEVICE inline EvaluationFlags & operator|=(EvaluationFlags &f1, const EvaluationFlags f2) { f1 = f1 | f2; @@ -101,7 +101,7 @@ namespace EvaluationFlags * * @ref EvaluationFlags */ - inline EvaluationFlags + DEAL_II_HOST_DEVICE inline EvaluationFlags operator&(const EvaluationFlags f1, const EvaluationFlags f2) { return static_cast(static_cast(f1) & @@ -115,7 +115,7 @@ namespace EvaluationFlags * * @ref EvaluationFlags */ - inline EvaluationFlags & + DEAL_II_HOST_DEVICE inline EvaluationFlags & operator&=(EvaluationFlags &f1, const EvaluationFlags f2) { f1 = f1 & f2; diff --git a/tests/matrix_free/matrix_free_device_no_index_initialize.cc b/tests/matrix_free/matrix_free_device_no_index_initialize.cc index f741a6a4b8..e2ce81d585 100644 --- a/tests/matrix_free/matrix_free_device_no_index_initialize.cc +++ b/tests/matrix_free/matrix_free_device_no_index_initialize.cc @@ -57,7 +57,7 @@ public: n_local_dofs), [&](int i) { fe_eval_ptr->submit_dof_value(1., i); }); shared_data->team_member.team_barrier(); - fe_eval.evaluate(/*evaluate_values =*/true, /*evaluate_gradients=*/true); + fe_eval.evaluate(EvaluationFlags::values | EvaluationFlags::gradients); #ifndef __APPLE__ Kokkos::parallel_for(Kokkos::TeamThreadRange(shared_data->team_member, @@ -69,8 +69,7 @@ public: assert(fe_eval_ptr->get_gradient(i)[e] == 0.); }); - fe_eval.integrate(/*integrate_values = */ true, - /*integrate_gradients=*/true); + fe_eval.integrate(EvaluationFlags::values | EvaluationFlags::gradients); Kokkos::parallel_for( Kokkos::TeamThreadRange(shared_data->team_member, n_local_dofs), diff --git a/tests/matrix_free/matrix_vector_device_mf.h b/tests/matrix_free/matrix_vector_device_mf.h index ce84faa007..a67705df33 100644 --- a/tests/matrix_free/matrix_vector_device_mf.h +++ b/tests/matrix_free/matrix_vector_device_mf.h @@ -109,12 +109,12 @@ HelmholtzOperator::operator()( CUDAWrappers::FEEvaluation fe_eval( gpu_data, shared_data); fe_eval.read_dof_values(src); - fe_eval.evaluate(true, true); + fe_eval.evaluate(EvaluationFlags::values | EvaluationFlags::gradients); fe_eval.apply_for_each_quad_point( HelmholtzOperatorQuad(gpu_data, coef, cell)); - fe_eval.integrate(true, true); + fe_eval.integrate(EvaluationFlags::values | EvaluationFlags::gradients); fe_eval.distribute_local_to_global(dst); }