Skip to content

Commit

Permalink
Merge pull request #296 from Honry/remove-MLTensorUsage
Browse files Browse the repository at this point in the history
Fix MLTensorUsage is undefined issue
  • Loading branch information
huningxin authored Nov 14, 2024
2 parents 77a98b9 + f45c753 commit 5be72c7
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
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

0 comments on commit 5be72c7

Please sign in to comment.