cuda入门

2018-12-20  本文已影响0人  深度学习dlai

Writing Application Code for the GPU

CUDA 为许多常用编程语言提供扩展,而在本实验中,我们将会为 C/C++ 提供扩展。这些语言扩展可让开发人员在 GPU 上轻松运行其源代码中的函数。

以下是一个 .cu 文件(.cu 是 CUDA 加速程序的文件扩展名)。其中包含两个函数,第一个函数将在 CPU 上运行,第二个将在 GPU 上运行。请抽点时间找出这两个函数在定义方式和调用方式上的差异。

void CPUFunction()
{
  printf("This function is defined to run on the CPU.\n");
}

__global__ void GPUFunction()
{
  printf("This function is defined to run on the GPU.\n");
}

int main()
{
  CPUFunction();

  GPUFunction<<<1, 1>>>();
  cudaDeviceSynchronize();
}

以下是一些需要特别注意的重要代码行,以及加速计算中使用的一些其他常用术语:

__global__ void GPUFunction()

GPUFunction<<<1, 1>>>();

cudaDeviceSynchronize();

上一篇 下一篇

猜你喜欢

热点阅读