tensorflow / tfjs

A WebGL accelerated JavaScript library for training and deploying ML models.
https://js.tensorflow.org
Apache License 2.0
18.39k stars 1.92k forks source link

Chrome Deprecation warning: SharedArrayBuffer will require cross-origin isolation as of M91 #4971

Closed vladmandic closed 3 years ago

vladmandic commented 3 years ago

Running TFJS 3.5.0 with WASM backend and SIMD & multithreading enabled results in warnings in browser console:

[Deprecation] SharedArrayBuffer will require cross-origin isolation as of M91, around May 2021.  
See https://developer.chrome.com/blog/enabling-shared-array-buffer/ for more details.

  (anonymous)   @   flags_wasm.ts:49
  evaluateFlag  @   environment.ts:141
  getAsync  @   environment.ts:88

Which happens in internal WASM test in flags_wasm.ts:

// Test for transferability of SABs (needed for Firefox)
// https://groups.google.com/forum/#!msg/mozilla.dev.platform/IHkBZlHETpA/dwsMNchWEQAJ
new MessageChannel().port1.postMessage(new SharedArrayBuffer(1));
// This typed array is a WebAssembly program containing threaded
// instructions.
return WebAssembly.validate(new Uint8Array([
  0, 97, 115, 109, 1, 0,  0,  0, 1, 4, 1,  96, 0,   0,  3, 2, 1,  0, 5,
  4, 1,  3,   1,   1, 10, 11, 1, 9, 0, 65, 0,  254, 16, 2, 0, 26, 11
]));

Environment: TFJS 3.5.0 with Edge/Chromium 90 on Windows 10 with WASM backend (SIMD and MultiThreading enabled)

lina128 commented 3 years ago

Yes, this change will be out with Chrome 91 release. Please see the official link for how to setup coop and coep: https://web.dev/coop-coep/

lina128 commented 3 years ago

Here's some updated progress on this change: https://developer.chrome.com/blog/enabling-shared-array-buffer/

google-ml-butler[bot] commented 3 years ago

Are you satisfied with the resolution of your issue? Yes No

SukkaW commented 3 years ago

@lina128 What if it is impossible to implement cross-origin isolated pages? Will tensorflow.js wasm backend add an ArrayBuffer fallback for unavailable SharedArrayBuffer, to make it less efficient but still workable?

jinjingforever commented 3 years ago

Hi @SukkaW, without cross-origin isolation, the wasm baskend will fallback to simd only (without multi-threading support).

SukkaW commented 3 years ago

without cross-origin isolation, the wasm baskend will fallback to simd only (without multi-threading support).

Thanks!

huningxin commented 3 years ago

Thanks @jinjingforever . Another question is: could cross-origin isolation be enabled for tfjs e2e benchmark site? Otherwise, users can only test it without multi-threading support.

jinjingforever commented 3 years ago

Good point @huningxin! I think the e2e benchmark is hosting on github page which doesn't support custom headers. I will discuss with the team and see where to move it. Thanks!

jinjingforever commented 3 years ago

@huningxin We set up a new benchmark site that has the cross-origin isolation set up: https://tfjs-benchmarks.web.app/local-benchmark/. Thanks!

huningxin commented 3 years ago

It works like a charm. Thanks @jinjingforever .