Intel® oneAPI HPC Toolkit
Get help with building, analyzing, optimizing, and scaling high-performance computing (HPC) applications.
Announcements
This community is designed for sharing of public information. Please do not share Intel or third-party confidential information here.
1921 Discussions

OpenMP target data to intel GPU segmentation fault when array too large

Sylvain
Beginner
952 Views

Hello,

When testing offload computation to intel GPU with OpenMP, I obtain a segmentation fault at execution with this code :

int main()
{
    const int N=350000;

    double a;
    double b;
    double c;
//    double *a = new double;
//    double *b = new double;
//    double *c = new double;

    for (int i=0; i<N; i++) {
        a = i;
        b = 1./i;
    }

    #pragma omp target data map(to:a,b) map(from:c)
//    #pragma omp target data map(to:a[0:N],b[0:N]) map(from:c[0:N])
    {
    #pragma omp target teams distribute parallel for simd
    for (int i=0; i<N; i++) {
        c = a+b;
    }
    }

//    delete[] a;
//    delete[] b;
//    delete[] c;

    return 0;
}

The error does not happen if I take N=300000 or if I use pointers instead of arrays (use of commented lines). With pointers it works even with N=100000000 (not tested above).

When looking with gdb, segmentation fault happens at line 12, but I cannot access exact value i, even with -O0.

My configuration :

  •     Gentoo Linux
  •     CPU i5-7300U with HD Graphics 620
  •     oneAPI HPC Toolkit 2021.1 beta06
  •     neo-20.16.16582
  •     intel-graphics-compiler-1.0.3826
  •     level-zero-0.91.10
  •     I used "-qnextgen -fiopenmp -fopenmp-targets=spir64" for compilation

 

Thanks,

Sylvain

0 Kudos
1 Solution
AbhishekD_Intel
Moderator
952 Views

Hi Sylvain,

We tried the code given by you and it is not giving segfault if I take N=300000. But we observe segfault if we take N>500000, and it is oblivious as it is exceeding maximum stack size for us. Whereas for the pointer (commented part of your code) it will work without segfault for N=100000000 as it is using heap instead of the stack.

If you want to check the stack size you can use ulimit -a command and you will get the reason for segfault.

If you use gdb you will definitely get a segfault on line 12(of your code) but if you try something like below code snippet :

    const int N=600000;

    double a;
    double b;
//    double c;

    for (int i=0; i<N; i++) {
        a = i;
        b = 1./i;
    }

    std::cout<<"here\n";
    double c;

In the above case, we will see that you will get segfault after "std::cout" as stack size is exceeding after std::cout statement.

So if you have a requirement of large size array then we will recommend you use dynamic memory allocation instead of using stack.

I hope this helps. Do let us know if your issue is resolved.

 

Warm Regards,

Abhishek

View solution in original post

5 Replies
AbhishekD_Intel
Moderator
953 Views

Hi Sylvain,

We tried the code given by you and it is not giving segfault if I take N=300000. But we observe segfault if we take N>500000, and it is oblivious as it is exceeding maximum stack size for us. Whereas for the pointer (commented part of your code) it will work without segfault for N=100000000 as it is using heap instead of the stack.

If you want to check the stack size you can use ulimit -a command and you will get the reason for segfault.

If you use gdb you will definitely get a segfault on line 12(of your code) but if you try something like below code snippet :

    const int N=600000;

    double a;
    double b;
//    double c;

    for (int i=0; i<N; i++) {
        a = i;
        b = 1./i;
    }

    std::cout<<"here\n";
    double c;

In the above case, we will see that you will get segfault after "std::cout" as stack size is exceeding after std::cout statement.

So if you have a requirement of large size array then we will recommend you use dynamic memory allocation instead of using stack.

I hope this helps. Do let us know if your issue is resolved.

 

Warm Regards,

Abhishek

Sylvain
Beginner
952 Views
Thank you for your answer, I understand it is a limitation of the system. I am learning new things. Nothing to do with GPU computing and oneAPI HPC Toolkit then. Best regards, Sylvain
AbhishekD_Intel
Moderator
952 Views

Hi Sylvain,

Please confirm if your issue has been resolved so that we can close the thread.

You can always post a new thread if you face any issue.

 

Warm Regards,

Abhishek

Sylvain
Beginner
952 Views
Yes, it solves the problem, thank you
AbhishekD_Intel
Moderator
952 Views

Thank you Sylvain for the conformation we are closing this thread.

You can always post a new thread if you face any issue.

 

Warm Regards,

Abhishek

Reply