假设我有以下序列号C:
int add(int* a, int* b, int n)
{
for(i=0; i<n; i++)
{
for(j=0; j<n; j++)
{
a[i][j]+=b[i][j];
}
}
return 0;
}
我认为并行化的最佳方法是认识到这是一个 2D 问题并按照以下方式使用 2D 线程块CUDA 内核 - 嵌套 for 循环
考虑到这一点,我开始像这样编写我的 cuda 内核:
__global__ void calc(int **A, int **B, int n)
{
int i= blockIdx.x * blockDim.x + threadIdx.x;
int j= blockIdx.y * blockDim.y + threadIdx.y;
if (i>=n || j>=n)
return;
A[i][j]+=B[i][j];
}
nvcc 告诉我:
./addm.cu(13): Warning: Cannot tell what pointer points to, assuming global memory space
./addm.cu(13): Warning: Cannot tell what pointer points to, assuming global memory space
./addm.cu(13): Warning: Cannot tell what pointer points to, assuming global memory space
1)我的哲学是正确的吗?
2)我想我理解块,线程等,但我不明白是什么
int i= blockIdx.x * blockDim.x + threadIdx.x;
int j= blockIdx.y * blockDim.y + threadIdx.y;
does
3)这是否是在 2D 数组上执行操作的最有效/最快的方法?即不仅仅是矩阵加法,它可以是任何“逐个元素”运算。
4)我可以从matlab中调用它吗?通常当原型是以下形式时它会很奇怪type** var
多谢你们