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

Fix MLTensorUsage is undefined issue #296

Merged
merged 2 commits into from
Nov 14, 2024
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: 5 additions & 2 deletions common/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -306,8 +306,11 @@ export function getUrlParams() {

export async function isWebNN() {
if (typeof MLGraphBuilder !== 'undefined') {
const context = await navigator.ml.createContext();
return !context.tf;
// Polyfill MLTensorUsage to make it compatible with old version of Chrome.
if (typeof MLTensorUsage == 'undefined') {
window.MLTensorUsage = {WEBGPU_INTEROP: 1, READ: 2, WRITE: 4};
}
return true;
} else {
return false;
}
Expand Down
3 changes: 2 additions & 1 deletion nnotepad/js/nnotepad.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ class WebNNUtil {
dataType: isShapeMethod ? operand.dataType() : operand.dataType,
dimensions: isShapeMethod ? operand.shape() : operand.shape,
shape: isShapeMethod ? operand.shape() : operand.shape,
usage: MLTensorUsage.READ,
usage: typeof MLTensorUsage == 'undefined' ?
undefined : MLTensorUsage.READ,
readable: true,
};
const tensor = await context.createTensor(desc);
Expand Down