gpuweb icon indicating copy to clipboard operation
gpuweb copied to clipboard

API should be exposed to ServiceWorker

Open MiguelsPizza opened this issue 2 years ago • 14 comments

Would be nice to have and I can't think of any reason not to expose WebGPU to a service worker considering Webgl is accessible.

It's only exposed to the Window and DedicatedWorkers at the moment. Reference: https://gpuweb.github.io/gpuweb/#navigator-gpu [Exposed=(Window, DedicatedWorker), SecureContext]

Similar issue regarding exposing webGPU to a dedicated worker:

MiguelsPizza avatar Jun 26 '23 00:06 MiguelsPizza

Thanks for filing this, I didn't realize we didn't have an issue for this :) I think we should do it. It seems WebGL just uses Worker. I don't know how to find an official listing of the Worker types but Chromium documents it as DedicatedWorker, SharedWorker, and ServiceWorker: https://chromium.googlesource.com/chromium/src/+/main/third_party/blink/renderer/bindings/IDLExtendedAttributes.md#exposed

So along with this, likely we should expose it in SharedWorker too.

kainino0x avatar Jun 26 '23 18:06 kainino0x

No Problem, thanks for the prompt response!

Let me know if there is anything I can do to help get this to the finish line

MiguelsPizza avatar Jun 26 '23 23:06 MiguelsPizza

@MiguelsPizza Is there no way to use webgpu in webview in android?

libofei2004 avatar Aug 19 '23 08:08 libofei2004

hi there, as far as I know, Tensorflow.js recomend using AI models in background.js (using service worker) for chrome-extension . So, I am really looking forward to this new feature

Jasonsey avatar Sep 08 '23 09:09 Jasonsey

Also love to see WebGPU being exposed to service worker. This would open up quite a bit opportunities building AI extensions with WebGPU

tqchen avatar Nov 29 '23 20:11 tqchen

This seems appropriate.

The only reason not to spec this would be if, somehow, all browsers never planned to actually get around to implementing it - but that's not the case. Once Firefox has its resource consumption controls firmed up, this makes sense for us to implement.

jimblandy avatar Jan 24 '24 17:01 jimblandy

FYI I've started https://github.com/gpuweb/gpuweb/pull/4464 that adds ServiceWorker support to the WebGPU spec.

beaufortfrancois avatar Jan 25 '24 13:01 beaufortfrancois

I don't know how to find an official listing of the Worker types but Chromium documents it as DedicatedWorker, SharedWorker, and ServiceWorker:

MDN also documents it as those 3. https://developer.mozilla.org/en-US/docs/Web/API/WorkerGlobalScope

kainino0x avatar Jan 25 '24 19:01 kainino0x

Thank you @beaufortfrancois @kainino0x, would be great to know how we are doing in terms of support status, love to followup and try out as soon as it lands

tqchen avatar Jan 27 '24 00:01 tqchen

We'll let you know when it's available behind a flag in Chrome so that you can play around.

beaufortfrancois avatar Jan 27 '24 07:01 beaufortfrancois

@tqchen @MiguelsPizza You can now play with WebGPU in a service worker in Chrome Canary 123.0.6271.0 by enabling the "Experimental Web Platform features" flag at chrome://flags/#enable-experimental-web-platform-features.

Here's an extension sample I've created to demonstrate its usage: https://gist.github.com/beaufortfrancois/4795c20bc4d147e0400303d0b8ec02d6

Let me know how it goes ;)

beaufortfrancois avatar Jan 31 '24 07:01 beaufortfrancois

@tqchen @MiguelsPizza Did you have a chance to experiment with Service Worker support in Chrome? Did you find some limitations or bugs we should be aware of?

beaufortfrancois avatar Feb 12 '24 08:02 beaufortfrancois

https://github.com/mlc-ai/web-llm/pull/296 @rickzx should be able to comment more :) really excited about what it can enable

tqchen avatar Feb 13 '24 14:02 tqchen

@beaufortfrancois @tqchen Thanks a lot for putting the effort to support WebGPU in service worker. I was able to put up a sample Chrome extension running LLM in the service worker in the background, and a popup window as a chat assistant. It's much simpler and more elegant to implement this now with the service worker support. Haven't encountered any bugs so far.

rickzx avatar Feb 14 '24 03:02 rickzx

@tqchen @MiguelsPizza @rickzx I'm happy to report that Chrome nows supports WebGPU in service worker by default as of Chrome 124.0.6359.0 (Canary at this moment) 🎉

beaufortfrancois avatar Mar 15 '24 08:03 beaufortfrancois

And to close the loop, here's the official announcement: https://developer.chrome.com/blog/new-in-webgpu-124?hl=en#service_workers_and_shared_workers_support

beaufortfrancois avatar Apr 12 '24 08:04 beaufortfrancois