Skip to content

core: explicit CPU thread count and compute-device selection for embedders - #112

Open
erichchampion wants to merge 1 commit into
ServeurpersoCom:masterfrom
erichchampion:offer/patch-4-backend-config
Open

core: explicit CPU thread count and compute-device selection for embedders#112
erichchampion wants to merge 1 commit into
ServeurpersoCom:masterfrom
erichchampion:offer/patch-4-backend-config

Conversation

@erichchampion

Copy link
Copy Markdown

Last of four small embedder patches from Cadenza (independent of the other three).

What it does

An embedder today can only steer GGML through the GGML_BACKEND environment variable, and cannot pick a thread count at all. Environment variables are the wrong interface for an app: a GUI cannot ask its user to export one before launch, and a mobile app has no shell at all.

This adds src/backend-config.h: a set-once, unsynchronized configuration object --

ace_backend_configure(/*device*/ "Metal", /*n_threads*/ 4);   // both at once
ace_backend_set_device(...); ace_backend_set_threads(...);     // or one field

-- that backend init reads before its first model load:

  • NULL/"" device means exactly today's behaviour (GGML_BACKEND env var, then auto-best), so the CLIs are unchanged.
  • A positive thread count caps GGML inference threads; <= 0 keeps the auto default.
  • The device name is one ggml registers; a request that matches nothing dies with the available names printed -- and the message says whether the request came from the config API or the env var, so a misconfigured embedder is not sent debugging the wrong knob.
  • The override is clamped to the logical CPU count (preferring Apple's perflevel0.physicalcpu where available, since GEMM shares SIMD units across hyperthreads), and the MP3 export encoder honours the same cap through one shared clamp helper so the two workloads cannot diverge.

Testing

tests/test-backend-config.cpp covers config read-back, clamping, and end-to-end device selection against the real registry (Metal on an Apple-silicon Mac, plus the CPU path). Built and run on macOS/arm64/Metal.

…dders

An embedder today can only steer GGML through the GGML_BACKEND environment
variable, and cannot pick a thread count at all. This adds
src/backend-config.h: a set-once, unsynchronized configuration object --
ace_backend_configure(device, n_threads) plus single-field setters -- that
backend init reads before its first model load. NULL/"" device means the old
behaviour (GGML_BACKEND env var, then auto-best), so the CLIs are unchanged;
a positive thread count caps GGML inference threads, <= 0 keeps the auto
default. The device name is one ggml registers (CUDA0, Vulkan0, Metal, CPU);
a request that matches nothing dies with the available names printed.

Thread clamping: the override is clamped to the logical CPU count (with the
Apple perflevel0 physical count preferred where available, since GEMM shares
SIMD units across hyperthreads), and the MP3 export encoder honours the same
cap through one shared clamp helper so the two workloads cannot diverge.

test-backend-config.cpp covers config-readback, clamping, and end-to-end
device selection against the real registry.
@coderabbitai

coderabbitai Bot commented Sep 7, 2026

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

Next included review available in 59 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used all 2 included reviews currently available.

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Learn how review limits work.

Review configuration:

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Team

Run ID: f550a614-b7ce-4641-9dee-94f80f18467f

📥 Commits

Reviewing files that changed from the base of the PR and between c9045e2 and bc4c10f.

📒 Files selected for processing (5)
  • src/audio-io.h
  • src/backend-config.h
  • src/backend.h
  • tests/CMakeLists.txt
  • tests/test-backend-config.cpp

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant