javascript 如何在 Chrome 中使用 WebCL?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11532281/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-26 13:33:56  来源:igfitidea点击:

How to use WebCL in Chrome?

javascriptgoogle-chromegoogle-chrome-extensionwebcl

提问by LowFieldTheory

I'm a young developer interested in HPC and parallel programming.

我是一名对 HPC 和并行编程感兴趣的年轻开发人员。

As you can see here http://www.khronos.org/webclhas been "released" (not yet, is a working draft) this porting for the web of OpenCL. I don't know where to start from, because I can't see what to do, because I would like to do it on Chrome that, unfortunately, still doesn't have his experimental plugin like Firefox, and I know that it would have better performance thanks to the v8.

正如您在此处看到的,http://www.khronos.org/webcl 已“发布”(尚未发布,是一份工作草案),此为 OpenCL 网络移植。我不知道从哪里开始,因为我不知道该怎么做,因为我想在 Chrome 上做,不幸的是,仍然没有像 Firefox 这样的实验性插件,我知道它会由于 v8.0 有更好的性能。

Well, no one knows nothing about it? I know I should use idl files, but I don't know where or what do, actually.

好吧,没有人对此一无所知吗?我知道我应该使用 idl 文件,但实际上我不知道在哪里或做什么。



Actually I think that my problem, lately, is first the debugging. Firebug, compared to the debugger of chrome is a pain and confusing. Chrome has less bug, is lighter and can give better performance also for this, what I was saying, lightweight.

实际上,我认为我最近的问题首先是调试。Firebug,相比于 chrome 的调试器是痛苦和混乱的。Chrome 有更少的错误,更轻,并且可以为此提供更好的性能,我所说的,轻量级。

And we should also see how is implemented the .idl for Firefox and make some comparisons about performance, on how resources are handled from both engines.

我们还应该了解 Firefox 的 .idl 是如何实现的,并对性能、两个引擎如何处理资源进行一些比较。

采纳答案by Engineer

(Jan 2020) There are other options to do web computation on the GPU:

(2020 年 1 月)还有其他选项可以在 GPU 上进行网络计算:

WebGL compute shaders (old but readily accessible)

WebGL 计算着色器(旧但易于访问)

Thisis pretty easy to set up within a WebGL context. Shortcomings compared to WebCL are minor:

在 WebGL 上下文中非常容易设置。与 WebCL 相比的缺点是次要的:

  • WebCL Floating point precision guarantees are better (for most uses, doesn't matter)
  • WebCL supports random writes where WebGL Compute doesn't, but for most parallel problems, this doesn't matter, as you'll be writing a result only for the current element operated on.
  • Buffer data comes back to CPU as integers, but you can solve this if you represent your values the right way and encode/decode accordingly on the GPU/CPU. I've done this by multiplying floats by some large value (like 1024) before finalising in compute shader, and dividing by same once you get integers back on CPU (note that using a power of 2 means you can do this integer division very fast by doing value = buffer[n] >> 10i.e. 1024 = 2^10). I did not have any precision concerns as some scientific / fintech apps do.
  • WebCL 浮点精度保证更好(对于大多数用途,无关紧要)
  • WebCL 支持随机写入,而 WebGL Compute 不支持,但对于大多数并行问题,这无关紧要,因为您将只为操作的当前元素写入结果。
  • 缓冲区数据作为整数返回到 CPU,但如果您以正确的方式表示您的值并在 GPU/CPU 上相应地编码/解码,您就可以解决这个问题。我已经通过在计算着色器中最终确定之前将浮点数乘以某个大值(如 1024)来完成此操作,并在您将整数返回 CPU 后除以相同的值(请注意,使用 2 的幂意味着您可以非常快地执行此整数除法通过这样做,value = buffer[n] >> 10即 1024 = 2^10)。我没有像某些科学/金融科技应用程序那样有任何精确性问题。

You can find the recently-updated spec here.

您可以在此处找到最近更新的规范。

WebGPU (new standard)

WebGPU(新标准)

Thisis the latest standard under implementation, and successor to WebGL 1.0, 2.0 and WebCL.

是正在实施的最新标准,是 WebGL 1.0、2.0 和 WebCL 的继承者。

You can access the GPU's computational power directly from JavaScript, dealing with latency on GPU callouts by using asyncand await. You will need to write shaders in WHLSL(now WSL), a new, high-level shader language based closely on Direct3D HLSL.

您可以直接从 JavaScript 访问 GPU 的计算能力,使用async和处理 GPU 标注的延迟await。您将需要在WHLSL(现在是 WSL)中编写着色器,WHLSL是一种紧密基于 Direct3D HLSL 的新的高级着色器语言。

It abstracts the latest low-level 3D graphics APIs such as Metal, Vulkan and Direct3D 12, thereby reducing GPU overheads compared with Open/WebGL.

它抽象了最新的低级 3D 图形 API,例如 Metal、Vulkan 和 Direct3D 12,从而与 Open/WebGL 相比减少了 GPU 开销。

Choices?

选择?

WebGL compute shadersfor those who intend to use computational results in WebGL rendering, who are anyway doing WebGL rendering in their app, or who want to prototype on web and then port to native OpenGL.

WebGL 计算着色器适用于那些打算在 WebGL 渲染中使用计算结果的人,他们无论如何都在他们的应用程序中进行 WebGL 渲染,或者想要在 Web 上进行原型设计然后移植到原生 OpenGL。

WebGPUfor planned cross-browserness including on Apple devices (where GL has been poorly supported for a long time), newness, and speed. Also used for graphics.

WebGPU用于计划的跨浏览器,包括在 Apple 设备(其中 GL 长期以来一直缺乏支持)、新颖性和速度。也用于图形。

WebCLvia the extension for Chrome / Chromium if you ultimately want the opportunity to run the code on CPUs too, without modification, and don't need GPU rendering.

WebCL通过 Chrome / Chromium 的扩展,如果您最终也希望有机会在 CPU 上运行代码,无需修改,并且不需要 GPU 渲染。

回答by Leo Meyerovich

For a Chrome version, Samsung's (the one on Google Code) is the right one to look at. It is for Safari: Safari is based on WebKit, which is also what Chrome is based on. Working with Chrome's renderer might be tricky, however, as I believe it is in a special process. I bet Chrome devs would love to help out on this, however, and I suggest checking with the WebCL project members if anybody has started looking at this already.

对于 Chrome 版本,三星(Google Code 上的那个)是正确的选择。它是针对 Safari 的:Safari 基于 WebKit,这也是 Chrome 的基础。然而,使用 Chrome 的渲染器可能会很棘手,因为我相信这是一个特殊的过程。我敢打赌,Chrome 开发人员很乐意为此提供帮助,如果有人已经开始研究这个,我建议与 WebCL 项目成员联系。

Feature-wise, Samsung's version has a big practical difference from Nokia's: it supports moving data directly from WebCL to WebGL. If you want to visualize a computation without going moving all the data off the GPU inbetween (which would kill real-time performance), this is a big deal.

在功能方面,三星的版本与诺基亚的有很大的实际区别:它支持将数据直接从 WebCL 移动到 WebGL。如果您想在不将所有数据从 GPU 中移出的情况下将计算可视化(这会降低实时性能),这是一个大问题。

Good luck!

祝你好运!

回答by Hymanalope

The performance gains you seem to be expecting with a port of the Firefox WebCL extension to the Chrome browser are, I would surmise, unlikely: Though the V8 engine does indeed process javascript faster than other engines, WebCL is, by definition, processed primarily on the GPU, so the javascript component of the code will more than likely represent a very small percentage of the processing time. For the time being, if you want to experiment with WebCL, you're going to need to stick with the Firefox extension.

您似乎期望通过将 Firefox WebCL 扩展移植到 Chrome 浏览器来获得性能提升,我推测不太可能:虽然 V8 引擎确实比其他引擎处理 javascript 的速度更快,但根据定义,WebCL 主要处理GPU,因此代码的 javascript 组件很可能只占处理时间的很小一部分。目前,如果您想尝试使用 WebCL,您将需要坚持使用 Firefox 扩展。

回答by Remi Arnaud

Chrome with WebCL is now available on github Chromium-WebCL. Source, build instructions and binaries (for windows)

带有 WebCL 的 Chrome 现在可在 github Chromium-WebCL 上使用。源代码、构建指令和二进制文件(适用于 Windows)