2. 内存结构 & 核函数基本说明
内存结构
对于 CPU + GPU 的异构模型,两者内存是隔离的 (当然了,CPU有自己的内存,GPU有自己的显存),因此我们会有对应的 CUDA 函数对设备进行内存分配与复制:
cudaMalloc: 分配内存
cudaMemcpy: 复制内存
cudaMemset: 设置内存
cudaFree: 释放内存
cuda 函数统一返回 cudaError_t 方便主机端进行错误处理,为了更好显示,runtime api 也提供了一些必要的转换方法,比如,具体参考官方文档
1234// Returns the string represent
2026-02-28572 字3 分钟
【CUDA学习】01-GPU 架构与异构计算
1. GPU 基本架构
GPU 可以类比 CPU 架构理解,只不过弱化控制器,强化计算能力 (SP),如下图:
右图 GPU 中,绿色方块为 SP (streaming processor) 是 GPU 运算的基本单元 (其实就类似 ALU),GPU 中天然的将多个 SP 组合在一起,配合一定数量的寄存器和共享内存,形成一个 SM (streaming multiprocessor) ,使其在架构上对 SIMD 更加友好 [个人理解: SM 是 GPU 对 SIMD 支持的基本单元],这都是很直觉的内容。
我们学习的 CUDA Runtime API 相对 CUDA Driver 更高层
2026-02-2880 字1 分钟
Hello World
Welcome to Hexo! This is your very first post. Check documentation for more info. If you get any problems when using Hexo, you can find the answer in troubleshooting or you can ask me on GitHub.
Quick Start
Create a new post
1$ hexo new "My New Post"
More info: Writing
Run server
1$ hex