如何调试 CUDA google colab notebook?

how to debug a CUDA google colab notebook?

我正在尝试 运行 使用 cuda 的 c 程序代码对连续数字数组进行一些数学运算(其中每个线程添加一行元素并检查最后一个数组元素和 return 总和的值或零,如果满足条件)。 我没有 NVIDIA GPU,所以我在 google colab notebook 上写了我的代码。

我遇到的问题是无法调试程序。它什么都不输出,没有错误消息,也没有输出。 代码有问题,看了几遍也不知道是哪里。

代码如下:

#include <iostream>

__global__ void matrixadd(int *l,int *result,int digits ,int possible_ids )

{  
    int sum=0;
    int zeroflag=1;
    int identicalflag=1;
    int id=  blockIdx .x * blockDim .x + threadIdx .x;
 
if(id<possible_ids)
{
    if (l[(digits*id)+digits-1]==0) zeroflag=0;/*checking if the first number is zero*/

    for(int i=0; i< digits-1;i++)/*edited:for(int i=0; i< digits;i++) */
          {
            
            if(l[(digits*id)+i]-l[(digits*id)+i+1]==0)
            identicalflag+=1; /* checking if 2 consequitive numbers are identical*/

            sum = sum + l[(digits*id)+i]; /* finding the sum*/
         }
    if (identicalflag!=1)identicalflag=0;
    result[id]=sum*zeroflag*identicalflag;
}
}

int main()
{
     int digits=6;
     int possible_ids=pow(10,digits);
/*populate the array */
int* a ;
 a= (int *)malloc((possible_ids * digits) * sizeof(int));
 int the_id,temp=possible_ids;

  for (int i = 0; i < possible_ids; i++) 
    { 
        temp--;
        the_id=temp;
        for (int j = 0; j < digits; j++)
        {  
        a[i * digits + j] = the_id % 10;    
        if(the_id !=0) the_id /= 10;
        }

    }
 /*the numbers will appear in reversed order  */

/*allocate memory on host and device then invoke the kernel function*/
    int *d_a,*d_c,*c;
    int size=possible_ids * digits;
    c= (int *)malloc(possible_ids * sizeof(int));/*results matrix*/

    cudaMalloc((void **)&d_a,size*sizeof(int));
    cudaMemcpy(d_a,a,size*sizeof(int),cudaMemcpyHostToDevice);
    cudaMalloc((void **)&d_c,possible_ids*sizeof(int));
/*EDITED: cudaMalloc((void **)&d_c,digits*sizeof(int));*/
 
matrixadd<<<ceil(possible_ids/1024.0),1024>>>(d_a,d_c,digits,possible_ids);
cudaMemcpy(c,d_c,possible_ids*sizeof(int),cudaMemcpyDeviceToHost);

 int acc=0;
for (int k=0;k<possible_ids;k++)
{
    if (c[k]==7||c[k]==17||c[k]==11||c[k]==15)continue;
    acc += c[k];
 }
printf("The number of possible ids %d",acc);
}
  

You are doing invalid indexing into the l array in this line of code: if(l[(digits*id)+i]-l[(digits*id)+i+1]==0)

来自