SharedAllocationRecord< Kokkos::HostSpace , void >::
SharedAllocationRecord( const Kokkos::HostSpace & arg_space
                      , const std::string       & arg_label
                      , const size_t              arg_alloc_size
                      , const SharedAllocationRecord< void , void >::function_type arg_dealloc
                      )
  // Pass through allocated [ SharedAllocationHeader , user_memory ]
  // Pass through deallocation function
  : SharedAllocationRecord< void , void >
      (
#ifdef KOKKOS_DEBUG
      & SharedAllocationRecord< Kokkos::HostSpace , void >::s_root_record,
#endif
        reinterpret_cast<SharedAllocationHeader*>( arg_space.allocate( sizeof(SharedAllocationHeader) + arg_alloc_size ) )
      , sizeof(SharedAllocationHeader) + arg_alloc_size
      , arg_dealloc
      )
  , m_space( arg_space )
{
#if defined(KOKKOS_ENABLE_PROFILING)
  if(Kokkos::Profiling::profileLibraryLoaded()) {
    Kokkos::Profiling::allocateData(Kokkos::Profiling::SpaceHandle(arg_space.name()),arg_label,data(),arg_alloc_size);
   }
#endif
  // Fill in the Header information
  RecordBase::m_alloc_ptr->m_record = static_cast< SharedAllocationRecord< void , void > * >( this );

  strncpy( RecordBase::m_alloc_ptr->m_label
          , arg_label.c_str()
          , SharedAllocationHeader::maximum_label_length
          );
}
Beispiel #2
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);
  }
}
Beispiel #3
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
}
SharedAllocationRecord< Kokkos::HostSpace , void >::
SharedAllocationRecord( const Kokkos::HostSpace & arg_space
                      , const std::string       & arg_label
                      , const size_t              arg_alloc_size
                      , const SharedAllocationRecord< void , void >::function_type arg_dealloc
                      )
  // Pass through allocated [ SharedAllocationHeader , user_memory ]
  // Pass through deallocation function
  : SharedAllocationRecord< void , void >
      ( & SharedAllocationRecord< Kokkos::HostSpace , void >::s_root_record
      , reinterpret_cast<SharedAllocationHeader*>( arg_space.allocate( sizeof(SharedAllocationHeader) + arg_alloc_size ) )
      , sizeof(SharedAllocationHeader) + arg_alloc_size
      , arg_dealloc
      )
  , m_space( arg_space )
{
  // Fill in the Header information
  RecordBase::m_alloc_ptr->m_record = static_cast< SharedAllocationRecord< void , void > * >( this );

  strncpy( RecordBase::m_alloc_ptr->m_label
          , arg_label.c_str()
          , SharedAllocationHeader::maximum_label_length
          );
}