From 42bb09d62b7039e622c46e799fc4d96028ee9334 Mon Sep 17 00:00:00 2001 From: MMRROO Date: Mon, 19 Feb 2024 16:07:09 -0500 Subject: [PATCH] updating parallel_for in tests --- MParT/Utilities/LinearAlgebra.h | 2 +- tests/Test_MapObjective.cpp | 3 ++- tests/Test_MonotoneComponent.cpp | 19 ++++++++++++------- tests/Test_MultivariateExpansionWorker.cpp | 5 +++-- tests/Test_OrthogonalPolynomials.cpp | 6 +++--- 5 files changed, 21 insertions(+), 14 deletions(-) diff --git a/MParT/Utilities/LinearAlgebra.h b/MParT/Utilities/LinearAlgebra.h index e2a18267..89ec3498 100644 --- a/MParT/Utilities/LinearAlgebra.h +++ b/MParT/Utilities/LinearAlgebra.h @@ -26,7 +26,7 @@ template void AddInPlace(ViewType1 x, ViewType2 y) { constexpr size_t rank = GetViewRank::Rank; if constexpr(rank == 1) { -// Kokkos::RangePolicy::Space> policy(0,x.extent(0)); + Kokkos::RangePolicy policy(0,x.extent(0)); Kokkos::parallel_for(x.extent(0), KOKKOS_LAMBDA(const int i){x(i) += y(i);}); } else if (rank == 2) { Kokkos::MDRangePolicy,typename ViewType1::execution_space> policy({0, 0}, {x.extent(0), x.extent(1)}); diff --git a/tests/Test_MapObjective.cpp b/tests/Test_MapObjective.cpp index e878c5d8..55300b40 100644 --- a/tests/Test_MapObjective.cpp +++ b/tests/Test_MapObjective.cpp @@ -46,7 +46,8 @@ TEST_CASE( "Test KLMapObjective", "[KLMapObjective]") { const double coeff_def = 1.; auto map = MapFactory::CreateTriangular(dim, dim, 2); - Kokkos::parallel_for("Fill coeffs", map->numCoeffs, KOKKOS_LAMBDA(const unsigned int i){ + Kokkos::RangePolicy::Space> policy(0, map->numCoeffs); + Kokkos::parallel_for("Fill coeffs", policy, KOKKOS_LAMBDA(const unsigned int i){ map->Coeffs()(i) = coeff_def; }); diff --git a/tests/Test_MonotoneComponent.cpp b/tests/Test_MonotoneComponent.cpp index 51b19259..33b4678c 100644 --- a/tests/Test_MonotoneComponent.cpp +++ b/tests/Test_MonotoneComponent.cpp @@ -905,7 +905,8 @@ TEST_CASE( "MonotoneIntegrand1d on device", "[MonotoneIntegrandDevice]") { SECTION("Integrand Only") { Kokkos::View dres("result", 1); - Kokkos::parallel_for(1, KOKKOS_LAMBDA(const int i){ + Kokkos::RangePolicy::Space> policy(0,1); + Kokkos::parallel_for(policy, KOKKOS_LAMBDA(const int i){ MonotoneIntegrand integrand(dcache.data(), expansion, dpt, dcoeffs, DerivativeFlags::None, 0.0); integrand(0.5, &dres(0)); }); @@ -918,7 +919,8 @@ TEST_CASE( "MonotoneIntegrand1d on device", "[MonotoneIntegrandDevice]") { SECTION("Integrand Derivative") { Kokkos::View dres("result", 2); - Kokkos::parallel_for(1, KOKKOS_LAMBDA(const int i){ + Kokkos::RangePolicy::Space> policy(0,1); + Kokkos::parallel_for(policy, KOKKOS_LAMBDA(const int i){ MonotoneIntegrand integrand(dcache.data(), expansion, dpt, dcoeffs, DerivativeFlags::Diagonal, 0.0); integrand(0.5, dres.data()); }); @@ -934,7 +936,8 @@ TEST_CASE( "MonotoneIntegrand1d on device", "[MonotoneIntegrandDevice]") { Kokkos::View dres_fd("result_fd", hset.Size()); Kokkos::View testVal("integrand", 1+hset.Size()); - Kokkos::parallel_for(1, KOKKOS_LAMBDA(const int i){ + Kokkos::RangePolicy::Space> policy(0,1); + Kokkos::parallel_for(policy, KOKKOS_LAMBDA(const int i){ MonotoneIntegrand integrand(dcache.data(), expansion, dpt, dcoeffs, DerivativeFlags::Parameters, 0.0); MonotoneIntegrand integrand2(dcache.data(), expansion, dpt, dcoeffs, DerivativeFlags::None, 0.0); @@ -968,8 +971,9 @@ TEST_CASE( "MonotoneIntegrand1d on device", "[MonotoneIntegrandDevice]") { Kokkos::View dres_fd("result_fd", hset.Size()); Kokkos::View testVal("integrand", 1+hset.Size()); Kokkos::View workspace("workspace", hset.Size()); - - Kokkos::parallel_for(1, KOKKOS_LAMBDA(const int i){ + + Kokkos::RangePolicy::Space> policy(0,1); + Kokkos::parallel_for(policy, KOKKOS_LAMBDA(const int i){ MonotoneIntegrand integrand(dcache.data(), expansion, dpt, dcoeffs, DerivativeFlags::Mixed, 0.0, workspace); MonotoneIntegrand integrand2(dcache.data(), expansion, dpt, dcoeffs, DerivativeFlags::Diagonal, 0.0); @@ -1036,7 +1040,8 @@ TEST_CASE( "Testing MonotoneComponent::EvaluateSingle on Device", "[MonotoneComp Kokkos::View dres("Device Evaluation", 1); // Run the fill cache funciton, using a parallel_for loop to ensure it's run on the device - Kokkos::parallel_for(1, KOKKOS_LAMBDA(const int i){ + Kokkos::RangePolicy::Space> policy(0,1); + Kokkos::parallel_for(policy, KOKKOS_LAMBDA(const int i){ dexpansion.FillCache1(dcache.data(), dpt, DerivativeFlags::None); dres(0) = MonotoneComponent::EvaluateSingle(dcache.data(), workspace.data(), dpt, dpt(dim-1), dcoeffs, quad, dexpansion); }); @@ -1139,4 +1144,4 @@ TEST_CASE( "Testing 1d monotone component evaluation on device", "[MonotoneCompo } -#endif \ No newline at end of file +#endif diff --git a/tests/Test_MultivariateExpansionWorker.cpp b/tests/Test_MultivariateExpansionWorker.cpp index 1b0db635..b88b7212 100644 --- a/tests/Test_MultivariateExpansionWorker.cpp +++ b/tests/Test_MultivariateExpansionWorker.cpp @@ -251,7 +251,8 @@ TEST_CASE( "Testing multivariate expansion on device", "[MultivariateExpansionWo hexpansion.FillCache1(hcache.data(), hpt, DerivativeFlags::None); // Run the fill cache funciton, using a parallel_for loop to ensure it's run on the device - Kokkos::parallel_for(1, KOKKOS_LAMBDA(const int i){ + Kokkos::RangePolicy::Space> policy(0,1); + Kokkos::parallel_for(policy, KOKKOS_LAMBDA(const int i){ dexpansion.FillCache1(dcache.data(), dpt, DerivativeFlags::None); dexpansion.FillCache2(dcache.data(), dpt, 0.5 * dpt(dim-1), DerivativeFlags::None); }); @@ -267,4 +268,4 @@ TEST_CASE( "Testing multivariate expansion on device", "[MultivariateExpansionWo } } -#endif \ No newline at end of file +#endif diff --git a/tests/Test_OrthogonalPolynomials.cpp b/tests/Test_OrthogonalPolynomials.cpp index 10a2d32b..2e8d7e73 100644 --- a/tests/Test_OrthogonalPolynomials.cpp +++ b/tests/Test_OrthogonalPolynomials.cpp @@ -251,9 +251,9 @@ TEST_CASE( "Device Hermite polynomial evaluation", "[PhysicistHermiteDevice]" ) auto xs_device = ToDevice(xs_host); Kokkos::View ys_device("evals", xs.size()); - + Kokkos::RangePolicy policy(0,xs.size()); for(unsigned int p=0; p<10; ++p){ - Kokkos::parallel_for(xs.size(), KOKKOS_LAMBDA(const size_t ind){ + Kokkos::parallel_for(policy, KOKKOS_LAMBDA(const size_t ind){ ys_device(ind) = poly.Evaluate(p, xs_device(ind)); }); @@ -267,4 +267,4 @@ TEST_CASE( "Device Hermite polynomial evaluation", "[PhysicistHermiteDevice]" ) } -#endif \ No newline at end of file +#endif