r/cpp • • Apr 30 '26

I made a super fast CNN library for C++20 from scratch.

68 Upvotes

I was exploring Convolutional Neural Networks (CNNs) in more depth and I had an interesting idea of making a dependency free, header only cnn library for C++20.

I did some research and found out about tiny-dnn which is a cnn library for c++14, super fast but the developers stopped updating it back in 2016, so I decided to take on a challenge to make my own CNN library from scratch for c+ +20 with extreme performance tuning for CPU, and I did achieve close to what I was expecting.

I benchmarked with "pytorch" and the results were good enough to post, I have documented about the library here along with the benchmark results. At some instances it outperformed pytorch and I was shocked too.

Documentation- "https://kunwarprabhat.github.io/MetalNet_Documentation/

To get a rough idea on how fast is my engine it goes 97.51% accuracy on mnist dataset in just 25 seconds of training with a throughput of 2k+ images / second.

processor - Ryzen 7 5800H mobile

For overview -

My engine uses DAG layout

It has Zero Allocation

Multithreading Support

L1/L2 Cache Optimization

and a lot of internal stuffs going on, here is the repository link-

"https://github.com/KunwarPrabhat/CustomCNN"

My engine is still in its early stage so there are alot of things that can be fixed I need more devlopers to contribute if they're interested in it :))

Edit : By zero allocation, I meant to say my engine pre allocates memory so it doesn't have to ask OS for allocation during inference. I am not saying it doesn't use memory at all I am saying it doesn't allocate during runtime, it's basically a pre-allocation.


r/cpp • • Apr 30 '26

Safe Optimistic Lock Coupling

Thumbnail databasearchitects.blogspot.com
9 Upvotes

r/cpp • • Apr 30 '26

Is anyone still using the CTRE library in 2026?

16 Upvotes

Back in 2018 an engineer/committee member made a splash by introducing CTRE, Compile Time Regular Expressions.

It was implemented using type aliases instead of constexpr function calls meaning it was easy to implement in C++11. Very impressive stuff.

It also gave you a nicer callsite spelling in C++20 leveraging generalized non-type template parameter passing.

I'm curious if anyone is still using it. If no, why not? I'd love to hear!


r/cpp • • Apr 30 '26

C++26: string and string_view improvements

Thumbnail sandordargo.com
70 Upvotes

r/cpp • • Apr 30 '26

Fast GPU Linear Algebra via Compile Time Expression Fusion

Thumbnail arxiv.org
28 Upvotes

r/cpp • • Apr 30 '26

Some theory and practice of alignment in C++ (guide part 3).

Thumbnail pvs-studio.com
21 Upvotes

If you haven’t seen parts 1 and 2 yet, they go over the basics and ordinary inheritance.
This one is about what happens when you add virtual to a class (spoiler: it can seriously mess with the whole memory layout)


r/cpp • • Apr 30 '26

GCC 16.1 released with many new C++26/23 features, C++20 now the default stable language version

Thumbnail gcc.gnu.org
263 Upvotes

r/cpp • • Apr 30 '26

What do you think is a keyword that should be added to C++?

74 Upvotes

r/cpp • • Apr 29 '26

ACAV v1.0.0: an open-source GUI tool for exploring Clang ASTs in C/C++ projects

24 Upvotes

I am the author of ACAV, the Aurora Clang AST Viewer, and I have just made the first public release, v1.0.0.

ACAV is an open-source Qt desktop application for exploring Clang ASTs in C, C++, Objective-C, and Objective-C++ projects that provide a `compile_commands.json` compilation database.

It supports source-to-AST navigation, AST-node search, source-code search, declaration-context views, selected-subtree JSON export, and background AST generation/caching.

Links:

- GitHub: https://github.com/uvic-aurora/acav

- Release: https://github.com/uvic-aurora/acav/releases/tag/v1.0.0

- Manual: https://uvic-aurora.github.io/acav-manual/index.html

- Demo video: https://youtu.be/0M7dYAlnrTI

There are also prebuilt Docker/Podman demo images for LLVM 20, 21, and 22.

https://github.com/uvic-aurora/acav/pkgs/container/acav

I would appreciate feedback from C++ users, especially anyone who works with Clang tooling or wants a more visual way to inspect ASTs.


r/cpp • • Apr 29 '26

Cpp Files Still Help Breaking Build Dependencies of Modules

Thumbnail abuehl.github.io
5 Upvotes

Nothing spectacular, but it helps to remember that cpp files still provide another level for breaking dependencies.


r/cpp • • Apr 29 '26

atomic_queue benchmarks SMT vs no-SMT performance

Thumbnail max0x7ba.github.io
15 Upvotes

atomic_queue benchmark charts have recently been updated with separate charts for benchmark runs with SMT threads and without (cross-core).

The cross-core performance charts have not been available before.


r/cpp • • Apr 29 '26

I tried compile-time heapsort in TMP. It basically became selection sort.

14 Upvotes

Tried implementing compile-time sorting with old-school TMP (recursive templates, no constexpr). Yeah, constexpr sort exists now, but I wanted to see how far pure template recursion could go. Quicksort and mergesort worked fine. Heapsort was the one that broke.

Then it clicked: heapsort assumes cheap random access. Parent node, left child, right child, all index arithmetic. But in a typelist like arr<5, 3, 8, 1> there's no arr[i]. Every element access peels the head off recursively, so it's O(n) per lookup. Heapify becomes expensive, sift-down becomes expensive, and the whole thing degrades.

What I actually ended up with was... selection sort. Find the min by scanning the whole list, pull it out, recurse. O(n²) template instantiations. Not great.

Quicksort doesn't have this problem because it just filters into two sublists (less-than pivot, greater-than pivot). No indexing needed. Mergesort splits with take/drop which is O(n) but only happens once per level, so it stays O(n log n) overall.

I didn't really clock the random access dependency until I was halfway through writing the heap version. Felt kind of dumb in retrospect. Never really felt how much big-O depends on the data structure until TMP took away my arrays.

Full code in comments if anyone wants to look at it. Fair warning the mergesort lives in namespace www because I was iterating on these in separate files and never bothered renaming.

Anyone else run into algorithms that stop making sense in TMP?


r/cpp • • Apr 28 '26

A Principal Software Engineer at Epic Games / 25 Year Vet, talks about why AI is just a "giant switchboard" and why code is a delicate crystal.

176 Upvotes

I’ve been thinking a lot about how people actually get comfortable with complex topics like programming, not by tutorials, but by just being passively around the conversations.

So I recorded one of those conversations.

I sat down with Dietmar Hauser (25+ years in the industry, Principal Software Engineer at Epic), and we went from Commodore 64 days, literally typing code out of magazines. All the way to modern C++ and where we find ourselves at the moment with another layer of abstraction = LLMs.

What stuck with me wasn’t just the history, but how he talks about coding as this fragile, interconnected system (“a delicate crystal”), that shatters if you touch the wrong thing, which i found very interesting.

It’s a long, unfiltered discussion, more like something you overhear between two people deep in the field than a structured interview.

If you’re trying to get a feel for how experienced engineers actually think about code, or if you wanna warm up to the idea, this convo might be useful:
https://youtu.be/PE3aCgSHvTQ


r/cpp • • Apr 28 '26

boost::container::hub ACCEPTED into Boost

69 Upvotes

Hi to all, I'm glad to announce that the proposed boost::container::hub container has been ACCEPTED. Congrats u/joaquintides !

More details here:

https://lists.boost.org/archives/list/boost@lists.boost.org/thread/7WZ7QTPE2YDYD5OYCKXKKV2N74JHJRZL/

Reminder:

hub is a sequence container with O(1) insertion and erasure and element stability with great performance (see these benchmarks): pointers/iterators to an element remain valid as long as the element is not erased. hub is very similar but not entirely equivalent to C++26 std::hive (hence the different naming, consult the section "Comparison with std::hive" for details).


r/cpp • • Apr 28 '26

Things C++26 define_static_array can’t do

Thumbnail quuxplusone.github.io
43 Upvotes

r/cpp • • Apr 28 '26

New features in GCC 16: Improved error messages and SARIF output

Thumbnail developers.redhat.com
114 Upvotes

r/cpp • • Apr 27 '26

The fastest Linux timestamps

Thumbnail hmpcabral.com
58 Upvotes

r/cpp • • Apr 27 '26

Florent Castelli: Introduction to the Bazel build system

Thumbnail youtu.be
61 Upvotes

An introduction to Bazel, the open-source build system designed to make C++ development fast, deterministic, and scalable for any team size.


r/cpp • • Apr 27 '26

New C++ Conference Videos Released This Month - April 2026 (Updated To Include Videos Released 2026-04-20 - 2026-04-26)

15 Upvotes

CppCon

2026-04-20 - 2026-04-26

2026-04-13 - 2026-04-19

2026-04-06 - 2026-04-12

2026-03-30 - 2026-04-05

C++Online

2026-04-20 - 2026-04-26

2026-04-13 - 2026-04-19

2026-04-06 - 2026-04-12

2026-03-30 - 2026-04-05

ADC

2026-04-20 - 2026-04-26

2026-04-13 - 2026-04-19

2026-04-06 - 2026-04-12

2026-03-30 - 2026-04-05

Meeting C++

2026-04-06 - 2026-04-12

2026-03-30 - 2026-04-05

using std::cpp

2026-03-30 - 2026-04-05


r/cpp • • Apr 26 '26

The Hidden Performance Price of C++ Virtual Functions

Thumbnail youtube.com
61 Upvotes

At the online weekend series by Global C++, Ivica from https://johnnysswlab.com/ explains, with examples, what the actual cost of using virtual functions in current C++ with modern hardware actually is.


r/cpp • • Apr 26 '26

"Parse, don't Validate" through the years with C++

Thumbnail derekrodriguez.dev
55 Upvotes

It's been a few years since I worked with C++ on a day-to-day basis in a professional capacity, but I like writing blog posts every now and then, and thought I would put my own spin on the evergreen "Parse, don't validate", by Alexis King. Feedback is welcome!


r/cpp • • Apr 26 '26

I made my C++ vector search engine 16x faster by changing data layout, not the algorithm

Thumbnail dubeykartikay.com
120 Upvotes

I’m working on a small vector search engine in C++ and spent some time cleaning up the Vamana search path.

The big win came from getting rid of a pointer-heavy layout and moving to flatter arrays / lighter-weight views. Same algorithm and recall, but much lower query latency in my benchmark.


r/cpp • • Apr 26 '26

Is there a C++ "venv" equivalent?

105 Upvotes

Python have venv, Rust have cargo, Node have nvm. You clone a repo, run one command, you're in a reproducible environment.

Is there a viable alternative for C++? I don't think standard will ever bother with this and to their defence, not sure if that is even possible.

I've tried Conan, vcpkg, various CMake setups. They're not bad tools, but there's no standard "activation" ritual. No isolated-per-project environment that pins compiler + deps + toolchain together. No single lockfile that means the same thing on my machine, my colleague's machine, and CI. What I keep wanting is something like: "cppenv activate" and suddenly I'm in a clean, isolated, reproducible build environment for that project. Exit it, and my system is untouched. Share a lockfile, and a teammate gets the exact same thing.

How are you handling reproducible build/development environments?


r/cpp • • Apr 26 '26

Code Examples From an App Using C++ Modules

Thumbnail abuehl.github.io
16 Upvotes

This demonstrates usage of our recommendations for using modules:

  • Prefer small modules
  • Only use partitions if you really must
  • Avoid using internal partitions

The intention is to show some real code for context of discussions about using C++ modules.

My goal is not to sell modules. If you prefer not using modules: Use header files. There are good reasons to continue using them.

For me, C++ source code is an asset. The intrinsic value of code using modules is higher (lower entropy), as modules are a higher abstraction, compared to header files, which are basically just the pasting of C++ code into translation units (I've done that for ~36 years now).

Using C++ modules comes at a cost though. Understanding modules requires a certain level of understanding, which isn't needed when using the simple model and tradition of header files.