Software Archive
Read-only legacy content
17061 Discussions

File I/O within the Offload Region

Guthrie_C_
Beginner
496 Views

Hello,

I am trying to test the default code for "Performing File I/O on the Coprocessor" at the end of Chapter 7 in Intel Xeon-Phi Coprocessor High Performance Programming by Jim Jefferies and James Reinders.

The code is as follows:

#pragma offload_attribute(push,target(mic))
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#pragma offload_attribute(pop)

int main()

{
  FILE *fp;
  char buffer[7];
  #pragma offload target(mic) nocopy(fp)
  {
    fp =fopen("./proxyfs/myfile.txt","wb");
    if(fp==NULL)
    {  
      fprintf(stderr,"Failed to open myfile.txt for write\n");
      exit(1);
    }
    fwrite("Hello\n",1,7,fp);
    fclose(fp);
  }
  #pragma offload target(mic) nocopy(fp) out(buffer)
  {
    fp = fopen("./proxyfs/myfile.txt","rb");
    if(fp==NULL)
    {
      fprintf(stderr,"Failed to open myfile.txt for read\n");
      exit(1);
    }
    fread(buffer, 1, 7, fp);
    fclose(fp);
    if(strcmp(buffer, "Hello\n") != 0)
    {
      fprintf(stderr,"File incorrectly read back on coproc\n");
      exit(1);
    }
  }
  printf("%s", buffer);
  return 0;
}

 

I set MIC_PROXY_FS_ROOT to a relevant location and set MIC_PROXY_IO = 1, just as stated in the book.  However, when I run the code, I get the first error:

"Failed to open myfile.txt for write"

which means that the proxyfs directory is invalid.

 

Was the software changed so this method doesn't work anymore?  Or is there something wrong with the code?

 

Thanks.

0 Kudos
3 Replies
Kevin_D_Intel
Employee
496 Views

Yes, the software changed. There was an earlier inquiry on this here that might help.

0 Kudos
Guthrie_C_
Beginner
496 Views

Wow, the code did not show up as expected. However you still seem to understand the issue.

So I would need to mount the file via NFS to be able to access it in the offload region?  

0 Kudos
Kevin_D_Intel
Employee
496 Views

Yes, NFS is the recommended option. Just to be clear, one can put files on the card into are area like /tmp and read/write them locally also (assuming the user environment permits the user such access). The caution with putting files on the card is that it impacts available memory as the uOS runs via a ramdisk.

0 Kudos
Reply