diff --git a/common/utils.js b/common/utils.js index a9c089e2..f7c61cec 100644 --- a/common/utils.js +++ b/common/utils.js @@ -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; } diff --git a/nnotepad/js/nnotepad.js b/nnotepad/js/nnotepad.js index 315b9f5a..21906a63 100644 --- a/nnotepad/js/nnotepad.js +++ b/nnotepad/js/nnotepad.js @@ -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);