Advertisement
Guest User

Untitled

a guest
Jun 17th, 2013
40
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.37 KB | None | 0 0
  1. struct data_type
  2. {
  3.     char name[256];
  4.     float number;
  5. };
  6.  
  7. void test_offload_pointers_nocopy ( void )
  8. {
  9.     int i;
  10.     int num_devices = _Offload_number_of_devices();
  11.  
  12.     // this is a local reference to memory that is allocated on the phi
  13.     struct data_type *data_phi;
  14.  
  15.     // This executes some code on the phi which creates, or already has
  16.     // has access to a persistent data structure
  17.     for ( i = 0; i < num_devices; i++ )
  18.     {
  19.         #pragma offload target(mic:i) nocopy ( data_phi )
  20.         {
  21.             // Now we are running on the phi. Lets make a new data structure
  22.             // and fill it with some things. Lets also align it to be friendly
  23.             // to vectorization later on
  24.             struct data_type *d = (struct data_type *) memalign ( 128, sizeof(struct data_type) );
  25.             d->number = 3.1415926;
  26.             sprintf ( d->name, "Data on Phi" );
  27.  
  28.             // Now lets link the pointer to the newly created data structure
  29.             data_phi = d;
  30.  
  31.             fprintf ( stderr, "First time (%d): %s\n", i, data_phi->name );
  32.             fprintf ( stderr, "First time (%d): %f\n", i, data_phi->number );
  33.         }
  34.     }
  35.  
  36.     // Some time later on the host, lets try to access it on the phi and see what happens
  37.     for ( i = num_devices - 1; i >= 0; i-- )
  38.     {
  39.         #pragma offload target(mic:i) nocopy ( data_phi )
  40.         {
  41.             fprintf ( stderr, "Second time (%d): %s\n", i, data_phi->name );
  42.             fprintf ( stderr, "Second time (%d): %f\n", i, data_phi->number );
  43.         }
  44.     }
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement