Software Archive
Read-only legacy content
17061 Discussions

offload error: cannot load library to the device 0 (error code 5)

Alexander_Komarov
707 Views

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)".

0 Kudos
7 Replies
Alexander_Komarov
707 Views

Can any one help me?

0 Kudos
Kevin_D_Intel
Employee
707 Views

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?

0 Kudos
Alexander_Komarov
707 Views

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. 

0 Kudos
Kevin_D_Intel
Employee
707 Views

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.

0 Kudos
Alexander_Komarov
707 Views

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 unmounting

printf("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.

0 Kudos
Kevin_D_Intel
Employee
707 Views

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!

0 Kudos
Alexander_Komarov
707 Views

Thanks for ways to deal with this. I tried and all ok.

0 Kudos
Reply