-
Notifications
You must be signed in to change notification settings - Fork 59
Closed
Labels
Description
Lifted from #298 for brevity.
Proposal
Provide a single context type as a mapped descriptor for the combination of resources used in the context, e.g. a valid combination of device(s). (Somewhat analogous to the adapter plus device(s) concept in Web GPU.)
enum MLContextType {
"cpu", // script-controlled context
"gpu" // script-controlled context
"webgpu", // managed by the user agent
// later other context types may be defined, even using multiple devices, e.g. "cpu+npu" etc.
// Note: in fact all these context types could be separate interface classes as well...
};
enum MLPowerPreference { // a hint
"default",
"high-performance",
"low-power"
};
dictionary MLContextOptions { // not a hint
MLContextType contextType = "cpu";
MLPowerPreference powerPreference = "default";
GPUDevice? gpuDevice = null;
};
[SecureContext, Exposed=(Window, DedicatedWorker)]
interface ML {
Promise<MLContext> createContext(optional MLContextOptions options);
[Exposed=(DedicatedWorker)]
MLContext createContextSync(optional MLContextOptions options);
// Internal slots
// [[boolean managed]] // `true` if the user agent controls the context (not really needed)
// [[MLContextType contextType]]
// [[MLPowerPreference powerPreference]]
// [[implementation]] // perhaps "adapter" would be better
// further methods (and eventually properties) will follow
};Rationale for change
- Including WebGPU into context options would allow a single definition of
createContext(), - handle the current context types ("default" and "webgpu") and also the current device types ("cpu" and "gpu") and possibly other (and combined) device types in the future. That way, it would simplify and minimize algorithms.
- This would simplify the issues mentioned in
Context-based graph execution methods for different threading models. #257,
Define graph execution methods used in different threading models. #255,
Add support for device selection #162.
Related to #303.
Reactions are currently unavailable