- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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; }
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi Kevin.
It does work.Thanks very much.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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; } ~
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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; }
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page