From 332546b1fdeecf208e4619015f128abb820dcead Mon Sep 17 00:00:00 2001 From: Sam Reeve <6740307+streeve@users.noreply.github.com> Date: Tue, 20 Aug 2024 12:58:49 -0400 Subject: [PATCH] fixup: remove class lambdas; use local copies + class operators --- .github/workflows/CI.yml | 3 -- src/CabanaPD_ForceModels.hpp | 17 ++++--- src/force/CabanaPD_ForceModels_PMB.hpp | 65 +++++++++++++++----------- 3 files changed, 47 insertions(+), 38 deletions(-) diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index 4420f25f..01f68736 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -57,7 +57,6 @@ jobs: -DCMAKE_BUILD_TYPE=${{ matrix.cmake_build_type }} \ -DCMAKE_CXX_COMPILER=${{ matrix.cxx }} \ -DCMAKE_INSTALL_PREFIX=$HOME/kokkos \ - -DCMAKE_CXX_STANDARD=20 \ -DKokkos_ENABLE_${{ matrix.backend }}=ON \ -DKokkos_ENABLE_HWLOC=ON cmake --build build --parallel 2 @@ -149,7 +148,6 @@ jobs: run: | cmake -B build \ -DCMAKE_INSTALL_PREFIX=$HOME/kokkos \ - -DCMAKE_CXX_STANDARD=20 \ -DKokkos_ENABLE_HIP=ON \ -DKokkos_ARCH_VEGA908=ON \ -DCMAKE_BUILD_TYPE=${{ matrix.cmake_build_type }} \ @@ -232,7 +230,6 @@ jobs: run: | cmake -B build \ -DCMAKE_INSTALL_PREFIX=$HOME/kokkos \ - -DCMAKE_CXX_STANDARD=20 \ -DKokkos_ENABLE_CUDA=ON \ -DKokkos_ARCH_VOLTA72=ON \ -DKokkos_ENABLE_CUDA_LAMBDA=ON \ diff --git a/src/CabanaPD_ForceModels.hpp b/src/CabanaPD_ForceModels.hpp index a75b7e41..3b617e58 100644 --- a/src/CabanaPD_ForceModels.hpp +++ b/src/CabanaPD_ForceModels.hpp @@ -65,11 +65,12 @@ struct BaseForceModel , num_types( _delta.size() ) { max_delta = 0; - auto init_func = KOKKOS_CLASS_LAMBDA( const int i, double& max ) + auto delta_copy = delta; + auto init_func = KOKKOS_LAMBDA( const int i, double& max ) { - delta( i ) = _delta[i]; - if ( delta( i ) > max ) - max = delta( i ); + delta_copy( i ) = _delta[i]; + if ( delta_copy( i ) > max ) + max = delta_copy( i ); }; using exec_space = typename memory_space::execution_space; Kokkos::RangePolicy policy( 0, num_types ); @@ -138,10 +139,12 @@ struct BaseTemperatureModel , temperature( _temp ) , type( _type ) { - auto init_func = KOKKOS_CLASS_LAMBDA( const int i ) + auto alpha_copy = alpha; + auto temp0_copy = temp0; + auto init_func = KOKKOS_LAMBDA( const int i ) { - alpha( i ) = _alpha[i]; - temp0( i ) = _temp0[i]; + alpha_copy( i ) = _alpha[i]; + temp0_copy( i ) = _temp0[i]; }; using exec_space = typename memory_space::execution_space; Kokkos::RangePolicy policy( 0, alpha.size() ); diff --git a/src/force/CabanaPD_ForceModels_PMB.hpp b/src/force/CabanaPD_ForceModels_PMB.hpp index 55d189ce..dd256aeb 100644 --- a/src/force/CabanaPD_ForceModels_PMB.hpp +++ b/src/force/CabanaPD_ForceModels_PMB.hpp @@ -91,25 +91,30 @@ struct ForceModel template void setParameters( const ArrayType& _K ) { - // Initialize self interaction parameters. - auto init_self_func = KOKKOS_CLASS_LAMBDA( const int i ) + // Initialize per-type variables. + auto K_copy = K; + auto init_self_func = KOKKOS_LAMBDA( const int i ) { - K( i ) = _K[i]; - c( i, i ) = micromodulus( i ); + K_copy( i ) = _K[i]; }; using exec_space = typename memory_space::execution_space; Kokkos::RangePolicy policy( 0, num_types ); - Kokkos::parallel_for( "CabanaPD::Model::Init", policy, init_self_func ); + Kokkos::parallel_for( "CabanaPD::Model::Copy", policy, init_self_func ); Kokkos::fence(); - // Initialize cross-terms. - auto init_cross_func = KOKKOS_CLASS_LAMBDA( const int i ) + // Initialize model parameters. + Kokkos::parallel_for( "CabanaPD::Model::Init", policy, *this ); + } + + KOKKOS_INLINE_FUNCTION void operator()( const int i ) const + { + c( i, i ) = micromodulus( i ); + for ( std::size_t j = i; j < num_types; j++ ) { - for ( std::size_t j = i; j < num_types; j++ ) - c( i, j ) = ( micromodulus( i ) + micromodulus( j ) ) / 2.0; - }; - Kokkos::parallel_for( "CabanaPD::Model::Init", policy, - init_cross_func ); + c( i, j ) = ( micromodulus( i ) + micromodulus( j ) ) / 2.0; + // Set symmetric cross-terms. + c( j, i ) = c( i, j ); + } } KOKKOS_INLINE_FUNCTION @@ -217,13 +222,11 @@ struct ForceModel template void setParameters( const ArrayType& _G0 ) { - // Initialize self interaction parameters. - auto init_self_func = KOKKOS_CLASS_LAMBDA( const int i ) + // Initialize per-type variables. + auto G0_copy = G0; + auto init_self_func = KOKKOS_LAMBDA( const int i ) { - G0( i ) = _G0[i]; - s0( i, i ) = criticalStretch( i ); - bond_break_coeff( i, i ) = - ( 1.0 + s0( i, i ) ) * ( 1.0 + s0( i, i ) ); + G0_copy( i ) = _G0[i]; }; using exec_space = typename memory_space::execution_space; Kokkos::RangePolicy policy( 0, num_types ); @@ -231,17 +234,23 @@ struct ForceModel Kokkos::fence(); // Initialize cross-terms. - auto init_cross_func = KOKKOS_CLASS_LAMBDA( const int i ) + Kokkos::parallel_for( "CabanaPD::Model::Init", policy, *this ); + } + + KOKKOS_INLINE_FUNCTION void operator()( const int i ) const + { + s0( i, i ) = criticalStretch( i ); + bond_break_coeff( i, i ) = ( 1.0 + s0( i, i ) ) * ( 1.0 + s0( i, i ) ); + + for ( std::size_t j = i; j < num_types; j++ ) { - for ( std::size_t j = i; j < num_types; j++ ) - { - s0( i, j ) = criticalStretch( i, j ); - bond_break_coeff( i, j ) = - ( 1.0 + s0( i, j ) ) * ( 1.0 + s0( i, j ) ); - } - }; - Kokkos::parallel_for( "CabanaPD::Model::Init", policy, - init_cross_func ); + s0( i, j ) = criticalStretch( i, j ); + bond_break_coeff( i, j ) = + ( 1.0 + s0( i, j ) ) * ( 1.0 + s0( i, j ) ); + // Set symmetric cross-terms. + s0( j, i ) = s0( i, j ); + bond_break_coeff( j, i ) = bond_break_coeff( i, j ); + } } KOKKOS_INLINE_FUNCTION