Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cap hexagon max con to number of HVX units #12394

Merged
merged 1 commit into from
Aug 12, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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