本文将介绍如何在GPU上并行地执行一段简单的Hello World代码,并介绍什么是核函数。
https://github.com/YouQixiaowu/CUDA-Programming-with-Pythongithub.comHello World
首先让我们从GPU中打印Hello World,现在无需知道每一行代码都在做什么,请先复制到你的编辑器中并运行它。
import pycuda.autoinit
from pycuda.compiler import SourceModule
kernel_code = r"""
__global__ void hello_from_gpu(void)
{
printf("Hello World from the GPU!n");
}
"""
mod = SourceModule(kernel_code)
hello_from_gpu = mod.get_function("hello_from_gpu")
hello_from_gpu(block=(1,1,1))
如果你的CUDA环境没有问题,那么下面内容将会输出在你的屏幕。
Hello World from the GPU!
逐行讲解Python代码
第一部分
import pycuda.autoinit # 以自动的方式对pycuda进行初始化
不同于普通的Python模块&#