r/cpp • u/illuhad • Sep 21 '23
Offloading standard C++ PSTL to Intel, NVIDIA and AMD GPUs with AdaptiveCpp
AdaptiveCpp (formerly known as hipSYCL) is an independent, open source, clang-based heterogeneous C++ compiler project. I thought some of you might be interested in knowing that we recently added support to offload standard C++ parallel STL algorithms to GPUs from all major vendors. E.g.:
std::vector<int> input = ...
std::vector<int> output(input.size());
// Will be executed on GPUs
std::transform(std::execution::par_unseq, input.begin(), input.end(), output.begin(),
[](auto x) { return x + 1; });So far, C++ PSTL offloading was mainly pushed for by NVIDIA with their nvc++ compiler, which supports this for NVIDIA hardware. In addition to NVIDIA, our compiler also supports Intel and AMD GPUs. And yes, you can very easily create a single binary that can offload to all :-) Just compile with acpp --acpp-stdpar --acpp-targets=generic
We haven't implemented all algorithms yet, but we are working on adding more. Here's what is already supported: https://github.com/AdaptiveCpp/AdaptiveCpp/blob/develop/doc/stdpar.md
If you find yourself using the par_unseq execution policy a lot, you might get a speedup just by recompiling. Since the system may have to transfer data between host and GPU under the hood, you get the most out of it for usage patterns where data can remain on the GPU for an extended period of time (e.g. multiple large PSTL calls following each other before the host touches data again). If you have a system where host and GPU are tightly integrated (say, an iGPU), data transfers may not be an issue however and you might get a boost in more scenarios.
It can be used with most recent clang and libstdc++ versions. I'm afraid it focuses on Linux at the moment.
This feature is all new and experimental, but maybe someone is brave :-)
8
u/[deleted] Sep 21 '23
I'd be curious to know who forced the project to rename itself from OpenSYCL (Intel?). Funny that the ideals behind sycl were to be open and collaborative (in opposition to NVIDIA), and a couple of years later we already have lawsuit threats being thrown around.
4
u/Kike328 Sep 22 '23 edited Sep 22 '23
i’m developing a sycl rendering engine, and by now I have just used DPC++. My objective is to compile and execute LLVM-IR kernel code, at runtime (because I need to run customs shaders), you know if it would be possible to do so in AdaptiveCpp? With DPC++ right now, I’m relying heavily in AOT which forces me to compile the LLVM-IR statically, but I have seen that your implementation works with JIT for Nvidia and other devices, which would be ideal for my usecase.
Summarizing I’m looking for a way to create a kernel at runtime from llvm-ir code, if I understood well enough that’s something implementation dependent.
PD: I’m literally presenting my master thesis today and you guys are making me changing again the slides to change the name of OpenSYCL haha
2
u/nimzobogo Sep 22 '23
What if I had a novel architecture and wanted to port it under AdaptiveSycl? Do I first need to port HIP to the architecture?
1
u/hadrabap Sep 22 '23
Excellent! Thank you for a new toy! I have no experience with HPC, and I have never faced the needs for it in my life. But I've developed a few parallel things already and have heard of SYCL, and I've got immediately interested in it. I pretty much love the idea of using single cross-platform language for cross-sillicon execution. 🙂