Compute Library
 21.11
arm_compute::scheduler_utils Namespace Reference

Functions

std::pair< unsigned, unsigned > split_2d (unsigned max_threads, std::size_t m, std::size_t n)
 Given two dimensions and a maximum number of threads to utilise, calculate the best combination of threads that fit in (multiplied together) max_threads. More...
 

Function Documentation

◆ split_2d()

std::pair< unsigned, unsigned > split_2d ( unsigned  max_threads,
std::size_t  m,
std::size_t  n 
)

Given two dimensions and a maximum number of threads to utilise, calculate the best combination of threads that fit in (multiplied together) max_threads.

This algorithm assumes that work in either of the dimensions is equally difficult to compute

Returns
[m_nthreads, n_nthreads] A pair of the threads that should be used in each dimension

Definition at line 35 of file SchedulerUtils.cpp.

References arm_compute::test::validation::m, arm_compute::test::validation::n, and arm_compute::round().

Referenced by IScheduler::num_threads_hint().

36 {
37  /*
38  * We want the same ratio of threads in M & N to the ratio of m and n problem size
39  *
40  * Therefore: mt/nt == m/n where mt*nt == max_threads
41  *
42  * max_threads/nt = mt & (max_threads/nt) * (m/n) = nt
43  * nt^2 = max_threads * (m/n)
44  * nt = sqrt( max_threads * (m/n) )
45  */
46  //ratio of m to n in problem dimensions
47  double ratio = m / static_cast<double>(n);
48 
49  // nt = sqrt(max_threads * (m / n) )
50  const unsigned adjusted = std::round(
51  std::sqrt(max_threads * ratio));
52 
53  //find the nearest factor of max_threads
54  for(unsigned i = 0; i != adjusted; ++i)
55  {
56  //try down
57  const unsigned adj_down = adjusted - i;
58  if(max_threads % adj_down == 0)
59  {
60  return { adj_down, max_threads / adj_down };
61  }
62 
63  //try up
64  const unsigned adj_up = adjusted + i;
65  if(max_threads % adj_up == 0)
66  {
67  return { adj_up, max_threads / adj_up };
68  }
69  }
70 
71  //we didn't find anything so lets bail out with maxes biased to the largest dimension
72  if(m > n)
73  {
74  return { std::min<unsigned>(m, max_threads), 1 };
75  }
76  else
77  {
78  return { 1, std::min<unsigned>(n, max_threads) };
79  }
80 }
int round(float x, RoundingPolicy rounding_policy)
Return a rounded value of x.
Definition: Rounding.cpp:35