- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
Recently, I use _Cilk_shared and _Cilk_offload to offload my c++ code to MIC. The problem is I want to offload a class B, but a member of class B is an object of class A. When I offload class B, the object of class A can not access inside the offload function. So I want to know if there a way to solve this situation? The code is like this:
#include <iostream> #pragma offload_attribute (push, _Cilk_shared) #include <offload.h> #pragma offload_attribute (pop) class _Cilk_shared A{ int* buffer; int size; public: A(int size_) { size = size_; buffer = new int[size]; } _Cilk_shared void print() { int sum = 0; for(int i=0;i<size;i++) sum+=buffer; std::cout<<"size = "<<size<<"sum = "<<sum<<std::endl; #ifdef __MIC__ std::cout<<"ON MIC"<<std::endl; #else std::cout<<"fail!"<<std::endl; #endif } }; class _Cilk_shared B{ public: A data; int size; const static int DefaultSize = 1<<10; B(int size_ = DefaultSize) : data(size_) , size(size_) {} }; _Cilk_shared B * _Cilk_shared ii; _Cilk_shared void offload() { ii->data.print(); } int main() { ii = new (_Offload_shared_malloc(sizeof(B))) _Cilk_shared B(); _Cilk_offload offload(); }
The result of This code is here:
CARD--ERROR:1 thread:3 myoiPageFaultHandler: 0x1274040 Out of Range! CARD--ERROR:1 thread:3 _myoiPageFaultHandler: 0x1274040 switch to default signal handle. CARD--ERROR:1 thread:3 Segment Fault - will exit! HOST--ERROR: thread:1 myoiScifGetRecvId: Call recv() Header Failed ! for source: 1, errno = 104 HOST--ERROR: thread:2 myoiScifSend: Call send() Failed! errno = 104 HOST--ERROR: thread:2 myoiSend: Failed to send message! HOST--ERROR: thread:2 _myoiWatchdogDaemon: could not send to target: 1 offload error: process on the device 0 unexpectedly exited with code 1
Thank you for your time!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I identified a change that leads to successful execution and our Developers confirmed it is the correct change noting that this change is needed because "you cannot allocate non-shared memory and assign to shared objects and access them."
The change needed is at line 13. Change it from this:
buffer = new int[size];
to this:
buffer = (_Cilk_shared int *)_Offload_shared_malloc(size);
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I tried a few things without success myself so let me inquire with our Developers about this and get back with your shortly.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I identified a change that leads to successful execution and our Developers confirmed it is the correct change noting that this change is needed because "you cannot allocate non-shared memory and assign to shared objects and access them."
The change needed is at line 13. Change it from this:
buffer = new int[size];
to this:
buffer = (_Cilk_shared int *)_Offload_shared_malloc(size);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thank you! I has modified my code and it works!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
You're welcome. Glad to hear that.

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