Introduce a dedicated process for (potentially) hardware accelerated inference
Categories
(Core :: Machine Learning: On Device, enhancement, P2)
Tracking
()
| Tracking | Status | |
|---|---|---|
| firefox156 | --- | fixed |
People
(Reporter: padenot, Assigned: padenot)
References
(Blocks 4 open bugs)
Details
Attachments
(9 external files, 2 obsolete files)
Splitting this off from bug 1940906 for clarity, this is about introducing the HWInference utility process. The name might change, the concept stays.
| Assignee | ||
Updated•4 months ago
|
| Assignee | ||
Comment 1•4 months ago
|
||
This is essentially a copy-paste of the GPU process policy, trimmed down
to removed everything that wasn't needed. One thing that has been added
is read/write permissions to the /plugincontainer directory so shader
compilation caching works.
We have discussed changing the executable name to relinquish allowing
executable page, this hasn't been implemented.
This also include just enough code so that it compiles and run on Linux,
but that side needs work.
Updated•4 months ago
|
| Assignee | ||
Comment 2•4 months ago
|
||
The HWInference process is a new type of process, that is created from a
content process (e.g. to implement a Web API), but can also talk to the
main process (e.g. to interact with ModelHub and acquire ML models).
It doesn't run script. It has a dedicated sandbox policy (in a
subsequent patch), that is roughly similar to the GPU process policy,
with everything related to graphics rendering removed (connection to the
display server, access to fonts, misc system calls and privileges,
etc.), as it is just for hardware accelerated computations.
This patch only contains the scaffolding, and the first actor
(PSpeechRecognition) will be introduced in another patch.
| Assignee | ||
Comment 3•4 months ago
|
||
This allows calling into ModelHub from native code. This also adds a
couple testing facilities, and a little bit of formatting fixes.
The testing facilities allow almost end-to-end testing of some
Web Speech API feature, testing all the IPC, but sidestepping the very
last part about having an actual model.
Only the facilities SpeechRecognition needs are exposed via this small
XPCOM component: check availability, download a mode, with progress
callbacks, and getting an fd for a model file stored in ModelHub.
Updated•4 months ago
|
| Assignee | ||
Comment 4•4 months ago
|
||
| Assignee | ||
Comment 5•4 months ago
|
||
| Assignee | ||
Comment 6•4 months ago
|
||
This is be later used when initializing the speech recognition backend.
The files range from a hundreds megabyte to multiple gigabytes
(depending on the quality and how many languages they can handle), so we
really need to avoid a copy here.
| Assignee | ||
Updated•4 months ago
|
Updated•4 months ago
|
Updated•4 months ago
|
| Assignee | ||
Comment 8•4 months ago
|
||
The Windows sandbox for HW_INFERENCE inherited UtilitySandboxProps'
defaults, which blocked loading our vendored, non-Microsoft-signed
mozinference.dll in two ways:
- Code Integrity Guard (MITIGATION_FORCE_MS_SIGNED_BINS) rejects
loading any binary that isn't Microsoft-signed. - Even with CIG disabled, the sandbox broker's file-access policy is
default-deny: nothing granted HW_INFERENCE read access to its own
installation directory, so the LoadLibrary call still failed.
Content processes hit neither problem: they never enable CIG at all,
and SetSecurityLevelForContentProcess() explicitly grants read access
to the installation directory. This makes HWInferenceSandboxProps do
the same two things - disable CIG and grant that same read-only
directory rule - while leaving the job/token/integrity levels at their
strict defaults, since content processes prove those aren't the
blocker.
Verified with MOZ_LOG=LlamaRuntimeLinker:5 on try: mozinference.dll now
loads and links successfully in the sandboxed process, and
mochitest-speech-recognition is green on Windows, Linux, and macOS.
Updated•4 months ago
|
Updated•4 months ago
|
Updated•4 months ago
|
Updated•4 months ago
|
Updated•4 months ago
|
Comment 9•4 months ago
|
||
The severity field is not set for this bug.
:gregtatum, could you have a look please?
For more information, please visit BugBot documentation.
Updated•4 months ago
|
Updated•4 months ago
|
Updated•4 months ago
|
Updated•4 months ago
|
Updated•4 months ago
|
Updated•4 months ago
|
Updated•4 months ago
|
Updated•4 months ago
|
Updated•4 months ago
|
| Assignee | ||
Comment 10•4 months ago
|
||
The HWInference process, once launched, only ever died at browser shutdown.
UtilityProcessManager now keeps a keep-alive count per process instance key
(AcquireHWInferenceKeepAlive/ReleaseHWInferenceKeepAlive) and shuts the
instance down with CleanShutdown as soon as the last one is released. It is a
plain refcount with no policy of its own; any 'keep it warm' behaviour belongs
to the consumer holding the keep-alive.
The count lives in the main process because that is where
UtilityProcessManager is: HWInferenceManagerParent, which represents 'a
content process is connected', lives in the utility process and cannot shut
its own process down. This mirrors what the WINDOWS_FILE_DIALOG utility
process does with sOpenDialogActors.
Content processes go through PContent: RequestHWInferenceConnection acquires
a keep-alive on success and the new ReleaseHWInferenceConnection drops it.
HWInferenceManagerChild sends exactly one release per successful request, from
ActorDestroy for the endpoint it adopted and immediately for one it had to
discard, since two concurrent requests can race and only the first is bound.
ContentParent counts its own process' share so ActorDestroy can release the
remainder, keeping a crashed content process from pinning the utility process
forever. Parent-process consumers call Acquire/Release directly.
TO MOVE: this is its own patch, to sit immediately after 'Introduce the
HWInference utility process' -- not squashed into it.
| Assignee | ||
Comment 11•3 months ago
|
||
Comment 12•3 months ago
|
||
Based on D268403, NEVER LAND
| Assignee | ||
Comment 13•3 months ago
|
||
As noted in the original patch that used this (D275653), this touches many patches of the
entire series, and I've have liked to see it in one separate diff. I can also fold it
into the patches it touches, now or prior to landing.
A managed actor is bound to its manager thread, so PSpeechRecognition managed by
PHWInferenceManager meant the first consumer to connect picked the thread for
all the others. PHWInferenceManager now creates the connection instead of
managing it: CreateSpeechRecognition() returns an Endpoint<PSpeechRecognitionChild>
the consumer binds where it wants. The manager moves to the main thread in both
processes; speech keeps its dedicated thread for the session actor.
The shared connection also had no owner: speech closed it when its own users hit
zero. It is refcounted by HWInferenceConnectionGuard now, and speech holds one
guard. Per-feature users and idle policy stay with the feature, since those
genuinely differ.
The utility now attaches the ContentParentId from the parent to
SpeechRecognitionParent at creation, since the managed relationship no longer
carries it.
Teardown is an explicit Close(), and session creation costs one round trip, so
Start() and the transient-session path resolve a promise instead of returning an
actor synchronously. This is perfectly fine.
Comment 14•3 months ago
|
||
Comment 15•3 months ago
|
||
| bugherder | ||
https://hg.mozilla.org/mozilla-central/rev/56742e925f81
https://hg.mozilla.org/mozilla-central/rev/fa3f3a4aaea0
https://hg.mozilla.org/mozilla-central/rev/c5c2c38183e2
https://hg.mozilla.org/mozilla-central/rev/c8ea8bf093c2
https://hg.mozilla.org/mozilla-central/rev/4b1566881bb7
https://hg.mozilla.org/mozilla-central/rev/a624029f63d0
https://hg.mozilla.org/mozilla-central/rev/4738cfcf61a6
https://hg.mozilla.org/mozilla-central/rev/b6c1f3457ae2
https://hg.mozilla.org/mozilla-central/rev/7a4e3a181bf1
Updated•2 months ago
|
Updated•2 months ago
|
Updated•2 months ago
|
Description
•