C++ and AI
Learning is Not the Ultimate Goal
Learning is not the ultimate goal; it is a means to an end. We live in an information-rich era where it is impossible to master every field, even if you had a hundred brains. Therefore, learning for the sake of learning, or drifting aimlessly through information, is a fool’s errand. You must be selective about what you study. Focus on a specific domain—driven by passion or a clear objective—and strive to become an expert in that field.
Goals: CUDA, LLVM, MLIR(IREE/TVM), Triton
- 从“修 Bug”开始: 不要一上来就试图写一个完整的编译器。去 GitHub 上找 TVM、MLIR 或 ONNX-MLIR 的 good first issue。
- 手写迷你算子编译器: 尝试用 C++ 和 LLVM/MLIR 实现一个极简的工具:读入一个单一的矩阵乘法或卷积算子的配置,自动生成一段针对你手头电脑 CPU(带 AVX 指令)的高效汇编/机器码。
- AI 编译器层(MLIR / TVM): 随着硬件的多样化(Nvidia GPU、AMD GPU、各类国产 ASIC 芯片),企业应用越来越依赖底层的 AI 编译器。框架层的代码最终都会被编译到更底层的算子。因此,掌握模型如何下沉到硬件(如通过 ONNX 转译)更有长期价值。
1. AI and Hardware Fundamentals
- PyTorch: Eager Execution, Computation Graph, 算子(Operator,如 Conv2D, MatMul), 看懂 ONNX 格式的模型结构。
- 数学: Tensor ( vector/scalar as a special case), Gradient(梯度,偏导数)
- 计算机: Cache Coherence, SIMD 指令集(AVX/NEON), 掌握 CUDA 编程基础,理解显存层级(Shared Memory, Global Memory)、Warp 调度机制。
∇f 梯度就是把一个函数在某个点上所有的偏导数打包在一起,组成一个向量。(简单理解:偏导数组成的向量)
其他
计算机
- 黄金分割数1.618,代数性质: φ + 1 = φ 2,斐波那契:φ n = F(n) φ + F( n-1)
- 进程的优雅退出实际上是给OS注册信号的回调处理函数,OS收到信号(SIGINT,SIGTERM)后调用该函数。fork,一般父进程需要等待子进程退出。孤儿进程(活着,pid为1): 父进程先于子进程结束。
- 僵尸进程(资源已回收,但是): 父进程没有wait/waitpid,导致在进程表残留。原因: 1. 没有捕获信号,或捕获后未处理。2. 容器环境下没有init参数,孤儿进程结束后没有收尸,沦为僵尸进程。kill -9会导致无法被捕获的SIGKILL信号。
英语
- Jim Gray once told me that he had heard two different opinions of this paper: that it’s trivial and that it’s brilliant. **I can’t argue with the former, and I am disinclined to argue with the latter. ** –莱斯利·罗伯特