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...

## ◆ 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

Definition at line 35 of file SchedulerUtils.cpp.

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  *
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(
52
53  //find the nearest factor of max_threads
54  for(unsigned i = 0; i != adjusted; ++i)
55  {
56  //try down
59  {
61  }
62
63  //try up
66  {
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