- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi there,
I am porting a large C++ application to MIC. I wrote a bit sample which allocate data using to offload pragma. When I try to run executable file, I have error "offload error: cannot load library to the device 0 (error code 5)".
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Can any one help me?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
There is not enough information in that portion of the error alone to draw any concrete conclusion on what might be the cause. Can you share the sample code that produced that error?
Have you tried the MIC product samples that ship with the Composer XE 2013 Product or any of the examples/tutorials at http://software.intel.com/mic-developer to know if other simple offload programs execute successfully?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I added this line of code
float x[4];
#pragma offload target (mic:0) \
inout(x : ALLOC)
{
#ifdef __MIC__
printf("MIC");
#else
printf("CPU");
#endif
}
#pragma offload target (mic:0) \
nocopy(x : FREE)
{
}
And there was this error.
The MIC product samples that ship with the Composer XE 2013 Product execute successfully.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Ok. So the sample code was added to your large C++ app which when built produces the error. Is that extent of the error or is there more that you are not sharing?
Typically there’s more that precedes the error you posted. Are there any errors regarding dlopen failed? Or undefined symbol?
When building your app, please try adding the following option to the final link step: -offload-option,mic,ld,"--no-undefined"
For any reported undefined references the associated entity likely requires decorating with __attribute__ ((target(mic))) to ensure an instance is created in the offload executable.
If you find none of this is applicable then more source code context is needed to show where this sample code appears to help understand what could lead to the error.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
My project is daemon for Linux. I created a minimal application that replicates my mistake.
int main(int argc, char *argv[]) {
::chdir("/"); // allow file system unmountingprintf("Hello\n");
float x[4];
#pragma offload target (mic:0) \
inout(x : ALLOC)
{
#ifdef __MIC__
printf("MIC");
#else
printf("CPU");
#endif
}
#pragma offload target (mic:0) \
nocopy(x : FREE)
{
}
}
If I delete this line "::chdir("/"); // allow file system unmounting", then error disappear.
For me this line of code is't critical. So I resolved my problem.
Thanks so much for the help.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Ah very interesting. Thank you for the efforts to find and post this. Yes, I can see now how this leads to only the error in your original post. When you change directory away from where the MIC image currently resides the load of this image fails.
There are two ways to deal with this.
1. Delay the chdir until after the first offload, or throw in a counterfeit offload_transfer before the chdir to cover all installed devices. Something like:
[cpp]int main(int argc, char *argv[]) {
int i;
for (i=0; i < _Offload_number_of_devices(); i++)
{
#pragma offload_transfer target (mic:i)
}
chdir("/");
<rest of code>[/cpp]
2. Use the OFFLOAD_INIT=on_start environment variable setting to initialize the target devices before entering main().
Thanks for the interesting issue!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks for ways to deal with this. I tried and all ok.
![](/skins/images/045A6C88D0527A93E76B179D7F5E2AFE/responsive_peak/images/icon_anonymous_message.png)
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page