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

Context-based graph execution methods for different threading models. #257

Merged
merged 13 commits into from
Apr 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions explainer.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ const bufferB = new Float32Array(4).fill(0.8);
const bufferC = new Float32Array(4);
const inputs = {'A': bufferA, 'B': bufferB};
const outputs = {'C': bufferC};
graph.compute(inputs, outputs);
context.compute(graph, inputs, outputs);
// The computed result of [[1, 1], [1, 1]] is in the buffer associated with
// the output operand.
console.log('Output value: ' + bufferC);
Expand Down Expand Up @@ -99,12 +99,13 @@ There are many important [application use cases](https://webmachinelearning.gith
export class NSNet2 {
constructor() {
this.graph = null;
this.context = null;
this.frameSize = 161;
this.hiddenSize = 400;
}

async build(baseUrl, batchSize, frames) {
const context = navigator.ml.createContext();
this.context = navigator.ml.createContext();
const builder = new MLGraphBuilder(context);
// Create constants by loading pre-trained data from .npy files.
const weight172 = await buildConstantByNpy(builder, baseUrl + '172.npy');
Expand Down Expand Up @@ -153,7 +154,7 @@ export class NSNet2 {
'gru94': gru94Buffer,
'gru157': gru157Buffer
};
return this.graph.compute(inputs, outputs);
return this.context.compute(this.graph, inputs, outputs);
}
}
```
Expand Down
Loading