Skip to content

Commit

Permalink
fixup: remove class lambdas; use local copies + class operators
Browse files Browse the repository at this point in the history
  • Loading branch information
streeve committed Aug 20, 2024
1 parent 8ff96ed commit c089abf
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 41 deletions.
3 changes: 0 additions & 3 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 }} \
Expand Down Expand Up @@ -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 \
Expand Down
34 changes: 24 additions & 10 deletions src/CabanaPD_ForceModels.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,20 @@ struct BaseForceModel
BaseForceModel( const ArrayType& _delta )
: delta( view_type_1d( "delta", _delta.size() ) )
, num_types( _delta.size() )
{
setParameters( _delta );
}

template <typename ArrayType>
void setParameters( const ArrayType& _delta )
{
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<exec_space> policy( 0, num_types );
Expand Down Expand Up @@ -99,7 +106,6 @@ struct BaseTemperatureModel<TemperatureType, SingleSpecies>
// Temperature field
TemperatureType temperature;

BaseTemperatureModel(){};
BaseTemperatureModel( const TemperatureType _temp, const double _alpha,
const double _temp0 )
: alpha( _alpha )
Expand Down Expand Up @@ -131,17 +137,25 @@ struct BaseTemperatureModel
ParticleType type;

template <typename ArrayType>
BaseTemperatureModel( const TemperatureType& _temp, const ArrayType _alpha,
const ArrayType _temp0, const ParticleType& _type )
BaseTemperatureModel( const TemperatureType& _temp, const ArrayType& _alpha,
const ArrayType& _temp0, const ParticleType& _type )
: alpha( view_type_1d( "delta", _alpha.size() ) )
, temp0( view_type_1d( "delta", _temp0.size() ) )
, temperature( _temp )
, type( _type )
{
auto init_func = KOKKOS_CLASS_LAMBDA( const int i )
setParameters( _alpha, _temp0 );
}

template <typename ArrayType>
void setParameters( const ArrayType& _alpha, const ArrayType& _temp0 )
{
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<exec_space> policy( 0, alpha.size() );
Expand Down
65 changes: 37 additions & 28 deletions src/force/CabanaPD_ForceModels_PMB.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,25 +91,30 @@ struct ForceModel<PMB, Elastic, TemperatureIndependent, ParticleType>
template <typename ArrayType>
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<exec_space> 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
Expand Down Expand Up @@ -217,31 +222,35 @@ struct ForceModel<PMB, Fracture, TemperatureIndependent, ParticleType>
template <typename ArrayType>
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<exec_space> policy( 0, num_types );
Kokkos::parallel_for( "CabanaPD::Model::Init", policy, init_self_func );
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
Expand Down

0 comments on commit c089abf

Please sign in to comment.