From 1bb0a99f5b6b4cf00887540cd0037bd791f92347 Mon Sep 17 00:00:00 2001 From: Bruno Turcksin Date: Thu, 16 Mar 2023 14:12:40 -0400 Subject: [PATCH] Initialize and finalize Kokkos --- tests/cuda/coefficient_eval.cc | 5 +- tests/cuda/matrix_free_initialize_vector.cc | 12 +- tests/cuda/matrix_free_multiple_objects.cc | 129 +++++++++--------- tests/cuda/matrix_free_no_index_initialize.cc | 7 + tests/cuda/matrix_vector_common.h | 5 + 5 files changed, 91 insertions(+), 67 deletions(-) diff --git a/tests/cuda/coefficient_eval.cc b/tests/cuda/coefficient_eval.cc index 8db177d609..09529e932f 100644 --- a/tests/cuda/coefficient_eval.cc +++ b/tests/cuda/coefficient_eval.cc @@ -28,6 +28,8 @@ #include "../tests.h" +#include "Kokkos_Core.hpp" + template class DummyOperator @@ -172,11 +174,12 @@ int main() { initlog(); - init_cuda(); + Kokkos::initialize(); test<2, 3>(); test<3, 3>(); deallog << "OK" << std::endl; + Kokkos::finalize(); return 0; } diff --git a/tests/cuda/matrix_free_initialize_vector.cc b/tests/cuda/matrix_free_initialize_vector.cc index 46e41fad76..7cdefebe5f 100644 --- a/tests/cuda/matrix_free_initialize_vector.cc +++ b/tests/cuda/matrix_free_initialize_vector.cc @@ -38,9 +38,9 @@ template void -check( - const LinearAlgebra::distributed::Vector &vector, - const Utilities::MPI::Partitioner &reference_partitioner) +check(const LinearAlgebra::distributed::Vector + & vector, + const Utilities::MPI::Partitioner &reference_partitioner) { Assert(vector.get_partitioner()->locally_owned_range() == reference_partitioner.locally_owned_range(), @@ -116,7 +116,11 @@ main(int argc, char **argv) init_cuda(true); MPILogInitAll mpi_inilog; - test<2, 1, LinearAlgebra::distributed::Vector>(); + test<2, + 1, + LinearAlgebra::distributed::Vector>(); if (Utilities::MPI::n_mpi_processes(MPI_COMM_WORLD) == 1) test<2, 1, LinearAlgebra::CUDAWrappers::Vector>(); + + return 0; } diff --git a/tests/cuda/matrix_free_multiple_objects.cc b/tests/cuda/matrix_free_multiple_objects.cc index 4742c108a6..c3740bc80f 100644 --- a/tests/cuda/matrix_free_multiple_objects.cc +++ b/tests/cuda/matrix_free_multiple_objects.cc @@ -43,6 +43,7 @@ #include "../tests.h" +#include "Kokkos_Core.hpp" #include "matrix_vector_mf.h" template @@ -147,70 +148,74 @@ main() deallog << std::setprecision(3); + Kokkos::initialize(); init_cuda(); - Triangulation<2> tria; - GridGenerator::hyper_cube(tria); - tria.refine_global(5 - 2); - AffineConstraints constraints; - constraints.close(); - bool constant_coefficient = true; - - // Create the first MatrixFree object - constexpr unsigned int fe_degree_1 = 1; - constexpr unsigned int n_q_points_1d_1 = fe_degree_1 + 1; - FE_Q<2> fe_1(fe_degree_1); - DoFHandler<2> dof_1(tria); - dof_1.distribute_dofs(fe_1); - MappingQ<2> mapping_1(fe_degree_1); - CUDAWrappers::MatrixFree<2, double> mf_data_1; - CUDAWrappers::MatrixFree<2, double>::AdditionalData additional_data_1; - additional_data_1.mapping_update_flags = update_values | update_gradients | - update_JxW_values | - update_quadrature_points; - const QGauss<1> quad_1(n_q_points_1d_1); - mf_data_1.reinit(mapping_1, dof_1, constraints, quad_1, additional_data_1); - const unsigned int n_dofs_1 = dof_1.n_dofs(); - MatrixFreeTest<2, - fe_degree_1, - double, - LinearAlgebra::CUDAWrappers::Vector, - n_q_points_1d_1> - mf_1(mf_data_1, - n_dofs_1 * std::pow(n_q_points_1d_1, 2), - constant_coefficient); - - // Create the second MatrixFree object - constexpr unsigned int fe_degree_2 = 2; - constexpr unsigned int n_q_points_1d_2 = fe_degree_2 + 1; - FE_Q<2> fe_2(fe_degree_2); - DoFHandler<2> dof_2(tria); - dof_2.distribute_dofs(fe_2); - MappingQ<2> mapping_2(fe_degree_2); - CUDAWrappers::MatrixFree<2, double> mf_data_2; - CUDAWrappers::MatrixFree<2, double>::AdditionalData additional_data_2; - additional_data_2.mapping_update_flags = update_values | update_gradients | - update_JxW_values | - update_quadrature_points; - const QGauss<1> quad_2(n_q_points_1d_2); - mf_data_2.reinit(mapping_2, dof_2, constraints, quad_2, additional_data_2); - const unsigned int n_dofs_2 = dof_2.n_dofs(); - MatrixFreeTest<2, - fe_degree_2, - double, - LinearAlgebra::CUDAWrappers::Vector, - n_q_points_1d_2> - mf_2(mf_data_2, - n_dofs_2 * std::pow(n_q_points_1d_2, 2), - constant_coefficient); - - // Perform MV with the first object - do_test( - dof_1, mf_1, n_dofs_1, mapping_1, constraints); - - // Perform MV with the second object - do_test( - dof_2, mf_2, n_dofs_2, mapping_2, constraints); + { + Triangulation<2> tria; + GridGenerator::hyper_cube(tria); + tria.refine_global(5 - 2); + AffineConstraints constraints; + constraints.close(); + bool constant_coefficient = true; + + // Create the first MatrixFree object + constexpr unsigned int fe_degree_1 = 1; + constexpr unsigned int n_q_points_1d_1 = fe_degree_1 + 1; + FE_Q<2> fe_1(fe_degree_1); + DoFHandler<2> dof_1(tria); + dof_1.distribute_dofs(fe_1); + MappingQ<2> mapping_1(fe_degree_1); + CUDAWrappers::MatrixFree<2, double> mf_data_1; + CUDAWrappers::MatrixFree<2, double>::AdditionalData additional_data_1; + additional_data_1.mapping_update_flags = update_values | update_gradients | + update_JxW_values | + update_quadrature_points; + const QGauss<1> quad_1(n_q_points_1d_1); + mf_data_1.reinit(mapping_1, dof_1, constraints, quad_1, additional_data_1); + const unsigned int n_dofs_1 = dof_1.n_dofs(); + MatrixFreeTest<2, + fe_degree_1, + double, + LinearAlgebra::CUDAWrappers::Vector, + n_q_points_1d_1> + mf_1(mf_data_1, + n_dofs_1 * std::pow(n_q_points_1d_1, 2), + constant_coefficient); + + // Create the second MatrixFree object + constexpr unsigned int fe_degree_2 = 2; + constexpr unsigned int n_q_points_1d_2 = fe_degree_2 + 1; + FE_Q<2> fe_2(fe_degree_2); + DoFHandler<2> dof_2(tria); + dof_2.distribute_dofs(fe_2); + MappingQ<2> mapping_2(fe_degree_2); + CUDAWrappers::MatrixFree<2, double> mf_data_2; + CUDAWrappers::MatrixFree<2, double>::AdditionalData additional_data_2; + additional_data_2.mapping_update_flags = update_values | update_gradients | + update_JxW_values | + update_quadrature_points; + const QGauss<1> quad_2(n_q_points_1d_2); + mf_data_2.reinit(mapping_2, dof_2, constraints, quad_2, additional_data_2); + const unsigned int n_dofs_2 = dof_2.n_dofs(); + MatrixFreeTest<2, + fe_degree_2, + double, + LinearAlgebra::CUDAWrappers::Vector, + n_q_points_1d_2> + mf_2(mf_data_2, + n_dofs_2 * std::pow(n_q_points_1d_2, 2), + constant_coefficient); + + // Perform MV with the first object + do_test( + dof_1, mf_1, n_dofs_1, mapping_1, constraints); + + // Perform MV with the second object + do_test( + dof_2, mf_2, n_dofs_2, mapping_2, constraints); + } + Kokkos::finalize(); return 0; } diff --git a/tests/cuda/matrix_free_no_index_initialize.cc b/tests/cuda/matrix_free_no_index_initialize.cc index 204658a41a..df3e7d700f 100644 --- a/tests/cuda/matrix_free_no_index_initialize.cc +++ b/tests/cuda/matrix_free_no_index_initialize.cc @@ -24,6 +24,8 @@ #include "../tests.h" +#include "Kokkos_Core.hpp" + template (); + + Kokkos::finalize(); + + return 0; } diff --git a/tests/cuda/matrix_vector_common.h b/tests/cuda/matrix_vector_common.h index fc506935f5..bdedecf6be 100644 --- a/tests/cuda/matrix_vector_common.h +++ b/tests/cuda/matrix_vector_common.h @@ -46,6 +46,7 @@ #include "../tests.h" +#include "Kokkos_Core.hpp" #include "matrix_vector_mf.h" @@ -194,6 +195,8 @@ main() deallog << std::setprecision(3); + Kokkos::initialize(); + init_cuda(); { @@ -223,5 +226,7 @@ main() deallog.pop(); } + Kokkos::finalize(); + return 0; } -- 2.39.5