]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Initialize and finalize Kokkos
authorBruno Turcksin <bruno.turcksin@gmail.com>
Thu, 16 Mar 2023 18:12:40 +0000 (14:12 -0400)
committerBruno Turcksin <bruno.turcksin@gmail.com>
Thu, 6 Apr 2023 13:10:39 +0000 (13:10 +0000)
tests/cuda/coefficient_eval.cc
tests/cuda/matrix_free_initialize_vector.cc
tests/cuda/matrix_free_multiple_objects.cc
tests/cuda/matrix_free_no_index_initialize.cc
tests/cuda/matrix_vector_common.h

index 8db177d609abbf2ca4421c1ec2c200f50d92ae1d..09529e932f18ef02e474772ba827e641d57e53a5 100644 (file)
@@ -28,6 +28,8 @@
 
 #include "../tests.h"
 
+#include "Kokkos_Core.hpp"
+
 
 template <int dim, int fe_degree>
 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;
 }
index 46e41fad76eeda8218b50f9b89cf84c4c0153eea..7cdefebe5fc9b576269de3b8639d06067d3006c3 100644 (file)
@@ -38,9 +38,9 @@
 
 template <typename Number>
 void
-check(
-  const LinearAlgebra::distributed::Vector<Number, MemorySpace::CUDA> &vector,
-  const Utilities::MPI::Partitioner &reference_partitioner)
+check(const LinearAlgebra::distributed::Vector<Number, MemorySpace::Default>
+        &                                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<double, MemorySpace::CUDA>>();
+  test<2,
+       1,
+       LinearAlgebra::distributed::Vector<double, MemorySpace::Default>>();
   if (Utilities::MPI::n_mpi_processes(MPI_COMM_WORLD) == 1)
     test<2, 1, LinearAlgebra::CUDAWrappers::Vector<double>>();
+
+  return 0;
 }
index 4742c108a6a2e9f60c3c658970bdf94fa5616d22..c3740bc80f2381a3352572a233e076b24ed1af9e 100644 (file)
@@ -43,6 +43,7 @@
 
 #include "../tests.h"
 
+#include "Kokkos_Core.hpp"
 #include "matrix_vector_mf.h"
 
 template <int fe_degree, int n_q_points_1d>
@@ -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<double> 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<double>,
-                 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<double>,
-                 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<fe_degree_1, n_q_points_1d_1>(
-    dof_1, mf_1, n_dofs_1, mapping_1, constraints);
-
-  // Perform MV with the second object
-  do_test<fe_degree_2, n_q_points_1d_2>(
-    dof_2, mf_2, n_dofs_2, mapping_2, constraints);
+  {
+    Triangulation<2> tria;
+    GridGenerator::hyper_cube(tria);
+    tria.refine_global(5 - 2);
+    AffineConstraints<double> 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<double>,
+                   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<double>,
+                   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<fe_degree_1, n_q_points_1d_1>(
+      dof_1, mf_1, n_dofs_1, mapping_1, constraints);
+
+    // Perform MV with the second object
+    do_test<fe_degree_2, n_q_points_1d_2>(
+      dof_2, mf_2, n_dofs_2, mapping_2, constraints);
+  }
+  Kokkos::finalize();
 
   return 0;
 }
index 204658a41aac33c0796bd1d67bf9f24e27654bed..df3e7d700fdab9beac4cf1cc838e8260bcdc4332 100644 (file)
@@ -24,6 +24,8 @@
 
 #include "../tests.h"
 
+#include "Kokkos_Core.hpp"
+
 template <int dim,
           int fe_degree,
           int n_q_points_1d = fe_degree + 1,
@@ -147,7 +149,12 @@ main()
 {
   initlog();
 
+  Kokkos::initialize();
   init_cuda();
 
   test<2, 1>();
+
+  Kokkos::finalize();
+
+  return 0;
 }
index fc506935f5e1efb4e5df14d64194475ef7bb7183..bdedecf6be73b5a030ccd9d518ac01a9610bb62c 100644 (file)
@@ -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;
 }

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.