Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wasi-nn: remove BackendKind, add wrapper structs #6893

Merged
merged 5 commits into from
Aug 25, 2023

Conversation

abrown
Copy link
Contributor

@abrown abrown commented Aug 23, 2023

One improvement that came from discussions with @geekbeast is that BackendKind, the enum used for differentiating between ML implementation, is no longer necessary. Instead, we can use the generated GraphEncoding type as the key to map to the right implementation.

Also, this PR adopts the Wrapper(Box<dyn ...>) pattern everywhere, which now includes backends and registries. Since wasi-nn accepts multiple implementations for all of these things, we need a way to virtually dispatch to the right implementation. Previously we used the Box<dyn ...> type explicitly in many places but this change opts to use a wrapper around this, expecting users to create the wrapper via From and Into and internally accessing the implementation via Deref and DerefMut. The idea is to eliminate some of the "type clutter;" let me know if you agree.

The wasi-nn crate uses virtual dispatch to handle different kinds of
backends and registries. For easier use, these items are now wrapped in
their own `Box<dyn ...>` structs.
This change completely removes the `BackendKind` enum, which uniquely
listed the kinds of backends that the wasi-nn crate contained. Since we
allow many kinds of backends in `WasiNnCtx` which can be implemented
even outside the crate, this `BackendKind` enum no longer makes sense.
This change uses `GraphEncoding` instead.
@abrown abrown requested a review from a team as a code owner August 23, 2023 17:13
@abrown abrown requested review from fitzgen and removed request for a team August 23, 2023 17:13
Copy link
Member

@alexcrichton alexcrichton left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nothing looks obviously wrong here to me but I'm not super familiar with the NN stuff of wasi-nn. It sounds like you're ok with that though so feel free to merge with my cursory review of "seems fine"

@abrown abrown added this pull request to the merge queue Aug 25, 2023
Merged via the queue into bytecodealliance:main with commit ac7d070 Aug 25, 2023
31 checks passed
@abrown abrown deleted the remove-backend-kind branch August 25, 2023 03:32
eduardomourar pushed a commit to eduardomourar/wasmtime that referenced this pull request Sep 6, 2023
…e#6893)

* wasi-nn: accept a list of backends instead of a hash map

* wasi-nn: refactor with new `Backend` and `Registry` wrappers

The wasi-nn crate uses virtual dispatch to handle different kinds of
backends and registries. For easier use, these items are now wrapped in
their own `Box<dyn ...>` structs.

* wasi-nn: completely remove `BackendKind`

This change completely removes the `BackendKind` enum, which uniquely
listed the kinds of backends that the wasi-nn crate contained. Since we
allow many kinds of backends in `WasiNnCtx` which can be implemented
even outside the crate, this `BackendKind` enum no longer makes sense.
This change uses `GraphEncoding` instead.

* nit: move `pub mod backend` with other exports

prtest:full

* fix: remove broken doc links
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.

2 participants