Skip to content

Commit

Permalink
Update hexagon max_concurrency to be at most equal to the number of H…
Browse files Browse the repository at this point in the history
…VX units available. (apache#12394)
  • Loading branch information
nverke committed Aug 12, 2022
1 parent 3eb6734 commit 57a02f7
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions src/runtime/threading_backend.cc
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@
#include <sched.h>
#endif
#if defined(__hexagon__)
extern "C" {
#include <qurt_hvx.h>
}
#include <dlfcn.h>
#include <qurt.h>
#include <stdlib.h>
Expand Down Expand Up @@ -381,15 +384,26 @@ int MaxConcurrency() {
#if defined(_M_X64) || defined(__x86_64__)
max_concurrency /= 2; // ignore hyper-threading
#elif defined(__hexagon__)
// Ideally max_concurrency is set to the total count of 128B
// HVX units available. This prevenets threads unable to lock
// an HVX unit from scheduling work on the Scalar cores instead
// of HVX.
int num_hvx128_contexts = (qurt_hvx_get_units() >> 8) & 0xFF;
// With unsigned PDs, getting the number of available hardware threads
// is not supported in earlier versions of QuRT. In such cases assume 4.
// If running on simulator, set max_concurrency to 1.
// is not supported in earlier versions of QuRT. In such cases assume
// the number of HVX units available. If running on simulator, set
// max_concurrency to 1.
if (max_concurrency == 0) {
if (dlsym(RTLD_DEFAULT, "running_in_sim_dev_17bc90206f6cf5a7")) {
max_concurrency = 1;
} else {
max_concurrency = 4;
max_concurrency = num_hvx128_contexts;
}
} else {
// If the hardware_concurrency has already set the max_concurrency to
// a non-zero value then make sure it is not greater than the number
// of HVX units available.
max_concurrency = std::min(num_hvx128_contexts, max_concurrency);
}
#endif
}
Expand Down

0 comments on commit 57a02f7

Please sign in to comment.