示例#1
0
// Resize thread team data scratch memory
void serial_resize_thread_team_data( size_t pool_reduce_bytes
                                   , size_t team_reduce_bytes
                                   , size_t team_shared_bytes
                                   , size_t thread_local_bytes )
{
  if ( pool_reduce_bytes < 512 ) pool_reduce_bytes = 512 ;
  if ( team_reduce_bytes < 512 ) team_reduce_bytes = 512 ;

  const size_t old_pool_reduce  = g_serial_thread_team_data.pool_reduce_bytes();
  const size_t old_team_reduce  = g_serial_thread_team_data.team_reduce_bytes();
  const size_t old_team_shared  = g_serial_thread_team_data.team_shared_bytes();
  const size_t old_thread_local = g_serial_thread_team_data.thread_local_bytes();
  const size_t old_alloc_bytes  = g_serial_thread_team_data.scratch_bytes();

  // Allocate if any of the old allocation is tool small:

  const bool allocate = ( old_pool_reduce  < pool_reduce_bytes ) ||
                        ( old_team_reduce  < team_reduce_bytes ) ||
                        ( old_team_shared  < team_shared_bytes ) ||
                        ( old_thread_local < thread_local_bytes );

  if ( allocate ) {

    Kokkos::HostSpace space ;

    if ( old_alloc_bytes ) {
      g_serial_thread_team_data.disband_team();
      g_serial_thread_team_data.disband_pool();

      space.deallocate( g_serial_thread_team_data.scratch_buffer()
                      , g_serial_thread_team_data.scratch_bytes() );
    }

    if ( pool_reduce_bytes < old_pool_reduce ) { pool_reduce_bytes = old_pool_reduce ; }
    if ( team_reduce_bytes < old_team_reduce ) { team_reduce_bytes = old_team_reduce ; }
    if ( team_shared_bytes < old_team_shared ) { team_shared_bytes = old_team_shared ; }
    if ( thread_local_bytes < old_thread_local ) { thread_local_bytes = old_thread_local ; }

    const size_t alloc_bytes =
      HostThreadTeamData::scratch_size( pool_reduce_bytes
                                      , team_reduce_bytes
                                      , team_shared_bytes
                                      , thread_local_bytes );

    void * const ptr = space.allocate( alloc_bytes );

    g_serial_thread_team_data.
      scratch_assign( ((char *)ptr)
                    , alloc_bytes
                    , pool_reduce_bytes
                    , team_reduce_bytes
                    , team_shared_bytes
                    , thread_local_bytes );

    HostThreadTeamData * pool[1] = { & g_serial_thread_team_data };

    g_serial_thread_team_data.organize_pool( pool , 1 );
    g_serial_thread_team_data.organize_team(1);
  }
}
示例#2
0
void Serial::finalize()
{
  if ( Impl::g_serial_thread_team_data.scratch_buffer() ) {
    Impl::g_serial_thread_team_data.disband_team();
    Impl::g_serial_thread_team_data.disband_pool();

    Kokkos::HostSpace space ;

    space.deallocate( Impl::g_serial_thread_team_data.scratch_buffer()
                    , Impl::g_serial_thread_team_data.scratch_bytes() );

    Impl::g_serial_thread_team_data.scratch_assign( (void*) 0, 0, 0, 0, 0, 0 );
  }

  #if defined(KOKKOS_ENABLE_PROFILING)
    Kokkos::Profiling::finalize();
  #endif
}