|
1 | | -# live-cpp-tutorials |
| 1 | +# live-cpp-tutorials |
| 2 | + |
| 3 | +`live-cpp-tutorials` is a collection of interactive Jupyter notebooks for learning C++, OpenMP, and CUDA - all powered by the [xeus-cpp](https://github.com/compiler-research/xeus-cpp) kernel. Code compiles and runs directly in the notebook; no local toolchain setup is required beyond the conda environment. |
| 4 | + |
| 5 | +Join our discord for discussions and collaboration. |
| 6 | + |
| 7 | +[](https://discord.gg/Vkv3ne4zVK) |
| 8 | + |
| 9 | +## About |
| 10 | + |
| 11 | +Each notebook series builds on the previous, taking you from core C++ through shared-memory parallelism with OpenMP to GPU programming with CUDA. Kernels are incremental - state, variables, and `#include`s persist across cells exactly like a Python notebook. |
| 12 | + |
| 13 | +The CUDA notebooks run on a CUDA 12-capable GPU and produce images rendered inline in the notebook. |
| 14 | + |
| 15 | +## Notebooks |
| 16 | + |
| 17 | +### C++ (`xeus-cpp/`) |
| 18 | +An introduction to modern C++ through live, interactive examples. Topics include basic syntax, standard containers, templates, and the C++ standard library—all executed cell-by-cell without leaving the browser. These tutorials leverage the Jupyter Notebook interface to allow deep exploration of C++ features like memory management, lambda expressions, object-oriented concepts, and advanced standard library structures in a highly visual, incremental manner. |
| 19 | + |
| 20 | +### OpenMP (`openmp/`) |
| 21 | +CPU parallelism using OpenMP pragmas. Covers `#pragma omp parallel`, loop-level parallelism, reductions, and thread synchronization using the OpenMP-enabled `xeus-cpp` kernel. The notebooks guide you step-by-step from foundational concepts like spawning threads and managing shared vs. private data variables, all the way to advanced patterns like task-based parallelism, critical sections, and optimizing performance loops directly in an interactive environment. |
| 22 | + |
| 23 | +### CUDA (`cuda/`) |
| 24 | +GPU programming from first principles using CUDA C++. This section explores how to accelerate compute-heavy workloads by utilizing graphics cards. It covers essential GPU architecture concepts, kernel declarations, memory allocation (`cudaMalloc`), host-to-device data transfers, and thread organization across grids and blocks to give you hands-on experience writing raw parallel code optimized for parallel hardware. |
| 25 | + |
| 26 | +## Installation |
| 27 | +To ensure a clean setup, install `live-cpp-tutorials` inside a fresh environment using Micromamba. |
| 28 | + |
| 29 | +Clone the repository and move into the directory: |
| 30 | + |
| 31 | +``` |
| 32 | +git clone --depth=1 https://github.com/compiler-research/live-cpp-tutorials.git |
| 33 | +cd live-cpp-tutorials |
| 34 | +``` |
| 35 | + |
| 36 | +Create and activate the environment: |
| 37 | + |
| 38 | +``` |
| 39 | +micromamba env create -f environment.yml |
| 40 | +micromamba activate livecpp-ci |
| 41 | +``` |
| 42 | + |
| 43 | +Launch Jupyter: |
| 44 | + |
| 45 | +``` |
| 46 | +jupyter lab |
| 47 | +``` |
| 48 | + |
| 49 | +The environment provides: |
| 50 | + |
| 51 | +- `xeus-cpp` - Jupyter kernel for C++ (Clang 21 / C++23) |
| 52 | +- `llvm-openmp` - OpenMP runtime for the parallel notebooks |
| 53 | +- `cuda-toolkit 12` - CUDA compiler and runtime for the GPU notebooks |
| 54 | + |
| 55 | +## How it works |
| 56 | + |
| 57 | +xeus-cpp wraps [Clang-Repl](https://clang.llvm.org/docs/ClangRepl.html) - an incremental C++ compiler - behind the [Jupyter protocol](https://jupyter-client.readthedocs.io/en/stable/messaging.html). Each cell is compiled and executed in the same persistent process, so definitions carry across cells. The CUDA notebooks additionally link against the NVIDIA runtime so `__global__` kernels compile and launch on the host GPU. |
| 58 | + |
| 59 | +## Related projects |
| 60 | + |
| 61 | +- [xeus-cpp](https://github.com/compiler-research/xeus-cpp) - the Jupyter kernel these notebooks run on |
| 62 | +- [CppInterOp](https://github.com/compiler-research/CppInterOp) - the C++ interoperability library xeus-cpp is built on |
| 63 | +- [compiler-research.org](https://compiler-research.org) - the research group behind this work |
| 64 | + |
| 65 | +## License |
| 66 | + |
| 67 | +This software is licensed under the `Apache-2.0 License`. See the [LICENSE](LICENSE) file for details. |
0 commit comments