7 routes42 sections324 units

Section 7 of 7 · Programming & Data Foundations

C & C++ Systems Literacy

GPU kernels, runtimes and Python extensions cross native boundaries. You need enough layout, lifetime and build fluency to make a safe bounded change and understand the resulting machine behavior.

9 units 18 topics 0/9

Units

9 in this section

  1. 7.1 Compiling, linking, loading, ABI and C linkage
    explain
    4 h
  2. 7.2 Integer representation, pointers, references and spans
    explain · implement
    4 h
  3. 7.3 Struct layout, alignment, strides and locality
    derive · measure
    5 h
  4. 7.4 Storage duration, RAII, smart pointers and move semantics
    explain · implement
    6 h
  5. 7.5 Templates, containers and iterator invalidation
    explain
    4 h
  6. 7.6 Undefined behavior, sanitizers and debugger evidence
    measure
    4 h
  7. 7.7 Threads, data races, memory ordering and atomics
    explain
    4 h
  8. 7.8 Python and native code: dtype, stride, ownership and GIL contracts
    explain
    5 h
  9. 7.9 Repeatable CMake builds and test targets
    implement
    5 h

Before moving on

Checkpoint

Build a tiny Python-callable C++ component, explain its layout and ownership, and repair one seeded lifetime or bounds error from sanitizer evidence in a clean build.

Deliberately out of scope

Leave for later

  • Advanced template metaprogramming and compiler construction
  • Large native application architecture
  • Lock-free data structures beyond literacy

Resources for this section

Shared by every unit above

  • AlgoMaster C++
    AlgoMastercourse
    primary
    Use the sections on compilation, pointers and references, memory, RAII and smart pointers, copy and move, STL containers, templates, errors, concurrency and paired exercises. Skip competitive-programming breadth already covered in Algorithms.
  • C++ Core Guidelines
    Standard C++ Foundation communityreference
    required
    Use the Philosophy, Interfaces, Resource management, Expressions, Containers and concurrency rule groups to review ownership and safety decisions in the native component.
  • cppreference
    cppreference communityreference
    support
    Consult language lifetime, object model, value categories, memory model, atomics, containers and iterator invalidation while reading or modifying code.
  • Clang AddressSanitizer and UndefinedBehaviorSanitizer
    LLVMimplementation
    required
    Compile seeded memory defects with AddressSanitizer and UndefinedBehaviorSanitizer, preserve the reports, repair the root cause and keep regression tests.
  • pybind11 documentation
    pybind11 projectimplementation
    required
    Follow First steps and NumPy support to expose one small native function with explicit shape, dtype, stride, ownership, GIL and exception behavior.
  • CMake tutorial
    CMakeimplementation
    support
    Use the introductory steps for targets, libraries, testing and install rules. Produce one clean debug build and one optimized build without copied one-off commands.
  • Algorithmica - AoS and SoA
    Sergey Slotinapplication
    support
    Read the AoS and SoA experiment for a measured case where keeping each record together wins, the counterpart to a single-field scan.
  • `ld.so`: dynamic linker/loader
    Linux man-pages projectreference
    support
    Read DESCRIPTION, Dynamic string tokens and LD_DEBUG to distinguish link-time symbols from runtime shared-library discovery on Linux.
  • Memory Layout Transformations
    Intelreference
    support
    Read Overview and Topics through AOS Form and SOA Form for field-wise access and locality trade-offs. Skip Intel array-notation syntax and the LIBOR example.
  • GDB manual: Backtraces
    GNU Projectreference
    support
    Use section 8.2 for frame numbers, bt, bt -full and optimized-out arguments when inspecting a native failure.

Apply the section

Mini-project · Native run-duration histogram with a strict pybind11 binding and a sanitizer-backed repair (12 to 16 h)

Move the run-duration histogram into C++ behind a strict Python boundary. Build it with CMake in debug, release and sanitizer trees, test it against NumPy, and follow one sanitizer report from evidence to regression test.

Steps

  1. Write the histogram core over spans with an owning Histogram class, and test copy independence, moves and bounds errors in a native test executable, using the AlgoMaster RAII and Copy-and-Swap Idiom exercises as reference.
  2. Seed an off-by-one that overflows the bins, capture the sanitizer report in a sanitizer build tree, repair it, connect the report to the frame with gdb, and keep the input as a regression test.
  3. Test the histogram against numpy.histogram on random values and on values at and beside every edge, then adopt NumPy's edge rule or document and test your own.
  4. Bind the core with pybind11 under dtype, shape, stride, alignment, ownership, exception and GIL contracts, and test every accepted and rejected input plus output lifetime.
  5. Build debug, release and sanitizer trees with CMake following the CMake Tutorial building and testing steps and register the native tests with CTest, then document the exported symbols and linked libraries and diagnose one link or loader failure from its message.
  6. Document the record layout from measured offsets, compare array-of-struct and struct-of-array scans with equal checksums, and split one call across threads with private bins merged after join, alongside a shared atomic-bin variant.

Deliverables

  • The native component: core library, owning Histogram, native tests, extension module and CMake trees.
  • The sanitizer write-up with the preserved report, the gdb session and the regression test.
  • Binding and oracle tests plus a boundary note with symbols, libraries, the diagnosed failure and the layout comparison.

Checks

  • rubric · Self-grade with the rubric below

Rubric

CriterionPassStrong
Oracle agreementThe binding agrees with numpy.histogram on random data and at every edge, or a documented edge rule is tested instead.Edge cases come from a generator, and a naive index version is kept as a comparison that fails.
Strict boundaryWrong dtype, lists, strided, reversed and multi-dimensional inputs are rejected with the stated exception types, and the result outlives the input.The binding names the owner of every buffer and the GIL state at each point.
Sanitizer repairThe report is preserved and explained, and the regression fails on the seeded code and passes after the repair.The write-up names what the sanitizers cannot prove here, such as a wrong but in-bounds bin.
Build and ABIDebug, release and sanitizer trees build from scratch, CTest catches a false check, and one failure is diagnosed from its message.The note says which upgrades force a rebuild of the extension and why.
Layout evidencePredicted offsets match the measured ones, both layouts agree, and raw timings are kept.The report separates the measured difference from cache explanations it did not test.

Feeds into: The Python-native histogram, its sanitizer-backed repair and the evidence-first debugging report for the capstone.

Quick find

Search Michi

Type to search every route, section, unit, topic and resource.

Enter opens the first result Esc closes

Reference

Keyboard shortcuts

n
Continue to the first unit not passed
j / k
Next / previous unit
1 2 3
Toggle learned, practised, passed
/
Open search
?
Show this help
Esc
Close open panels