-
Notifications
You must be signed in to change notification settings - Fork 12.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Initialize LLVM's AMDGPU target machine, if available. #51548
Conversation
Note this isn't useful, yet. More changes will be necessary to be able to actually codegen for this machine. As such, it is not enabled by default. This patch is on its own for the benefit of the reviewers.
(rust_highfive has picked a reviewer for you, use r? to override) |
Will this enable Rust on the GPU in the long term? Is there any kind of RFC/tracking issue one can follow? |
Rust on the gpu would be fantastic, but this doesn't seems to be an extension to SYCL which support many languages, if it's standard rust, how will it work ? This doesn't seems to be difficult as it's more about removing feature support than adding them :) And you should use the language agnostic SPIR-V back-end. It's also more than openCL/SYCL, for example it's used by openGL and Vulkan (and others khronos apis) maybe even for WebGL-next), and HSA. Rust could arguably be the best language for GPUs, and others accelerators. Edit [1] There are others interesting results : There was also this thread on reddit GPU computing enable massive optimisations and is already used by e.g Pathfinder @pcwalton Sorry for the long post. |
@LifeIsStrange SYCL is just a nice C++ API/domain specific embedded language on top of OpenCL (there's actually two versions, SYCL 1.2.1 for OpenCL 1.2, and SYLC 2.2 for OpenCL 2.2), so adding support would mean designing something similar for Rust. |
@pmarcell Quoting Wikipedia, "The OpenCL standard defines host APIs for C and C++; third-party APIs exist for other programming languages and platforms such as Python,[13] Java and .NET.[10]:15" Then we have two ways for adding rust support for GPUs, either we transpile rust to the c++ Subset that is sycl or to the OpenCL C or even to .NET. The other paradigm would be to port the same gpu restrictions and Syntax (eg the kernel entry point) and the few features (single source, runtime compilation, gpu host memory support and optionally unified memory) than sycl. |
I think most of the higher level languages generate OpenCL code, which is JIT compiled by the runtime, so no IR is involved. JIT compiling the source code is the default mode of OpenCL 1.2, the Wikipedia article describes some of the problems with this approach. This also works in Rust today via an ordianry API binding (and the kernels are still OpenCL C), and in theory it is possible to create something like SYCL 1.2 for Rust, but it probably would be a more difficult project than SYCL itself. The second paradigm you described is not possible. The generated SPIR-V is fed to the OpenCL runtime, which is part of the GPU driver itself, it first compiles the SPIR-V to GPU machine code, and then the driver feeds this machine code to the GPU for execution. If these PRs are accepted, rustc will be able to generate a binary that contains both the CPU and the GPU (in this case AMD) machine code. Rustc can already target Nvidia GPUs, so it's theoretically possible to hack something together to target both GPU vendors, but it still wouldn't be universally usable, like OpenCL (and even OpenCL is not universally usable, the only version that is supported everywhere is 1.2, Nvidia doesn't support 2.0 because they prefer CUDA, and their 1.2 implementation is slower than CUDA, AMD only supports OpenCL 2.0 with their ROCm runtime, and Intel only supports OpenCL 2.1, so the one year old OpenCL 2.2 specification is implemented by exactly zero GPU manufacturers). |
I thought that was because they were both waiting for the OpenCL 2.2 frontend to land in LLVM mainline, which it is doing right now I think (or just finished)? |
Landing it in upstream LLVM is important, but they could have implemented it in closed source drivers earlier. BTW, sorry for spamming this PR with these conversations. |
AMD doesn't have closed source drivers anymore, the last update was over a year ago for it (AMDGPUPRO) and their open-source AMDGPU driver has overtaken it in all functionality now. :-) /me quite likes that Intel and AMD are well made enough to use fully open source drivers now, unlike nVidia But yeah, OpenCL 2.2 I think will come out in the drivers shortly after LLVM is released stable with it. You can of course use OpenCL 2.2 to accelerate work on the CPU or computational cards currently, you are not limited to just the GPU unlike the poorly made cuda. |
AMD released an updated to their closed driver very recently, see: https://www.phoronix.com/scan.php?page=news_item&px=Radeon-Software-18.20-Stable And from the release notes:
They now have three different OpenCL runtimes: the legacy driver, ROCm, and the new PAL. See: https://www.phoronix.com/scan.php?page=news_item&px=ROCm-PAL-Future The PAL runtime is also open source, but it's integrated into the closed driver (IIRC it will also become the official runtime on Windows). The PAL runtime seems to only support OpenCL 1.2 and ROCm is a non-standard implementation, it supports OpenCL 1.2, and extra AMD specific stuff. And OpenCL 2.1 is not part of either of them. I also like that they open up most of the stack, but GPGPU is still a mess, which means it will be a lot harder for Rust to become a part of it. |
Ah, I bet that is for some backwards compatibility bits. the AMDGPUPRO driver is used by some older setups (AMDGPU only supports 'newer' GPU's, like 5 years old or newer).
Sounds like PR time? ;-) |
TBH, this whole ecosystem is a mess. Thankfully, targeting the GPU directly avoids most of this, though it has it's downsides. |
ping from triage @michaelwoerister will you have time to review this in near future? |
@bors: r+ |
📌 Commit b4d64b7 has been approved by |
@bors rollup |
…ne, r=alexcrichton Initialize LLVM's AMDGPU target machine, if available. Note this isn't useful, yet. More changes will be necessary to be able to actually codegen for this machine. As such, it is not enabled by default. This patch is on its own for the benefit of the reviewers.
…ne, r=alexcrichton Initialize LLVM's AMDGPU target machine, if available. Note this isn't useful, yet. More changes will be necessary to be able to actually codegen for this machine. As such, it is not enabled by default. This patch is on its own for the benefit of the reviewers.
…ne, r=alexcrichton Initialize LLVM's AMDGPU target machine, if available. Note this isn't useful, yet. More changes will be necessary to be able to actually codegen for this machine. As such, it is not enabled by default. This patch is on its own for the benefit of the reviewers.
Rollup of 13 pull requests Successful merges: - #51548 (Initialize LLVM's AMDGPU target machine, if available.) - #51809 (Add read_exact_at and write_all_at methods to FileExt on unix) - #51914 (add outlives annotations to `BTreeMap`) - #51958 (Show known meta items in unknown meta items error) - #51973 (Make Stdio handle UnwindSafe) - #51977 (bootstrap: tests should use rustc from config.toml) - #51978 (Do not suggest changes to str literal if it isn't one) - #51979 (Get rid of `TyImplTraitExistential`) - #51980 (Emit column info in debuginfo for non msvc like targets) - #51982 (incr.comp.: Take names of children into account when computing the ICH of a module's HIR.) - #51997 (add entry for cargo-metadata feature to RELEASES) - #52004 (toolstate: Fixed detection of changed submodule, and other fixes.) - #52006 ( Change --keep-stage to apply more often) Failed merges: r? @ghost
Note this isn't useful, yet. More changes will be necessary to be able to
actually codegen for this machine. As such, it is not enabled by default.
This patch is on its own for the benefit of the reviewers.