Skip to content

Commit

Permalink
[Executorch][llama] Set # of threads to use performant cores
Browse files Browse the repository at this point in the history
When using all cores, slower ones are dragging the performance down by blocking
large cores. Perhaps when we have uarch specific implementation, we may not
need this, but this tool is useful in general until we have better API

Differential Revision: [D54766071](https://our.internmc.facebook.com/intern/diff/D54766071/)

[ghstack-poisoned]
  • Loading branch information
kimishpatel committed Mar 11, 2024
1 parent 2728d9c commit d6a3897
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
9 changes: 9 additions & 0 deletions examples/models/llama2/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@

#include <executorch/examples/models/llama2/runner/runner.h>

#include <executorch/backends/xnnpack/threadpool/cpuinfo_utils.h>
#include <executorch/backends/xnnpack/threadpool/threadpool.h>

DEFINE_string(
model_path,
"llama2.pte",
Expand Down Expand Up @@ -45,6 +48,12 @@ int32_t main(int32_t argc, char** argv) {

int32_t seq_len = FLAGS_seq_len;

uint32_t num_performant_cores =
torch::executorch::cpuinfo::get_num_performant_cores();
ET_LOG(
Info, "Resetting threadpool with num threads = %d", num_performant_cores);
torch::executorch::threadpool::get_threadpool()->_reset_threadpool(
num_performant_cores);
// create llama runner
::torch::executor::Runner runner(model_path, tokenizer_path, temperature);

Expand Down
2 changes: 2 additions & 0 deletions examples/models/llama2/targets.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ def define_common_targets():
deps = [
"//executorch/examples/models/llama2/runner:runner" + aten_suffix,
"//executorch/extension/evalue_util:print_evalue",
"//executorch/backends/xnnpack/threadpool:threadpool",
"//executorch/backends/xnnpack/threadpool:cpuinfo_utils",
],
external_deps = [
"gflags",
Expand Down

0 comments on commit d6a3897

Please sign in to comment.