码迷,mamicode.com
首页 > 其他好文 > 详细

Professional CUDA C Programming的代码实例1.1

时间:2019-12-24 11:33:02      阅读:83      评论:0      收藏:0      [点我收藏+]

标签:apple   程序   cer   结构   step   str   global   ESS   ram   

CUDA PROGRAM STRUCTURE
A typical CUDA program structure consists of fi ve main steps:
1. Allocate GPU memories.
2. Copy data from CPU memory to GPU memory.
3. Invoke the CUDA kernel to perform program-specifi c computation.
4. Copy data back from GPU memory to CPU memory.
5. Destroy GPU memories.
In the simple program hello.cu, you only see the third step: Invoke the kernel. For
the remainder of this book, examples will demonstrate each step in the CUDA program
structure.

一个典型的CUDA程序结构由以下五个主要步骤组成:

1分配GPU的记忆。

2. 将数据从CPU内存复制到GPU内存。

3.调用CUDA内核执行program-specifi计算。

4. 将数据从GPU内存复制到CPU内存。

5. 摧毁GPU的记忆。

在简单的程序中hello.cu,你只看到第三步:调用内核。在本书的其余部分,示例将演示CUDA程序结构中的每个步骤。

#include <stdio.h>
#include"cuda_runtime.h"
__global__ void helloFromGPU(void)
{
    printf("Hello World from GPU!\n");
}
int main(void)
{
    // hello from cpu
    printf("Hello World from CPU!\n");
    helloFromGPU <<<10, 1 >>> ();
    cudaDeviceReset();
    return 0;
}

技术图片

Professional CUDA C Programming的代码实例1.1

标签:apple   程序   cer   结构   step   str   global   ESS   ram   

原文地址:https://www.cnblogs.com/WangGuiHandsome/p/12090352.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!