Update Kokkos library to r2.6.00
This commit is contained in:
@ -35,7 +35,7 @@
|
||||
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
// Questions? Contact H. Carter Edwards (hcedwar@sandia.gov)
|
||||
// Questions? Contact Christian R. Trott (crtrott@sandia.gov)
|
||||
//
|
||||
// ************************************************************************
|
||||
//@HEADER
|
||||
@ -61,114 +61,181 @@ struct TestDynamicView
|
||||
typedef typename Space::execution_space execution_space ;
|
||||
typedef typename Space::memory_space memory_space ;
|
||||
|
||||
typedef Kokkos::MemoryPool<typename Space::device_type> memory_pool_type;
|
||||
|
||||
typedef Kokkos::Experimental::DynamicView<Scalar*,Space> view_type;
|
||||
typedef typename view_type::const_type const_view_type ;
|
||||
|
||||
typedef typename Kokkos::TeamPolicy<execution_space>::member_type member_type ;
|
||||
typedef double value_type;
|
||||
|
||||
struct TEST {};
|
||||
struct VERIFY {};
|
||||
|
||||
view_type a;
|
||||
const unsigned total_size ;
|
||||
|
||||
TestDynamicView( const view_type & arg_a , const unsigned arg_total )
|
||||
: a(arg_a), total_size( arg_total ) {}
|
||||
|
||||
KOKKOS_INLINE_FUNCTION
|
||||
void operator() ( const TEST , member_type team_member, double& value) const
|
||||
{
|
||||
const unsigned int team_idx = team_member.league_rank() * team_member.team_size();
|
||||
|
||||
if ( team_member.team_rank() == 0 ) {
|
||||
unsigned n = team_idx + team_member.team_size();
|
||||
|
||||
if ( total_size < n ) n = total_size ;
|
||||
|
||||
a.resize_parallel( n );
|
||||
|
||||
if ( a.extent(0) < n ) {
|
||||
Kokkos::abort("GrowTest TEST failed resize_parallel");
|
||||
}
|
||||
}
|
||||
|
||||
// Make sure resize is done for all team members:
|
||||
team_member.team_barrier();
|
||||
|
||||
const unsigned int val = team_idx + team_member.team_rank();
|
||||
|
||||
if ( val < total_size ) {
|
||||
value += val ;
|
||||
|
||||
a( val ) = val ;
|
||||
}
|
||||
}
|
||||
|
||||
KOKKOS_INLINE_FUNCTION
|
||||
void operator() ( const VERIFY , member_type team_member, double& value) const
|
||||
{
|
||||
const unsigned int val =
|
||||
team_member.team_rank() +
|
||||
team_member.league_rank() * team_member.team_size();
|
||||
|
||||
if ( val < total_size ) {
|
||||
|
||||
if ( val != a(val) ) {
|
||||
Kokkos::abort("GrowTest VERIFY failed resize_parallel");
|
||||
}
|
||||
|
||||
value += a(val);
|
||||
}
|
||||
}
|
||||
|
||||
static void run( unsigned arg_total_size )
|
||||
{
|
||||
typedef Kokkos::TeamPolicy<execution_space,TEST> TestPolicy ;
|
||||
typedef Kokkos::TeamPolicy<execution_space,VERIFY> VerifyPolicy ;
|
||||
// Test: Create DynamicView, initialize size (via resize), run through parallel_for to set values, check values (via parallel_reduce); resize values and repeat
|
||||
// Case 1: min_chunk_size is a power of 2
|
||||
{
|
||||
view_type da("da", 1024, arg_total_size );
|
||||
ASSERT_EQ( da.size(), 0 );
|
||||
// Init
|
||||
unsigned da_size = arg_total_size / 8;
|
||||
da.resize_serial(da_size);
|
||||
ASSERT_EQ( da.size(), da_size );
|
||||
|
||||
// printf("TestDynamicView::run(%d) construct memory pool\n",arg_total_size);
|
||||
#if defined( KOKKOS_ENABLE_CXX11_DISPATCH_LAMBDA )
|
||||
#if !defined(KOKKOS_ENABLE_CUDA) || ( 8000 <= CUDA_VERSION )
|
||||
Kokkos::parallel_for( Kokkos::RangePolicy<execution_space>(0, da_size), KOKKOS_LAMBDA ( const int i )
|
||||
{
|
||||
da(i) = Scalar(i);
|
||||
}
|
||||
);
|
||||
|
||||
const size_t total_alloc_size = arg_total_size * sizeof(Scalar) * 1.2 ;
|
||||
const size_t superblock = std::min( total_alloc_size , size_t(1000000) );
|
||||
value_type result_sum = 0.0;
|
||||
Kokkos::parallel_reduce( Kokkos::RangePolicy<execution_space>(0, da_size), KOKKOS_LAMBDA ( const int i, value_type& partial_sum )
|
||||
{
|
||||
partial_sum += (value_type)da(i);
|
||||
}
|
||||
, result_sum
|
||||
);
|
||||
|
||||
memory_pool_type pool( memory_space()
|
||||
, total_alloc_size
|
||||
, 500 /* min block size in bytes */
|
||||
, 30000 /* max block size in bytes */
|
||||
, superblock
|
||||
);
|
||||
ASSERT_EQ(result_sum, (value_type)( da_size * (da_size - 1) / 2 ) );
|
||||
#endif
|
||||
#endif
|
||||
|
||||
// printf("TestDynamicView::run(%d) construct dynamic view\n",arg_total_size);
|
||||
// add 3x more entries i.e. 4x larger than previous size
|
||||
// the first 1/4 should remain the same
|
||||
unsigned da_resize = arg_total_size / 2;
|
||||
da.resize_serial(da_resize);
|
||||
ASSERT_EQ( da.size(), da_resize );
|
||||
|
||||
view_type da("A",pool,arg_total_size);
|
||||
#if defined( KOKKOS_ENABLE_CXX11_DISPATCH_LAMBDA )
|
||||
#if !defined(KOKKOS_ENABLE_CUDA) || ( 8000 <= CUDA_VERSION )
|
||||
Kokkos::parallel_for( Kokkos::RangePolicy<execution_space>(da_size, da_resize), KOKKOS_LAMBDA ( const int i )
|
||||
{
|
||||
da(i) = Scalar(i);
|
||||
}
|
||||
);
|
||||
|
||||
const_view_type ca(da);
|
||||
value_type new_result_sum = 0.0;
|
||||
Kokkos::parallel_reduce( Kokkos::RangePolicy<execution_space>(da_size, da_resize), KOKKOS_LAMBDA ( const int i, value_type& partial_sum )
|
||||
{
|
||||
partial_sum += (value_type)da(i);
|
||||
}
|
||||
, new_result_sum
|
||||
);
|
||||
|
||||
// printf("TestDynamicView::run(%d) construct test functor\n",arg_total_size);
|
||||
ASSERT_EQ(new_result_sum+result_sum, (value_type)( da_resize * (da_resize - 1) / 2 ) );
|
||||
#endif
|
||||
#endif
|
||||
} // end scope
|
||||
|
||||
TestDynamicView functor(da,arg_total_size);
|
||||
// Test: Create DynamicView, initialize size (via resize), run through parallel_for to set values, check values (via parallel_reduce); resize values and repeat
|
||||
// Case 2: min_chunk_size is NOT a power of 2
|
||||
{
|
||||
view_type da("da", 1023, arg_total_size );
|
||||
ASSERT_EQ( da.size(), 0 );
|
||||
// Init
|
||||
unsigned da_size = arg_total_size / 8;
|
||||
da.resize_serial(da_size);
|
||||
ASSERT_EQ( da.size(), da_size );
|
||||
|
||||
const unsigned team_size = TestPolicy::team_size_recommended(functor);
|
||||
const unsigned league_size = ( arg_total_size + team_size - 1 ) / team_size ;
|
||||
#if defined( KOKKOS_ENABLE_CXX11_DISPATCH_LAMBDA )
|
||||
#if !defined(KOKKOS_ENABLE_CUDA) || ( 8000 <= CUDA_VERSION )
|
||||
Kokkos::parallel_for( Kokkos::RangePolicy<execution_space>(0, da_size), KOKKOS_LAMBDA ( const int i )
|
||||
{
|
||||
da(i) = Scalar(i);
|
||||
}
|
||||
);
|
||||
|
||||
double reference = 0;
|
||||
double result = 0;
|
||||
value_type result_sum = 0.0;
|
||||
Kokkos::parallel_reduce( Kokkos::RangePolicy<execution_space>(0, da_size), KOKKOS_LAMBDA ( const int i, value_type& partial_sum )
|
||||
{
|
||||
partial_sum += (value_type)da(i);
|
||||
}
|
||||
, result_sum
|
||||
);
|
||||
|
||||
// printf("TestDynamicView::run(%d) run functor test\n",arg_total_size);
|
||||
ASSERT_EQ(result_sum, (value_type)( da_size * (da_size - 1) / 2 ) );
|
||||
#endif
|
||||
#endif
|
||||
|
||||
Kokkos::parallel_reduce( TestPolicy(league_size,team_size) , functor , reference);
|
||||
execution_space::fence();
|
||||
// add 3x more entries i.e. 4x larger than previous size
|
||||
// the first 1/4 should remain the same
|
||||
unsigned da_resize = arg_total_size / 2;
|
||||
da.resize_serial(da_resize);
|
||||
ASSERT_EQ( da.size(), da_resize );
|
||||
|
||||
#if defined( KOKKOS_ENABLE_CXX11_DISPATCH_LAMBDA )
|
||||
#if !defined(KOKKOS_ENABLE_CUDA) || ( 8000 <= CUDA_VERSION )
|
||||
Kokkos::parallel_for( Kokkos::RangePolicy<execution_space>(da_size, da_resize), KOKKOS_LAMBDA ( const int i )
|
||||
{
|
||||
da(i) = Scalar(i);
|
||||
}
|
||||
);
|
||||
|
||||
// printf("TestDynamicView::run(%d) run functor verify\n",arg_total_size);
|
||||
value_type new_result_sum = 0.0;
|
||||
Kokkos::parallel_reduce( Kokkos::RangePolicy<execution_space>(da_size, da_resize), KOKKOS_LAMBDA ( const int i, value_type& partial_sum )
|
||||
{
|
||||
partial_sum += (value_type)da(i);
|
||||
}
|
||||
, new_result_sum
|
||||
);
|
||||
|
||||
Kokkos::parallel_reduce( VerifyPolicy(league_size,team_size) , functor , result );
|
||||
execution_space::fence();
|
||||
ASSERT_EQ(new_result_sum+result_sum, (value_type)( da_resize * (da_resize - 1) / 2 ) );
|
||||
#endif
|
||||
#endif
|
||||
} // end scope
|
||||
|
||||
// printf("TestDynamicView::run(%d) done\n",arg_total_size);
|
||||
// Test: Create DynamicView, initialize size (via resize), run through parallel_for to set values, check values (via parallel_reduce); resize values and repeat
|
||||
// Case 3: resize reduces the size
|
||||
{
|
||||
view_type da("da", 1023, arg_total_size );
|
||||
ASSERT_EQ( da.size(), 0 );
|
||||
// Init
|
||||
unsigned da_size = arg_total_size / 2;
|
||||
da.resize_serial(da_size);
|
||||
ASSERT_EQ( da.size(), da_size );
|
||||
|
||||
#if defined( KOKKOS_ENABLE_CXX11_DISPATCH_LAMBDA )
|
||||
#if !defined(KOKKOS_ENABLE_CUDA) || ( 8000 <= CUDA_VERSION )
|
||||
Kokkos::parallel_for( Kokkos::RangePolicy<execution_space>(0, da_size), KOKKOS_LAMBDA ( const int i )
|
||||
{
|
||||
da(i) = Scalar(i);
|
||||
}
|
||||
);
|
||||
|
||||
value_type result_sum = 0.0;
|
||||
Kokkos::parallel_reduce( Kokkos::RangePolicy<execution_space>(0, da_size), KOKKOS_LAMBDA ( const int i, value_type& partial_sum )
|
||||
{
|
||||
partial_sum += (value_type)da(i);
|
||||
}
|
||||
, result_sum
|
||||
);
|
||||
|
||||
ASSERT_EQ(result_sum, (value_type)( da_size * (da_size - 1) / 2 ) );
|
||||
#endif
|
||||
#endif
|
||||
|
||||
// remove the final 3/4 entries i.e. first 1/4 remain
|
||||
unsigned da_resize = arg_total_size / 8;
|
||||
da.resize_serial(da_resize);
|
||||
ASSERT_EQ( da.size(), da_resize );
|
||||
|
||||
#if defined( KOKKOS_ENABLE_CXX11_DISPATCH_LAMBDA )
|
||||
#if !defined(KOKKOS_ENABLE_CUDA) || ( 8000 <= CUDA_VERSION )
|
||||
Kokkos::parallel_for( Kokkos::RangePolicy<execution_space>(0, da_resize), KOKKOS_LAMBDA ( const int i )
|
||||
{
|
||||
da(i) = Scalar(i);
|
||||
}
|
||||
);
|
||||
|
||||
value_type new_result_sum = 0.0;
|
||||
Kokkos::parallel_reduce( Kokkos::RangePolicy<execution_space>(0, da_resize), KOKKOS_LAMBDA ( const int i, value_type& partial_sum )
|
||||
{
|
||||
partial_sum += (value_type)da(i);
|
||||
}
|
||||
, new_result_sum
|
||||
);
|
||||
|
||||
ASSERT_EQ(new_result_sum, (value_type)( da_resize * (da_resize - 1) / 2 ) );
|
||||
#endif
|
||||
#endif
|
||||
} // end scope
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user