Skip to content

Support sync API and require pre-allocated output buffers#174

Merged
huningxin merged 4 commits intowebmachinelearning:mainfrom
huningxin:sync_api
Jun 10, 2021
Merged

Support sync API and require pre-allocated output buffers#174
huningxin merged 4 commits intowebmachinelearning:mainfrom
huningxin:sync_api

Conversation

@huningxin
Copy link
Contributor

@huningxin huningxin commented May 31, 2021

This PR follows the discussion in PR #166 and fixes use case #156. The changes include

  1. Change MLGraphBuilder.build and MLGraph.compute to sync API.
    a. Sync API is easy to use and required by sync wasm lib implementation.
    b. The caller can call the sync API within a webworker to achieve asynchronous Support CPU - WebAssembly scenario of the op level execution use case #156 (comment) @pyu10055
  2. Change MLGraph.compute to require pre-allocated output buffers.
    a. For wasm lib, the output buffers are pre-allcoated in wasm memory.
    b. For GPU, it is prohibitively expensive to create GPU resources on the fly as a function call's return value Support download data asynchronously #166 (comment) @wchao1115
  3. Simplify the the input / output resources binding by MLResource. Leave MLInput only for dynamic input shape case.

Please take a look. Thanks.


Preview | Diff

Leave MLInput only for dynamic input shape.
Copy link
Member

@anssiko anssiko left a comment

Choose a reason for hiding this comment

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

Thanks @huningxin! I submitted some review comments.

I'd encourage @wchao1115 @pyu10055 @RafaelCintron to take an in-depth look at this PR latest before our next call.

@anssiko
Copy link
Member

anssiko commented Jun 7, 2021

@pyu10055 @RafaelCintron we appreciate your quick review of this PR before this Thursday's call.

}

async load(baseUrl, batchSize, frames) {
async build(baseUrl, batchSize, frames) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

you need to remove async keyword if build method is sync.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is needed, because buildConstantByNpy in this function uses fetch to download .npy files from network which is async.

@huningxin
Copy link
Contributor Author

Thanks for the review and approval. I am going to merge this PR.

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.

4 participants