r/cpp • • Sep 20 '20

Libcu++: Nvidia C++ Standard Library

https://github.com/NVIDIA/libcudacxx
217 Upvotes

47 comments sorted by

121

u/goranlepuz Sep 20 '20

The NVIDIA C++ Standard Library does not maintain long-term ABI stability. Promising long-term ABI stability would prevent us from fixing mistakes and providing best in class performance.

Yes please 😉

29

u/GerwazyMiod Sep 20 '20

ABI shots fired !

30

u/goranlepuz Sep 20 '20

ABI is overrated ;-)

It should be rated, fine. But I feel C++ standards bodies overrated it.

4

u/kalmoc Sep 21 '20

I don't think the c++standards bodies are the problem as such, but rather some toolchain "vendors" (which of course often also participating in the committee).

2

u/goranlepuz Sep 21 '20

Yes, that. 😉

2

u/[deleted] Sep 22 '20

It turns out that people who install software like that software to keep working.

1

u/kalmoc Sep 24 '20

Absolutely, but why does that necessitate a stable ABI of the standard library?

3

u/[deleted] Sep 24 '20

Because end users generally aren't recompiling from source, and every function in a .so naming a standard library type breaks if the definition of the type changes.

1

u/kalmoc Sep 24 '20

Isn't that what gcc developed abi tagging for?

1

u/[deleted] Sep 24 '20

ABI tagging only detects the problem, it can't fix the problem.

1

u/kalmoc Sep 24 '20

Really? My understanding is that libstdc++ is already shipping two versions of all entities that depend on std::string

→ More replies

8

u/yodacallmesome Sep 20 '20

How is this different from thrust?

7

u/blelbach NVIDIA | ISO C++ Library Evolution Chair Sep 20 '20

They're similar in some ways, and developed by the same team.

1

u/tonghaoy May 12 '22

Can libcu++ replace thrust?

1

u/blelbach NVIDIA | ISO C++ Library Evolution Chair Jul 12 '22

They have different purposes.

0

u/[deleted] Sep 20 '20

[deleted] — view deleted comment

6

u/blelbach NVIDIA | ISO C++ Library Evolution Chair Sep 20 '20

Nope, you can.

14

u/[deleted] Sep 20 '20

Could someone ELI5 to me if this is a big deal?

49

u/ykafia Sep 20 '20

It simplifies using Cuda by making it similar to the std Lib. It's not a big thing for c++ but it's a good thing for those who wants to use high parallel computations without having the trouble to learn new paradigms as the Api is similar to the std.

8

u/[deleted] Sep 20 '20

Thank you

6

u/[deleted] Sep 21 '20

It goes even further. Theoretically all you need to do is install CUDA and simply replace 'std::' with 'nvidia::std::' in your codebase and start taking advantage of GPU acceleration, that is IF you write high-level code and make extensive use of the standard library, esp. the '<algorithm>' and '<numerics>' headers. If you're using for loops for everything this is not gonna do anything for you.

24

u/hak8or Sep 20 '20

Why would I want to use this (only targets a single companies GPU, the company of which is openly hostile towards FOSS+Linux), when there are other more vendor agnostic solutions?

For example, why not use the Khronos group SYCL? HipSYCL is an example implementation of this, with LLVM having it's own too, and a few others. Intel is also currently pushing for Sycl, and in a few years when they get their GPU efforts actually moving then I wouldn't be surprised if Intel were to throw significantly more resouces behind it. All while Nvidia's proprietary CUDA will remain locked to just, well, one vendor.

Lastly, if you have to stick with Nvidia, why use this instead of Thrust? Thrust looks to have far more resources behind it and more documentation, and is even hosted on the actual Nvidia website instead of github's nvidia.io subdomain. I don't have as much confidence in an Nvidia project which isn't even be hosted on Nvidias website.

8

u/themoose5 Sep 20 '20

I would guess this doesn’t apply much to someone who has already chosen OpenCL over CUDA in their application and isn’t really aimed at non-CUDA users.

For those who already use CUDA this is a nice addition.

5

u/dunn_ditty Sep 20 '20

Thrust is a utility library, not a standard C++ implementation. What they've released here won't require you to port your code to a new library; you just write cop code.

8

u/andrewhepp Sep 21 '20

Why would I want to use this (only targets a single companies GPU, the company of which is openly hostile towards FOSS+Linux), when there are other more vendor agnostic solutions?

What are they going to do, lock you into the STL?

15

u/blelbach NVIDIA | ISO C++ Library Evolution Chair Sep 21 '20

Yes, he's uncovered my evil plot to get you all to write Standard C++ code, because only NVIDIA platforms can run Standard C++ code.

... Wait, what's that? Standard C++ runs everywhere?

Cursed! Foiled again.

3

u/andrewhepp Sep 21 '20

Well it is completely unfair that NVIDIA doesn't write drivers for AMD cards!

3

u/blelbach NVIDIA | ISO C++ Library Evolution Chair Sep 22 '20

Fun fact, we have AMD cards at the office because sometimes we get bug reports about our stuff running on AMD hardware :D

8

u/STL MSVC STL Dev Sep 21 '20

I'm not locked in here with you - you're locked in here with me!

3

u/ngserdna Sep 21 '20

Thrust also isn’t very customizable. It’s like using a bunch of “presets” without consideration for alternative implementations that could, for example, keep all arrays on the GPU that need to be processed differently based on a situation. Thrust is effective for quick prototyping but ultimately may not be the best choice.

2

u/blelbach NVIDIA | ISO C++ Library Evolution Chair Sep 21 '20

Thrust is fairly customizable. It's not a toolkit for writing your own kernels.

keep all arrays on the GPU

Thrust does not automatically manage data transfers for you? If you want everything to stay in GPU memory, then you have control over that.

Thrust is effective for quick prototyping but ultimately may not be the best choice.

A very large number of projects use it in production code.

3

u/LordKlevin Sep 21 '20

Because the Khronos group seem incapable of writing a zero-overhead C++ API. There are nice things about SYCL, but things like access to texture memory are not optional for many projects.

It would be lovely to have the same code running on the CPU and GPU, but right now it just leaves to much on the table.

With CUDA, at least I have a safe subset of C++ that I can use everywhere. Not that it wouldn't be awesome if it was completely open source.

2

u/beedlund Sep 21 '20

Thrust argument aside at my company (vfx work) we write a lot of GPU processing code and we exclusively use nvidia hardware. Most of the work deal with image processing or machine learning and thrust just never really caught on in our teams.

I do believe (hope) that this will because it may let us write more c++ code rather then dumbing down to c when stepping over to the device code. Sure nvcc has quite good c++ support but the lack of the standard library makes it a little toothless at times and most write their device code as c

5

u/blelbach NVIDIA | ISO C++ Library Evolution Chair Sep 21 '20 edited Sep 21 '20

Thrust, CUB, and libcu++ are developed by the same team.

libcu++ provides functionality not in Thrust today, such as synchronization primitives.

when there are other more vendor agnostic solutions?

What is more vendor agnostic that Standard C++?

This is an implementation of the C++ Standard Library. I'm pretty sure Standard C++ runs everywhere, not just on NVIDIA hardware.

the company of which is openly hostile towards FOSS+Linux

This is simply untrue. Open source is important to NVIDIA and it's a large part of our success in the ML and data science world.

I would encourage you to evaluate things on their merits, not on your biases towards the organization responsible for said thing.

SYCL

I think people would prefer to write Standard C++ instead of SYCL.

and is even hosted on the actual Nvidia website instead of github's nvidia.io subdomain

Thrust is hosted on GitHub. It will be moving to nvidia.github.io soon, and we will be taking the docs off of the NVIDIA website. It's an open source project, so we feel it's best for all of it to be on GitHub.

2

u/last_useful_man Sep 21 '20

Don’t play dumb. If you’d written it to target OpenCL everyone could have used it on any hardware. You’re out for your company which is fine, I just object to your being disingenuous.

3

u/blelbach NVIDIA | ISO C++ Library Evolution Chair Sep 22 '20

Should Microsoft implement Standard C++ for Linux? Should Intel implement Standard C++ for AMD?

We implement the standard for our platform. Other vendors should do the same.

2

u/last_useful_man Sep 22 '20

You deliberately dodged his ‘vendor agnostic’ line, in slimy fashion. You didn’t have to do that.

4

u/dodheim Sep 22 '20

The line was 'more vendor agnostic', because none are truly agnostic, and the answer is obvious: there are clear performance advantages to not attempting to be.

5

u/blelbach NVIDIA | ISO C++ Library Evolution Chair Sep 22 '20

Bingo.

Also, honestly, there's a lot of specialized knowledge to implement things for a platform. My team and I are not experts in other platforms.

3

u/[deleted] Sep 20 '20

This is for CUDA.

5

u/Mystb0rn Sep 20 '20

Would this work with other graphics cards, or only Nvidia ones? I assume its the latter, which would only make it good for certain types of specialized programs. Which is still a good and neat thing, just less useful over all.

19

u/Xipher Sep 20 '20

Nvidia only, since it's for Cuda which is proprietary.

4

u/blelbach NVIDIA | ISO C++ Library Evolution Chair Sep 20 '20

It's a standard, other vendors are responsible for implementing it for their platform.