Skip to content

API review, questions, brainstorming  #298

@zolkis

Description

@zolkis

As a newcomer with fresh/naive eyes, I use this issue to summarize my thoughts, from the perspective of defining future algorithms. I tried to draft some algorithms, and bumped into how context, operators, graph and internal slots are to be exposed and referenced in the spec.

This is a "questions" category issue, no fix is required, please just bear with me and explain stuff, as I've been missing prior discussions. If needed, targeted issues can be spawned.

From the spec:

  • Context objects are created synchronously by a factory method.
    Internal slots are used for storing device type and power prefs as string enums.
  • CPU context has a synchronous compute() method
  • GPU context has sync and async compute(),
    as well as a sync factory method to create a command encoder.
  • MLGraphBuilder is created with constructor, but bound to a single context.
  • Graphs, operators, operands are intermediary constructs / empty interfaces.
  • method overloading is used for returning MLOperator.

From the explainer,

  • A context owns the set of operations supported by a builder, and the way graphs are compiled and executed.

Basically the main workflows that are covered:

  • programmatically build a compute graph
    (though in theory it could be also built based on a JSON or JSON-LD description as well, I do very well understand why a programmatic approach is more practical here).
  • compile a compute graph to obtain an immutable MLGraph (an opaque type)
  • encode an MLGraph to GPUCommandBuffer (only on GPU contexts)
  • execute (compute) a graph asynchronously (GPU) or synchronously (CPU, GPU),
  • integrate the graph with other Web APIs that provide input data to the graph.

To me it seems use cases are revolving around graphs, which leads to the premise they could be the primary interface exposed by the spec.
Mainly first we construct them, and there I am not sure if context is relevant, is this a syntactic construction, or some context dependent optimizations already supposed to happen by specification during the build?

I am checking the implementation to figure out things, but for now I have some questions:

  • Does Context correspond to anything more substantial than string enum options for device (CPU, GPU) and power prefs? To me context seems to be only a parameter to the workflows above, not a standalone thing.
  • How many contexts are allowed? How many are typically used?
  • How many builders can (are meant to) work in a context?
  • Could a graph (in theory) be built as a structure only, and then compiled/executed for different contexts?
  • From the implementation: an operator object always belongs to one builder, can be connected (well, bound) or not.
    Question: could one bind a user function to it, that overrides the default one?

(This post may be edited/reformulated in the future).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions