Software Archive
Read-only legacy content
17061 Discussions

error about a test of asynchronous data transfer

wang_p_
Beginner
880 Views

This is my code. I just want to test asynchronous data transfer from CPU to coprocessor. But I got an error message:offload error: "process on the device 0 was terminated by signal 11 (SIGSEGV)"

Please help me, I have already taken 6 hours to debug this problem.

#include<iostream>
#include<string.h>
#define LEN 1024000

void function (float *fPtr0,float*fPtr1,float *fPtr2){

        #pragma offload target(mic:0)wait(1)  nocopy(fPtr0)in(fPtr1:length(LEN)alloc_if(1) free_if(0)) out(fPtr2:length(LEN)alloc_if(1)free_if(0))
{

        for(int i=0;i<11;i++)
                fPtr2=fPtr0+fPtr1;

}
}
int main(){
        float *p0       =       new float [LEN] ;
        float *p1       =       new float [LEN] ;
        float *p2       =       new float [LEN] ;
        memset(p0,0,LEN*sizeof(float));
        #pragma offload_transfer target(mic:0) in(p0:length(LEN) alloc_if(1) free_if(0)) signal(1)
        {}
        for(int i=0;i<LEN;i++)
                p1=i;
        function(p0,p1,p2);
        for(int i=0;i<15;i++)
        std::cout<<p2<<" ";
        std::cout<<std::endl;
        return 0;
}
0 Kudos
1 Solution
Kevin_D_Intel
Employee
880 Views

Inside routine function, change nocopy(fPtr0) to in(fPtr0 : length(0)) so as to create an instance of the pointer within that routine’s scope and update the pointer’s value only within the associated offload scope and reuse the existing allocation on the coprocessor associated with that pointer. You would only use nocopy within the scope where the pointer was initially created to reuse that instance of it.

View solution in original post

0 Kudos
5 Replies
Kevin_D_Intel
Employee
881 Views

Inside routine function, change nocopy(fPtr0) to in(fPtr0 : length(0)) so as to create an instance of the pointer within that routine’s scope and update the pointer’s value only within the associated offload scope and reuse the existing allocation on the coprocessor associated with that pointer. You would only use nocopy within the scope where the pointer was initially created to reuse that instance of it.

0 Kudos
wang_p_
Beginner
880 Views

Hi Kevin.

It does work.Thanks very much.

0 Kudos
wang_p_1
Beginner
880 Views

There is another problem. 

In the pragma offload , we cannot increase the pointer's value.Like this:

#include<iostream>
#include<string.h>
#include<stdio.h>
#define LEN 1024000

void function (float *fPtr0,float*fPtr1,float *fPtr2){

        #pragma offload target(mic:0)  in(fPtr0:length(0))in(fPtr1:length(LEN)alloc_if(1) free_if(0)) out(fPtr2:length(LEN)alloc_if(1)free_if(0))
{
#if 1

        for(int i=0;i<11;i++){
        //      fPtr2=fPtr0+fPtr1; //It's ok!
                *fPtr2++=*fPtr0++ + *fPtr1++; // error message:offload error: cannot release buffer memory on device 0 (error code 14)
}
#endif

}
}
int main(){
        float *p0       =       new float [LEN] ;
        float *p1       =       new float [LEN] ;
        float *p2       =       new float [LEN] ;
        memset(p0,0,LEN*sizeof(float));
        #pragma offload_transfer target(mic:0) in(p0:length(LEN)alloc_if(1) free_if(0)) signal(1)
        {}
        for(int i=0;i<LEN;i++)
                p1=i;
        #pragma offload_wait target(mic:0) wait(1)
        function(p0,p1,p2);
        function(p0,p1,p2);
        for(int i=0;i<15;i++)
        std::cout<<p2<<" ";
        std::cout<<std::endl;
        return 0;

}
~

 

0 Kudos
wang_p_1
Beginner
880 Views

I have already solve above problem.

I just take the pointer offset to it's original. like this:

#include<iostream>
#include<string.h>
#include<stdio.h>
#define LEN 1024000

void function (float *fPtr0,float*fPtr1,float *fPtr2){

        #pragma offload target(mic:0)  in(fPtr0:length(0))in(fPtr1:length(LEN)alloc_if(1) free_if(0)) out(fPtr2:length(LEN)alloc_if(1)free_if(0))
{
#if 1

        for(int i=0;i<LEN;i++){
                *fPtr2++=*fPtr0++ + *fPtr1++; 
}
        fPtr0 -= LEN;
        fPtr1 -= LEN;
        fPtr2 -= LEN;
#endif

}
}
int main(){
        float *p0       =       new float [LEN] ;
        float *p1       =       new float [LEN] ;
        float *p2       =       new float [LEN] ;
        memset(p0,0,LEN*sizeof(float));
        #pragma offload_transfer target(mic:0) in(p0:length(LEN)alloc_if(1) free_if(0)) signal(1)
        {}
        for(int i=0;i<LEN;i++)
                p1=i;
        #pragma offload_wait target(mic:0) wait(1)
        function(p0,p1,p2);
        function(p0,p1,p2);
        for(int i=0;i<15;i++)
        std::cout<<p2<<" ";
        std::cout<<std::endl;
        return 0;

}

 

0 Kudos
Rajiv_D_Intel
Employee
880 Views

Because you want to continue using the memory allocated in the main program for p0, line 8 above should be changed to contain this:

in(fPtr0:length(0) alloc_if(0) free_if(0) )

The alloc_if(0) and free_if(0) modifiers are needed because the default for the "in" clause is alloc_if(1) and free_if(1).

With that change the program works.

0 Kudos
Reply