Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- struct data_type
- {
- char name[256];
- float number;
- };
- void test_offload_pointers_nocopy ( void )
- {
- int i;
- int num_devices = _Offload_number_of_devices();
- // this is a local reference to memory that is allocated on the phi
- struct data_type *data_phi;
- // This executes some code on the phi which creates, or already has
- // has access to a persistent data structure
- for ( i = 0; i < num_devices; i++ )
- {
- #pragma offload target(mic:i) nocopy ( data_phi )
- {
- // Now we are running on the phi. Lets make a new data structure
- // and fill it with some things. Lets also align it to be friendly
- // to vectorization later on
- struct data_type *d = (struct data_type *) memalign ( 128, sizeof(struct data_type) );
- d->number = 3.1415926;
- sprintf ( d->name, "Data on Phi" );
- // Now lets link the pointer to the newly created data structure
- data_phi = d;
- fprintf ( stderr, "First time (%d): %s\n", i, data_phi->name );
- fprintf ( stderr, "First time (%d): %f\n", i, data_phi->number );
- }
- }
- // Some time later on the host, lets try to access it on the phi and see what happens
- for ( i = num_devices - 1; i >= 0; i-- )
- {
- #pragma offload target(mic:i) nocopy ( data_phi )
- {
- fprintf ( stderr, "Second time (%d): %s\n", i, data_phi->name );
- fprintf ( stderr, "Second time (%d): %f\n", i, data_phi->number );
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement