cuda:thread->block->stream


程序结构

1.核函数

核函数的定义和c语言方式类似,使用__global__什么核函数,线程的数目通过<<<...,nums>>>来传递。

// Kernel definition
__global__ void VecAdd(float* A, float* B, float* C)
{
    int i = threadIdx.x;
    C[i] = A[i] + B[i];
}
int main()
{
    ...
    // Kernel invocation with N threads
    VecAdd<<<1, N>>>(A, B, C);
    ...
}

2.线程的结构

线程是一个三维向量(x,y,z),在使用的过程中,可以使用(x),(x,y),(x,y,z)

以下,是一个使用二维(x,y)的核函数

// Kernel definition
__global__ void MatAdd(float A[N][N], float B[N][N],
                       float C[N][N])
{
    int i = threadIdx.x;
    int j = threadIdx.y;
    C[i][j] = A[i][j] + B[i][j];
}
int main()
{
    ...
    // Kernel invocation with one block of N * N * 1 threads
    int numBlocks = 1;
    dim3 threadsPerBlock(N, N);
    MatAdd<<<numBlocks, threadsPerBlock>>>(A, B, C);
    ...
}

threadindex(x,y) = threadid(x+y*Dx);

优质内容筛选与推荐>>
1、Ribbon 框架简介及搭建(没有与SpringCloud整合,独立使用)
2、SLua
3、C6 P5.2
4、yii归档版安装后gii使用时在地址后面加上请求参数r=gii就可以使用
5、谷歌Chrome浏览器是如何“炼”成的?


长按二维码向我转账

受苹果公司新规定影响,微信 iOS 版的赞赏功能被关闭,可通过二维码转账支持公众号。

    阅读
    好看
    已推荐到看一看
    你的朋友可以在“发现”-“看一看”看到你认为好看的文章。
    已取消,“好看”想法已同步删除
    已推荐到看一看 和朋友分享想法
    最多200字,当前共 发送

    已发送

    朋友将在看一看看到

    确定
    分享你的想法...
    取消

    分享想法到看一看

    确定
    最多200字,当前共

    发送中

    网络异常,请稍后重试

    微信扫一扫
    关注该公众号





    联系我们

    欢迎来到TinyMind。

    关于TinyMind的内容或商务合作、网站建议,举报不良信息等均可联系我们。

    TinyMind客服邮箱:support@tinymind.net.cn