JIT 编译器是否可以利用 GPU 进行幕后的某些操作?
如果我的理解有任何错误的部分,请随时纠正我。
我的理解是 GPU 提供普通 CPU 提供的指令的子集,但执行速度要快得多。
我知道有很多方法可以将 GPU 周期用于非图形目的,但似乎(理论上)一种即时编译的语言可以检测到合适的 GPU 的存在,并在幕后将一些工作卸载到 GPU无需更改代码。
我的理解是不是太天真了?难道只是因为事情太复杂而没有做到吗?
Feel free to correct me if any part of my understanding is wrong.
My understanding is that GPUs offer a subset of the instructions that a normal CPU provides but executes them much faster.
I know there are ways to utilize GPU cycles for non-graphical purpose, but it seems like (in theory) a language that's Just In Time compiled could detect the presence of a suitable GPU and offload some of the work to the GPU behind the scenes without code change.
Is my understanding naive? Is it just a matter of it's really complicated and just hasn't been done it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
事情绝对没有那么简单。 GPU主要针对SIMD/矢量处理进行定制。因此,尽管当今 GPU 的理论潜力远远优于 CPU,但只有能够受益于 SIMD 指令的程序才能在 GPU 上高效执行。此外,当数据必须从 CPU 传输到 GPU 进行处理时,性能当然也会受到影响。
因此,为了使 JIT 编译器能够有效地使用 GPU,它必须能够检测可以并行化以受益于 SIMD 指令的代码,然后必须确定将数据从 CPU 传输到 GPU 所产生的开销是否会增加。性能的提高超过了它的重量。
It's definitly not as simple. The GPU is tailored mainly at SIMD/vector processing. So even though the theoretical potential of GPUs nowadays is vastely superior to CPUs, only programs that can benefit from SIMD instructions can be executed efficiently on the GPU. Also, there is of course a performance penalty when data has to be transfered from the CPU to the GPU to be processed there.
So for a JIT compiler to be able to use the GPU efficiently, it must be able to detect code that can be parallelized to benefit from SIMD instructions and then has to determine, if the overhead induced by transfering data from the CPU to the GPU will be outweight by the performance improvements.
可以使用 GPU(例如,支持 CUDA 或 OpenCL 的 GPU)来加速 JIT 本身。寄存器分配和指令调度都可以有效地实现。
It is possible to use GPU (e.g., a CUDA- or OpenCL-enabled one) to speed up JIT itself. Both register allocation and instruction scheduling could be efficiently implemented.