Unified memory

Hi
I am trying to use cudaMallocManged(), it gave segmentation error

Here is part of the code:

int main()
{
    int X, Y, i=0;
   
   float *a[MaxSize];
    float   *x[MaxSize];
    float  *y[MaxSize];
    float  *tmp[MaxSize];
   int *ny, *nx;
    cudaMallocManaged((void **)&nx,sizeof(int)* MaxSize);
    cudaMallocManaged((void **)&ny,sizeof(int)* MaxSize);
    int ret = fscanf(stdin, "%d %d", &X, &Y);
    while(ret != EOF){
        printf("%d ",i);
        nx[i] = X ;
        ny[i] = Y;
        cudaMallocManaged((void**)&a[i], nx[i]*ny[i]*sizeof(float));
        cudaMallocManaged((void**)&x[i],ny[i]*sizeof(float));
        cudaMallocManaged((void**)&y[i],ny[i]*sizeof(float));
        cudaMallocManaged((void**)&tmp[i],nx[i]*sizeof(float));
        init_arrays(nx[i],ny[i],a[i],x[i]);
        i++;
        ret = fscanf(stdin, "%d %d", &X, &Y);
    }

use proper CUDA error checking in your code. (not sure what that is? google: “proper CUDA error checking” and take the first hit, read it, and apply it to your code).

By the way, seg faults can always be localized to a single line of code that triggers it. You should identify that also.

Scroll through the first 3 pages of the forum, you will see topics related to UMA, cudaMallocManaged or system freeze when allocating memory, with debug tips and fixed code.

I had this problem when I use Cuda 10. When I changed it to Cuda 9, the segmentation fault is gone.