// @HEADER // ***************************************************************************** // MueLu: A package for multigrid based preconditioning // // Copyright 2012 NTESS and the MueLu contributors. // SPDX-License-Identifier: BSD-3-Clause // ***************************************************************************** // @HEADER #include #include #include // Galeri #include #include #include #include #include #include #include #include #include #include #include namespace MueLuTests { TEUCHOS_UNIT_TEST_TEMPLATE_4_DECL(Regression, H2D, Scalar, LocalOrdinal, GlobalOrdinal, Node) { #include MUELU_TESTING_SET_OSTREAM; MUELU_TESTING_LIMIT_SCOPE(Scalar, GlobalOrdinal, Node); out << "version: " << MueLu::Version() << std::endl; typedef typename Teuchos::ScalarTraits::magnitudeType real_type; typedef typename Xpetra::MultiVector RealValuedMultiVector; RCP > comm = TestHelpers_kokkos::Parameters::getDefaultComm(); if (comm->getSize() != 1) { out << "Skipping test for more than 1 proc" << std::endl; return; } Teuchos::RCP stacked_timer = rcp(new Teuchos::StackedTimer("H2D")); Teuchos::TimeMonitor::setStackedTimer(stacked_timer); int numRows = 399; RCP A = MueLuTests::TestHelpers_kokkos::TestFactory::Build1DPoisson(numRows); RCP map = A->getMap(); RCP coordinates = Xpetra::MultiVectorFactory::Build(map, 1); RCP nullspace = MultiVectorFactory::Build(map, 1); nullspace->putScalar(Teuchos::ScalarTraits::one()); Teuchos::ParameterList MueLuList; MueLuList.set("verbosity", "high"); MueLuList.set("coarse: max size", numRows - 1); // make it so we want two levels MueLuList.set("smoother: type", "RELAXATION"); MueLuList.sublist("smoother: params").set("relaxation: type", "Jacobi"); MueLuList.set("max levels", 2); MueLuList.set("use kokkos refactor", true); Teuchos::ParameterList userParamList = MueLuList.sublist("user data"); userParamList.set >("Coordinates", coordinates); userParamList.set >("Nullspace", nullspace); Tpetra::Details::DeepCopyCounter::reset(); Tpetra::Details::DeepCopyCounter::start(); Teuchos::RCP > H = MueLu::CreateXpetraPreconditioner(A, MueLuList); Tpetra::Details::DeepCopyCounter::stop(); // confirm that we did get a hierarchy with two levels -- a sanity check for this test TEST_EQUALITY(2, H->GetGlobalNumLevels()); // When Kokkos Kernels uses TPLs, some Kokkos::deep_copy in the Kokkos Kernels native implementations are not called. int kkNativeDeepCopies = 8; #if defined(KOKKOSKERNELS_ENABLE_TPL_MKL) if constexpr (Node::is_cpu) kkNativeDeepCopies = 0; #endif #if defined(KOKKOSKERNELS_ENABLE_TPL_CUSPARSE) if constexpr (std::is_same_v) { // kokkos kernels only uses cuSparse for these versions #if (CUDA_VERSION < 11000) || (CUDA_VERSION >= 11040) kkNativeDeepCopies = 0; #endif } #endif #if defined(KOKKOSKERNELS_ENABLE_TPL_ROCSPARSE) if constexpr (std::is_same_v) kkNativeDeepCopies = 0; #endif if (Node::is_cpu) { TEST_EQUALITY(Tpetra::Details::DeepCopyCounter::get_count_different_space(), 0); } #ifdef KOKKOS_HAS_SHARED_SPACE else { size_t targetNumDeepCopies = kkNativeDeepCopies + (std::is_same_v ? 17 : 32); TEST_EQUALITY(Tpetra::Details::DeepCopyCounter::get_count_different_space(), targetNumDeepCopies); } #else else { TEST_EQUALITY(Tpetra::Details::DeepCopyCounter::get_count_different_space(), kkNativeDeepCopies + 32); } #endif // KOKKOS_HAS_SHARED_SPACE auto X = Xpetra::MultiVectorFactory::Build(map, 1); auto B = Xpetra::MultiVectorFactory::Build(map, 1); Tpetra::Details::DeepCopyCounter::reset(); Tpetra::Details::DeepCopyCounter::start(); H->Iterate(*B, *X, 1, false); Tpetra::Details::DeepCopyCounter::stop(); if (Node::is_cpu) { TEST_EQUALITY(Tpetra::Details::DeepCopyCounter::get_count_different_space(), 0); } else { TEST_EQUALITY(Tpetra::Details::DeepCopyCounter::get_count_different_space(), 2); } stacked_timer->stopBaseTimer(); Teuchos::StackedTimer::OutputOptions options; options.output_fraction = options.output_histogram = options.output_minmax = true; stacked_timer->report(out, comm, options); } // H2D TEUCHOS_UNIT_TEST_TEMPLATE_4_DECL(Regression, Aggregation, Scalar, LocalOrdinal, GlobalOrdinal, Node) { #include MUELU_TESTING_SET_OSTREAM; MUELU_TESTING_LIMIT_SCOPE(Scalar, GlobalOrdinal, Node); out << "version: " << MueLu::Version() << std::endl; RCP > comm = TestHelpers_kokkos::Parameters::getDefaultComm(); Teuchos::RCP stacked_timer = rcp(new Teuchos::StackedTimer("H2D")); Teuchos::TimeMonitor::setStackedTimer(stacked_timer); // Make a Matrix with multiple degrees of freedom per node GlobalOrdinal nx = 20, ny = 20; // Describes the initial layout of matrix rows across processors. Teuchos::ParameterList galeriList; galeriList.set("nx", nx); galeriList.set("ny", ny); using test_factory = TestHelpers_kokkos::TestFactory; Teuchos::CommandLineProcessor clp(false); Galeri::Xpetra::Parameters matrixParameters(clp, 8748); // manage parameters of the test case Xpetra::Parameters xpetraParameters(clp); // manage parameters of xpetra RCP A = TestHelpers_kokkos::TestFactory::Build2DPoisson(nx, ny); Tpetra::Details::DeepCopyCounter::reset(); Tpetra::Details::DeepCopyCounter::start(); Level aLevel; TestHelpers_kokkos::TestFactory::createSingleLevelHierarchy(aLevel); aLevel.Request("A"); aLevel.Set("A", A); RCP dropFact = rcp(new CoalesceDropFactory_kokkos()); RCP aggFact = rcp(new UncoupledAggregationFactory()); aggFact->SetFactory("Graph", dropFact); aLevel.Request(*aggFact); aggFact->Build(aLevel); Tpetra::Details::DeepCopyCounter::stop(); if (Node::is_cpu) { TEST_EQUALITY(Tpetra::Details::DeepCopyCounter::get_count_different_space(), 0); } #ifdef KOKKOS_HAS_SHARED_SPACE else { size_t targetNumDeepCopies = std::is_same_v ? 11 : 17; TEST_EQUALITY(Tpetra::Details::DeepCopyCounter::get_count_different_space(), targetNumDeepCopies); } #else else { TEST_EQUALITY(Tpetra::Details::DeepCopyCounter::get_count_different_space(), 17); } #endif stacked_timer->stopBaseTimer(); Teuchos::StackedTimer::OutputOptions options; options.output_fraction = options.output_histogram = options.output_minmax = true; stacked_timer->report(out, comm, options); } // Aggregration #define MUELU_ETI_GROUP(Scalar, LO, GO, Node) \ TEUCHOS_UNIT_TEST_TEMPLATE_4_INSTANT(Regression, H2D, Scalar, LO, GO, Node) \ TEUCHOS_UNIT_TEST_TEMPLATE_4_INSTANT(Regression, Aggregation, Scalar, LO, GO, Node) #include } // namespace MueLuTests