MCPcopy Create free account
hub / github.com/ARM-software/ComputeLibrary / split_2d

Function split_2d

src/runtime/SchedulerUtils.cpp:35–79  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

33{
34#ifndef BARE_METAL
35std::pair<unsigned, unsigned> split_2d(unsigned max_threads, std::size_t m, std::size_t n)
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(std::sqrt(max_threads * ratio));
51
52 //find the nearest factor of max_threads
53 for (unsigned i = 0; i != adjusted; ++i)
54 {
55 //try down
56 const unsigned adj_down = adjusted - i;
57 if (max_threads % adj_down == 0)
58 {
59 return {adj_down, max_threads / adj_down};
60 }
61
62 //try up
63 const unsigned adj_up = adjusted + i;
64 if (max_threads % adj_up == 0)
65 {
66 return {adj_up, max_threads / adj_up};
67 }
68 }
69
70 //we didn't find anything so lets bail out with maxes biased to the largest dimension
71 if (m > n)
72 {
73 return {std::min<unsigned>(m, max_threads), 1};
74 }
75 else
76 {
77 return {1, std::min<unsigned>(n, max_threads)};
78 }
79}
80#endif /* #ifndef BARE_METAL */
81} // namespace scheduler_utils
82} // namespace arm_compute

Callers 1

schedule_commonMethod · 0.85

Calls 2

sqrtFunction · 0.85
roundFunction · 0.50

Tested by

no test coverage detected