intel / webml-polyfill

Deprecated, the Web Neural Network Polyfill project has been moved to https://github.com/webmachinelearning/webnn-polyfill
Apache License 2.0
161 stars 46 forks source link

[polyfill] Supported WebGPU backend. #1355

Closed BruceDai closed 3 years ago

BruceDai commented 3 years ago

@huningxin @ibelem PTAL, thanks. I use require to instead of import for '@tensorflow/tfjs-backend-webgpu' model, now if browser didn't support WebGPU, there's an error 'WebGPU is not available'.

  static _supportWebGPU() {
    if (navigator.gpu === undefined) {
      return false;
    } else {
      let tfjsBackendWebgpu = require("@tensorflow/tfjs-backend-webgpu");
      tf.setBackend('webgpu');
      tf.ready();
      return tf.getBackend() === "webgpu";
    }
  }
ibelem commented 3 years ago

Thanks @BruceDai !