3 ms·
> why would anyone start a greenfield project like this in C++ these days? TLDR: quite often, using C++ instead of Rust saves software development costs. Some
by Const-me 3y ago
> why would anyone start a greenfield project like this in C++ these days?
TLDR: quite often, using C++ instead of Rust saves software development costs.
Some software needs to consume many external APIs. Examples on Windows: Direct3D, Direct2D, DirectWrite, MediaFoundation. Examples on Linux: V4L2, ALSA, DRM/KMS, GLES. These things are huge in terms of API surface. Choose Rust, and you gonna need to write and support non-trivial amount of boilerplate code for the interop. Choose C++ (on Linux, C is good too) and that code is gone, you only need well-documented and well supported APIs supplied by the OS vendors.
Similarly, some software needs to integrate with other systems or libraries written in C or C++. An example often relevant to HPC applications is Eigen. Another related thing, game console SDKs, and game engines, don’t support Rust.
For the project being discussed here, GGML, for optimal performance the implementation needs vector intrinsics. Technically Rust has the support, but in practice Intel and ARM are only supporting them for C and C++. Not just CPU vendors, when using C or C++ there’re useful relevant resources: articles, blogs, and stackoverflow. These things help a lot in practice. I don’t program Rust, but I program C# in addition to C++, technically most vector intrinsics are available in the current version of C#, but they are much harder to use from C# for this reason.
All current C and C++ compilers support OpenMP for parallelism. While not a silver bullet, and not available on all platforms supported by C or C++, some software benefits tremendously from that thing.
Finally, it’s easier to find good C++ developers, compared to good Rust developers.
- galangalalgol 3y agoThere are existing supported bindings for direct3d from MS, as they themselves are migrating. GLES and ggml also have supported bindings. I like nalgebra + rustfft better than eigen now. Nalgebra still isn't quite as peformant on small matricies until const generic eval stabilizes, but it is close enough for 6x6 stuff that it is in the noise. Rustfft is faster than fftw even. Rust has intrinsic support on par with clang and gcc, and the autovectorizer uses whatever llvm know about, so again equivalent to clang. On the last point, I will again assert that a good c++ developer is just a good rust developer minus a month of ramp, that you'll get nack from not having to fight combinations of automake, cmake, conan, vcpkg, meson, bazel and hunter.
- Const-me 3y agoI'll be very surprised if MS will ever support rust bindings for media foundation. That thing is COM based, requires users to implement COM interfaces not just consume, and is heavily multithreaded. About SIMD, automatic vectorizers are very limited. I was talking about manually vectorized stuff with intrinsics. I've been programming C++ for living for decades now. Tried to learn rust but failed. I have an impression the language is extremely hard to use.
- theLiminator 3y agoCurious how long you tried to learn rust? I've found C++ much harder to learn (coming from a python/scala) background. Is it just a case of you forgetting how hard C++ was to learn?
- Const-me 3y agoI have minimal experience with Rust. OTOH, programming C++ for living since 2000, with a few gaps when I used other languages like Obj-C and C#. I agree C++ is very hard to learn if you only have experience with higher-level languages like Python and Scala. I think there’re two reasons for that. C++ is unsafe. There’s no way around this one, it was designed that way, like C or assembly. Still, with modern toolset it’s not terribly bad. Compilers print warnings, BTW I typically ask them to treat warnings as errors to deliberately fail the build. On Windows, a combination of debug build, debug C runtime, and visual studio debugger helps tremendously. Linux compilers have these sanitizers (address, memory, thread, undefined behavior) which are comparable, they too sacrifice runtime speed for diagnostics and debuggability. Another reason, the language itself is very complicated, especially the templates. However, just because something is in the language doesn’t mean it’s a good idea to use it. You don’t need to be familiar with that stuff unless doing something very advanced, like customizing the Eigen C++ library. Don’t follow the patterns found in the standard library: unlike your code, that library has good reasons to use that template BS. If instead of templates you do something else, C++ becomes much easier to use, and most importantly other people will still be able to read and understand your code. Another reason to avoid excessive template metaprogramming, it slows down the compiler, because template-heavy code often needs to be in headers as opposed to cpp files. P.S. If you don’t need extreme levels of performance (defined as “approach the numbers listed in CPU specs”, the numbers are FLOPS or memory bandwidth), and you don’t need the ecosystem too much, consider C# instead of C++. Much faster than Python, often faster than Scala or Java, easy integration with C should you need that (about the same as Rust, much easier than Python or Java), the only downside is these ~100MB of the runtime. The reputation is weird, but technically the language and runtime are pretty good. For example, here’s a C# library which re-implements a subset of ffmpeg and libavcodec C libraries for one particular platform, Linux on Raspberry Pi4: https://github.com/Const-me/Vrmac/tree/master/VrmacVideo https://github.com/Const-me/Vrmac/tree/master/VrmacVideo