cpp/src/traversal/tsp_utils.hpp
// Get maximum number of threads we can run on based on number of nodes,
// shared memory usage, max threads per block and SM, max blocks for SM and registers per SM.
Get maximum number of threads we can run on based on number of nodes,
shared memory usage, max threads per block and SM, max blocks for SM and registers per SM.
Get maximum number of threads we can run on based on number of nodes shared memory usage max threads per block and SM max blocks for SM and registers per SM .
int best_thread_count(int nodes, int max_threads, int sm_count, int warp_size)
{
  int smem, blocks, thr, perf;
  int const max_threads_sm = 2048;
  int max                  = nodes - 2;
  int best                 = 0;
  int bthr                 = 4;
  if (max > max_threads) max = max_threads;
  for (int threads = 1; threads <= max; ++threads) {
    smem   = sizeof(int) * threads + 2 * sizeof(float) * tilesize + sizeof(int) * tilesize;
    blocks = (16384 * 2) / smem;
    if (blocks > sm_count) blocks = sm_count;
    thr = (threads + warp_size - 1) / warp_size * warp_size;
    while (blocks * thr > max_threads_sm) blocks--;
    perf = threads * blocks;
    if (perf > best) {
      best = perf;
      bthr = threads;
    }
  }
  return bthr;
}
int best_thread_count ( int nodes , int max_threads , int sm_count , int warp_size ) { int smem , blocks , thr , perf ; int const max_threads_sm = 2048 ; int max = nodes - 2 ; int best = 0 ; int bthr = 4 ; if ( max > max_threads ) max = max_threads ; for ( int threads = 1 ; threads <= max ; ++ threads ) { smem = sizeof ( int ) * threads + 2 * sizeof ( float ) * tilesize + sizeof ( int ) * tilesize ; blocks = ( 16384 * 2 ) / smem ; if ( blocks > sm_count ) blocks = sm_count ; thr = ( threads + warp_size - 1 ) / warp_size * warp_size ; while ( blocks * thr > max_threads_sm ) blocks -- ; perf = threads * blocks ; if ( perf > best ) { best = perf ; bthr = threads ; } } return bthr ; }
Get maximum number of threads we can run on based on number of nodes,
shared memory usage, max threads per block and SM, max blocks for SM and registers per SM.
Get maximum number of threads we can run on based on number of nodes shared memory usage max threads per block and SM max blocks for SM and registers per SM .