Remix.run Logo
ryao 14 days ago

  CUDA was born from C and C++
It would be nice if they actually implemented a C variant of CUDA instead of extending C++ and calling it CUDA C.
pjmlp 14 days ago | parent | next [-]

First of all they extend C, and with CUDA 3.0, initial support was added for C++, afterwards they bought PGI and added Fortran into the mix.

Alongside for the ride, they fostered an ecosystem from compiled language backends targeting CUDA.

Additionally modern CUDA supports standard C++ as well, with frameworks that hide the original extensions.

Most critics don't really get the CUDA ecosystem.

ryao 14 days ago | parent [-]

They replaced C with C++. For example, try passing a function pointer as a void pointer argument without a cast. C says this should work. C++ says it should not. There are plenty of other differences that make it C++ and not C, if you know to look for them. The fact that C++ symbol names are used for one, which means you need to specify extern “C” if you want to reference them from the CUDA driver API. Then there is the fact that it will happily compile C++ classes where a pure C compiler will not. There is no stdc option for the compiler.

pjmlp 13 days ago | parent [-]

They replaced most of the documentation with C++ examples, given the benefits the language has over C, that was already obvious to me in 1993.

As for the language extensions required by CUDA C, it is kind of interesting that clang and GCC extensions are praised and people keep referring to them as C, while everyone else's extensions are never C or C++ under the same measure.

With OpenAAC directives, an HPC industry standard, you can make use of plain old C11 with traditional #pragmas,

https://developer.nvidia.com/openacc

ryao 12 days ago | parent [-]

I used to like C++. Then it caused me headaches one too many times because of things it implemented that C did not have. Now I prefer to use C whenever I can, since it avoids entire classes of headaches that only exist in C++.

swyx 14 days ago | parent | prev [-]

why is that impt to you? just trying to understand the problem you couldnt solve without a C-like

ryao 14 days ago | parent | next [-]

I want to write C code, not C++ code. Even if I try to write C style C++, it is more verbose and less readable, because of various C++isms. For example, having to specify extern “C” to get sane ABI names for the Nvidia CUDA driver API:

https://docs.nvidia.com/cuda/cuda-driver-api/index.html

Not to mention that C++ does not support neat features like variable sized arrays on the stack.

pjmlp 13 days ago | parent [-]

A neat feature that is so neat Google paid to get it irradicated from Linux kernel, and became optional after C11.

ryao 10 days ago | parent [-]

I think you replied to the wrong person.

kevmo314 14 days ago | parent | prev [-]

A strict C variant would indeed be quite nice. I've wanted to write CUDA kernels in Go apps before so the Go app can handle the concurrency on the CPU side. Right now, I have to write a C wrapper and more often than not, I end up writing more code in C++ instead.

But then I end up finding myself juggling mutexes and wishing I had some newer language features.