Skip to content

Commit

Permalink
Fix MLTensorUsage is undefined issue
Browse files Browse the repository at this point in the history
Polyfill MLTensorUsage to make it compatible with old version of Chrome
  • Loading branch information
Honry committed Nov 14, 2024
1 parent 77a98b9 commit 06e90e4
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;
if (typeof MLTensorUsage == 'undefined') {
// Polyfill MLTensorUsage to make it compatible with old version of Chrome.

Check failure on line 310 in common/utils.js

View workflow job for this annotation

GitHub Actions / job (ubuntu-latest)

This line has a length of 81. Maximum allowed is 80
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 06e90e4

Please sign in to comment.