wasi-nn: remove BackendKind, add wrapper structs#6893
Merged
abrown merged 5 commits intobytecodealliance:mainfrom Aug 25, 2023
Merged
wasi-nn: remove BackendKind, add wrapper structs#6893abrown merged 5 commits intobytecodealliance:mainfrom
BackendKind, add wrapper structs#6893abrown merged 5 commits intobytecodealliance:mainfrom
Conversation
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.
alexcrichton
approved these changes
Aug 24, 2023
Member
alexcrichton
left a comment
There was a problem hiding this comment.
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"
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 generatedGraphEncodingtype 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 theBox<dyn ...>type explicitly in many places but this change opts to use a wrapper around this, expecting users to create the wrapper viaFromandIntoand internally accessing the implementation viaDerefandDerefMut. The idea is to eliminate some of the "type clutter;" let me know if you agree.