r/programming • • Sep 19 '20

Libcu++: Nvidia C++ Standard Library

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

62 comments sorted by

38

u/allinwonderornot Sep 20 '20

"I love open source so much, I embrace hardware vendor lock-in!"

6

u/13steinj Sep 20 '20

With the current state of GPUs and AMD not having a decent competitor, that's incredibly disingenuous. Not to mention nothings stopping AMD from making their own stl, and then you can just hot swap between namespaces...

6

u/allinwonderornot Sep 20 '20

Or use a GPU-agnostic computing framework...

Crypto-miners can do it, so-called professional programmers can't?

22

u/13steinj Sep 20 '20

You mean like OpenCl vs cuda?

Because some of us deal with workloads where every bit of perf counts? With cuda you have anywhere from a 16-45% performance increase (you'll have to get the percents from using ratios on the tables within), depending on what is taking the most of your application's time.

To quote the concluding paragraph:

CUDA seems to be a better choice for applications where achieving as high a performance as possible is important. Otherwise the choice between CUDA and OpenCL can be made by considering factors such as prior familiarity with either system, or available development tools for the target GPU hardware.

Until AMD / someone else can do something that will be properly matched, I'm sticking with cuda. Now there are rumors that AMD will unveil a language / framework that would be cross platform and transpile into cuda, but those rumors have been circulating for the better part of a year.

10

u/James20k Sep 20 '20

This conflicts with a lot of the data I saw at the time, there are other papers on this which found that correctly written OpenCL has similar performance to CUDA, but you can't 1:1 translate it because there are some slightly different semantics. They also don't provide host code which is unfortunate. Nothing in my experience of gpgpu would suggest that OpenCL is 46% slower, there's absolutely 0 reason for kernel code to run that much slower

10

u/13steinj Sep 20 '20

Can you send me some of these papers? Because the few I've found all have the same result. General consensus online is the same, that cuda is significantly more performant in many if not all applications.

8

u/Elusivehawk Sep 20 '20

Comparing the performance uplift going from OpenCL to CUDA on the same hardware from the same vendor, while it makes sense on paper, is actually a terrible way to test it. Nvidia has zero incentive whatsoever to ensure their OpenCL implementation is as fast as their CUDA one. In fact it's quite the opposite: CUDA's vendor lock-in gives them incentive to ensure their OpenCL implementation is slower.

1

u/13steinj Sep 20 '20

I agree, and I explain why that doesn't really matter here.

TLDR: Until AMD can make a comparable piece of hardware (regardless of framework used), everyone is already "vendor locked" by means of what they're purchasing-- same reason a lot of universities up until recently would mostly if not solely be buying Intel CPUs --the decision to solely buy Nvidia for the sake of "well, price:perf doesn't matter to me because I'm not strapped for cash, just go highest perf and be done with it".

4

u/fuasthma Sep 20 '20

It's not a rumour. AMD has the open source framework HIP which can run either CUDA or their own AMD stuff under the hood. HIP looks pretty much like CUDA so going from CUDA to HIP is super easy.

1

u/13steinj Sep 23 '20

Missed this comment, I've gotten my inbox flooded recently by a post in another sub, sorry.

Yeah I know of HIP, but from what I've seen it's still not 100% so to speak. From some connections I have in this subfield (friend of a friend kind of dealio), I've heard that AMD is working on some architecture to beat out Nvidia and come back in a big way, and at the same time release something akin to HIP but better. They're just taking longer than expected because Nvidia does things like come up with Ampere.

-2

u/allinwonderornot Sep 20 '20

Lol yeah when the paper was written, it's still called ATI. Very relevant indeed!

Well, enjoy your vendor lock-in then.

7

u/13steinj Sep 20 '20

I'm sorry there aren't more recent papers going into in-depth performance metrics. However:

If you compare them, on the same cards, you still, even now, see a minimum of a 12-25% performance increase in using cuda. E: to clarify, more depending on the specifics of your workflow.

Like I don't know if this is AMD shilling or what, but it's not really vendor lock in given the lifecycle of this kind of software, which is mostly used in research.

I also can't really think of any major GPU code that isn't rewritten often or stopped being used after a year. Also worst case...just translate it? And until AMD fulfills on that rumor I mentioned, someone else already wrote such a translator.

5

u/forthemostpart Sep 20 '20

Consider me a noob here, but how can we be sure any of this is fairly assessed? If CUDA only works on Nvidia, then it seems to me that the comparison between CUDA and OpenCL can only be done on Nvidia GPUs. Considering Nvidia owns CUDA, I feel like a conflict of interest could arise here.

3

u/josefx Sep 20 '20

The Geekbench OpenCL benchmark has quite a few NVIDIA cards at the top. So even if NVIDIA is crippling OpenCL performance intentionally it still seems to beat everything in a direct comparison.

2

u/13steinj Sep 20 '20

This is the TLDR2 of my response, thanks for saying it in so few words whereas I'm rambling and tired.

3

u/13steinj Sep 20 '20 edited Sep 20 '20

Oh no you're definitely right-- but the argument was "open API". So you only have two options really-- use the same open API and compare on the same cards, in which case, for whatever reason (conflict of interest included) Nvidia wins.

Of course, not much point in neutering OpenCl on Nvidia cards, at least other than not releasing information about how the GPU works internally-- in the end no matter what language you use things basically get translated (say, to ioctls) and sent over the bus. But there's nothing stopping anyone from reverse engineering which ioctls to use either.

Now again, let's say for whatever reason it's not a fair comparison-- fine, go with the second option. Take the comparable AMD GPU, and the best compute language that works there-- you'll still see a significant gap in performance. But then the question is "well, what if the issue here is a hardware gap", in which case the answer is "you'd be buying the better GPU in that case anyway, at which point because of the lifecycle of this kind of software vendor lock is a non-issue / not really even existent".

Until AMD can come up with a truly comparable GPU (compute or otherwise) to Nvidia's offerings, any vendor lock that exists isn't an issue because you wouldn't be using AMD here. It's the same thing with the CPU game-- AMD for years was stuck in a rut having to win on the price:perf ratio. Slowly they beat out Intel in multi-core performance, and threadripper/epyc + the new zen architecture was a big blow to Intel (though I think Intel still beats out AMD in single core performance-- hopefully a zen 3 announcement changes that).

In the same way, I hope eventually AMD catches up GPU wise...but as of right now, people will be buying nvidia. So either the argument is "open > closed" in which case, who cares, there's only one vendor with a large enough punch, or "you'll be sorry in 10 years!", which, who cares, lifecycle of many of these pieces of software is <3 years.

E: added 5 words for clarity.

0

u/[deleted] Sep 20 '20

[deleted]

5

u/[deleted] Sep 20 '20

Or Hardware Ray Tracing, which is honestly mind boggling how easy it is to use and map to scientific workloads using optix.

Nvidia has the high ground and I don’t see anyone getting out of CUDA for masssively parallel programming.

SYCL is in infancy right now and CUDA keeps getting better and better. The extremely large install base, not in cloud and university HPC systems only furthers the lock in.

With all of that said, buy NVDA stock.

1

u/_-ammar-_ Sep 20 '20

AMD still have bad driver in both linux and windows

the only way to use AMD GPU is by using community open source driver to get full prefromnce out of your hardware

4

u/vikigenius Sep 20 '20

This is actually pretty neat, and from the documentation, seems incredibly easy to use.

4

u/StromaeNotDed Sep 20 '20

What would be a use case of this?

7

u/13steinj Sep 20 '20 edited Sep 20 '20

Say you need an atomic variable. Also say for whatever reason you need this to do an atomic operation on this variable at some point on the host, on another point on the device. Under normal circumstances you'd have pain points, because you'd essentially need to create a wrapper class that uses a std::atomic on the host and otherwise still "works" when passed to the device. Here they made that wrapper for you.

Hopefully eventually, container support gets added. So like the thrust library for cuda, but without having to manually copy things over host to device and visa versa.

E: to clarify, traditionally, you'll see code that offloads to a GPU, maybe involves some atomic variables to do the work. But besides the difficulty in implementation, there's no reason you can't theoretically also use CPU threads.

So, assuming you meet cuda's memory-based restrictions, this additionally allows for a use of an atomic variable that works both in the CPU and the GPU, at the same steps of execution. Which is the (arguably) bigger deal.

8

u/BladedD Sep 20 '20

Seems awesome. Can’t wait to check it out tomorrow

going to try cuda::std::cout <<“Hello World”;

11

u/josefx Sep 20 '20

At least you didn't put a std::endl at the end. The performance impact of several thousand forced parallel io flushes to the same stream gives me a headache just thinking about it. Always remember: use '\n' to denote an end of line, std::flush to flush and never use std::endl unless you are printf debugging your program.

2

u/PsyLich Sep 20 '20

I was told by a senior programmer that ‘\n’ doesn’t always work as there may be operating systems that don’t have it as a default “end of line”. Can you confirm that?

9

u/josefx Sep 20 '20

The implementation of std::endl is defined based on '\n' and flush. So they should both break for the same reasons. Either your senior programmer had a run in with a buggy standard library that got '\n' wrong without also breaking std::endl or he has a habbit of opening text streams in binary mode, in which case std::endl shouldn't work either.

6

u/max0x7ba Sep 20 '20

On Linux, standard output is line buffered on a terminal and block buffered when redirected into a file or a pipe. The latter is probably why \n wasn't enough for that senior programmer.

1

u/PsyLich Sep 20 '20

Ohh that makes sense. Thanks for explaining.

0

u/13steinj Sep 20 '20

Uh, unfortunate part is AFAIK iostreams are not currently supported? Unless I'm misunderstanding something. Seems to be on the backburner.

2

u/BladedD Sep 20 '20

My comment was more of a joke lol

Not really sure what benefit Cuda could have for iostreams haha, but I didn’t know it wasn’t supported at all. Good info to know though, thanks

2

u/13steinj Sep 20 '20

Yeah currently it's incredibly limited mostly to multiple access primitives.

2

u/13steinj Sep 19 '20

Hot damn I've needed something like this for a year!

2

u/[deleted] Sep 20 '20

Would this be different from something like, say Boost?

4

u/13steinj Sep 20 '20

AFAIK, boost has no cuda-specific device available code. What this provides is

  • libc++

  • additions to libc++ allowing you to use the same type, and in some cases, same object, in both host and device code, the latter letting you "fully utilize your machine" with greater ease, so to speak (currently this is limited to a specific but growing subset of the STL)

  • cuda-specific extensions to STL objects (which only make sense on device)

1

u/[deleted] Sep 20 '20

Thanks for clarifying.

-8

u/Mgladiethor Sep 20 '20

Until cuda dies, fuck no

10

u/13steinj Sep 20 '20

I don't follow. This is to be used with cuda code; as in, cuda and C++ compliant standard library usable in both host and device code. More specifically, a large amount is an offshoot of libc++ standard library, with a growing subset gaining quick, easy, cuda interoperability.

E: unfortunate part is lack of documentation, seems to be a lot of "TODO".

0

u/[deleted] Sep 19 '20

[deleted]

9

u/alsatian-studio Sep 20 '20

Just want to add, in Vietnamese, "cu" means "penis"

18

u/txdv Sep 19 '20

would tou be so kind to eaborate?

66

u/ElectroDr Sep 19 '20

Cu means ass in Portuguese

64

u/Glacia Sep 19 '20

23

u/QualitySoftwareGuy Sep 19 '20

First thing I saw when I clicked that link was "ass_shaper", lol.

11

u/Theemuts Sep 19 '20

Get it

10

u/panties_in_my_ass Sep 20 '20

Information about the ASS format:

  • ASS specification (incomplete)

  • ASS override

5

u/megayippie Sep 20 '20

Everything means ass or penis in portuguese. Never order bread in São Paulo...

3

u/ducttapecoder Sep 20 '20

That's still short as Cu means dick in Vietnamese

7

u/patlefort Sep 19 '20

Also means ass in Quebec french slang :)

11

u/foreheadteeth Sep 19 '20

It's not Québec slang, it's plain old French. It may be used in a vulgar fashion to refer to someone's ass, but it can also be used in a non-vulgar way ("cul de sac").

0

u/[deleted] Sep 20 '20

[deleted]

5

u/foreheadteeth Sep 20 '20

Dead end street.

2

u/treefox Sep 19 '20

“Error: missing library: libass.so.5”

6

u/TalesM Sep 19 '20

Brazilian here too, and very amused, hahaha

1

u/AttackOfTheThumbs Sep 19 '20

We use CU as a standard abbreviation at work. I chuckle most days.

-5

u/CJSZ01 Sep 19 '20

Caralho?

-21

u/squareswordfish Sep 19 '20

Are you also 10?

12

u/Narase33 Sep 19 '20

Oh look, a grown up. See, nobody cares

2

u/_-ammar-_ Sep 20 '20

yes.

-4

u/squareswordfish Sep 20 '20

Apparently the whole sub is lol. This word is as funny as “assassin” (it has ass in it twice hahahahah!!!)

0

u/[deleted] Sep 20 '20

[deleted]

3

u/PsyLich Sep 20 '20

Weirdest comment I’ve seen in a while and there is quite the competition...

To answer your question, he either works for some security company(may be even government) on a very high level, or he is doing something illegal with his hacking/coding skills, there is also the small chance of him cheating on you.