Software Archive
Read-only legacy content
17061 Discussions

Xeon Phi and offload from MATLAB MEX file

Marcin_K_
Beginner
279 Views

Hello,

I am having a really hard time figuring out how to use the Xeon Phi offload mode from within MATLAB MEX files under Linux. I have managed to force MATLAB to use icc for compilation and verified that the mex files run fine. The problems start when using the offload pragma - as far as I can tell, nobody has tried that yet and I suspect this is some (fixable?) issue with libraries. Can someone here help me with this?

Consider the following simple code

int main()
{
  __attribute__((target(mic : 0))) int vsize;
 
#pragma offload target(mic:0)
  vsize = 10;
}

When I execute this with OFFLOAD_REPORT=3, I get the following output

$ ./test
[Offload] [HOST]          [State]           Initialize logical card 0 = physical card 0
[Offload] [MIC 0] [File]                    test.c
[Offload] [MIC 0] [Line]                    23
[Offload] [MIC 0] [Tag]                     Tag 0
[Offload] [HOST]  [Tag 0] [State]           Start target
[Offload] [HOST]  [Tag 0] [State]           Setup target entry: __offload_entry_test_c_23mainicc0101288930704RqbsVt
[Offload] [HOST]  [Tag 0] [State]           Host->target pointer data 0
[Offload] [HOST]  [Tag 0] [Signal]          signal : none
[Offload] [HOST]  [Tag 0] [Signal]          waits  : none
[Offload] [HOST]  [Tag 0] [State]           Host->target pointer data 0
[Offload] [HOST]  [Tag 0] [State]           Host->target copyin data 4
[Offload] [HOST]  [Tag 0] [State]           Execute task on target
[Offload] [HOST]  [Tag 0] [State]           Target->host pointer data 0
[Offload] [MIC 0] [Tag 0] [State]           Start target entry: __offload_entry_test_c_23mainicc0101288930704RqbsVt
[Offload] [MIC 0] [Tag 0] [Var]             vsize  INOUT
[Offload] [HOST]  [Tag 0] [CPU Time]        0.301827(seconds)
[Offload] [MIC 0] [Tag 0] [CPU->MIC Data]   4 (bytes)
[Offload] [MIC 0] [Tag 0] [MIC Time]        0.000171(seconds)
[Offload] [MIC 0] [Tag 0] [MIC->CPU Data]   4 (bytes)

[Offload] [MIC 0] [Tag 0] [State]           Target->host copyout data   4

 

I have written a MEX file that does the same thing. FYI, a MEX file is essentially a dynamic .so library with one specific symbol exported. The result of running the MEX file under MATLAB is as follows

 

>> mictest
[Offload] [HOST]          [State]           Initialize logical card 0 = physical card 0
offload error: cannot load library to the device 0 (error code 5)

------------------------------------------------------------------------
       Segmentation violation detected at Fri Aug 21 14:57:31 2015
------------------------------------------------------------------------

[...]

I have looked around and tried to set the OFFLOAD_INIT=on_start variable before starting MATLAB. The results were VERY promising, but still some problems remain unsolved:

[Offload] [MIC 0] [File]                    mictest_mex.c
[Offload] [MIC 0] [Line]                    41
[Offload] [MIC 0] [Tag]                     Tag 0
[Offload] [HOST]  [Tag 0] [State]           Start target
[Offload] [HOST]  [Tag 0] [State]           Setup target entry: __offload_entry_mictest_mex_c_41mexFunctionicc0104735023118W8NJ2
[Offload] [HOST]  [Tag 0] [State]           Host->target pointer data 0
[Offload] [HOST]  [Tag 0] [Signal]          signal : none
[Offload] [HOST]  [Tag 0] [Signal]          waits  : none
[Offload] [HOST]  [Tag 0] [State]           Host->target pointer data 0
[Offload] [HOST]  [Tag 0] [State]           Host->target copyin data 4
[Offload] [HOST]  [Tag 0] [State]           Execute task on target
offload error: cannot create pipeline on the device 0 (error code 14)

So it seems that MIC is indeed doing something, but one last step is missing to make this work. The library paths and the whole bash environment is the same in both cases. I have also looked at output of the nm command and it seems that in both cases (C standalone and MATLAB MEX) the number and names of symbols that contain work 'offload' are the same/similar.

I think this can be solved: I have seen a document about MKL using offload inside MATLAB, alas for Windows. Does anybody have a clue where to start?

Thanks a lot!

Marcin Krotkiewski

 

0 Kudos
2 Replies
Ravi_N_Intel
Employee
279 Views

To be able to help you I need to understand more about your application :
- Which version of the compiler you are using.
- How do you build your main application
- Is the offload in the .exe or only in the .so
- If the offload is in .exe, can you confirm that it is a fat binary  
     mic_extract  a.out    //  this would create a aMIC.out
- if the offload is in .so  confirm if it is a fat binary
     mic_extract  my.so    // this could create a myMIC.so

Ravi


 

0 Kudos
Tim_P_4
Beginner
279 Views

Hi Marcin

Did you make any progress on offloading from within a MEX file? I'm struggling with the same issue and would really appreciate any update and details.

Cheers
Tim

0 Kudos
Reply