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

Define graph execution methods used in different threading models. #255

Closed
wants to merge 2 commits into from
Closed
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
9 changes: 7 additions & 2 deletions explainer.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,15 @@ const B = builder.input('B', operandType);
const C = builder.add(builder.mul(A, constant), B);
// 2. Compile it into an executable.
const graph = builder.build({'C': C});
// 3. Create an execution method
const execution = new MLExecution(context);
// 3. Bind inputs to the graph and execute for the result.
const bufferA = new Float32Array(4).fill(1.0);
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);
execution.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,6 +101,7 @@ There are many important [application use cases](https://webmachinelearning.gith
export class NSNet2 {
constructor() {
this.graph = null;
this.execution = null;
this.frameSize = 161;
this.hiddenSize = 400;
}
Expand Down Expand Up @@ -140,6 +143,8 @@ export class NSNet2 {
const relu167 = builder.relu(builder.add(builder.matmul(relu163, weight216), biasFcOut2));
const output = builder.sigmoid(builder.add(builder.matmul(relu167, weight217), biasFcOut4));
this.graph = builder.build({'output': output, 'gru94': gru94, 'gru157': gru157});
// Create graph execution method
this.execution = new MLExecution(context);
}

compute(inputBuffer, initialState92Buffer, initialState155Buffer, outputBuffer, gru94Buffer, gru157Buffer) {
Expand All @@ -153,7 +158,7 @@ export class NSNet2 {
'gru94': gru94Buffer,
'gru157': gru157Buffer
};
return this.graph.compute(inputs, outputs);
return this.execution.compute(graph, inputs, outputs);
}
}
```
Expand Down
Loading