- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
I tried to offload a structure with pointers on the MIC. So I tried the code for the example presented in:
http://software.intel.com/en-us/articles/effective-use-of-the-intel-compilers-offload-features
However, I get a Segmentation Fault (core dumped) and this occurs when execution hits the
#pragma offload target(mic) in(struct1.m1) in(struct1.m2[0:SIZE] : ALLOC) nocopy(struct1)
When replacing struct1.m2 with a pointer, it works but then we're not using the structure :
int *ptr = struct.m;2
#pragma offload target(mic) in(struct1.m1) in(ptr:length(SIZE) ALLOC) nocopy(struct1)
So does the problem come from the compiler or is there something I'm missing?
Thank you.
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I am looking into this issue. Let me get back to you with what I find.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi Vincent,
This was a new feature that was to be added to Intel Composer XE SP1 Update 1. It seems that the BKM was updated before the compiler update was publically available.
In the meantime, you can use the following work around:
[cpp]
#include <stdio.h>
#include <stdlib.h>
#define SIZE 10
#define ALLOC alloc_if(1) free_if(0)
#define REUSE alloc_if(0) free_if(0)
#define FREE alloc_if(0) free_if(1)
// Example of Non-Bitwise Object Transfer, All Data Elements Needed
typedef struct {
int m1;
int *m2;
} nbwcs;
__declspec(target(mic)) nbwcs struct1;
void send_inputs()
{
int m1;
int *m2;
// Initialize the struct
struct1.m1 = 10;
struct1.m2 = (int *)malloc(SIZE * sizeof(int));
for (int i=0; i<SIZE; i++)
{
struct1.m2 = i;
}
// In this offload data is transferred
m1 = struct1.m1;
m2 = struct1.m2;
#pragma offload target(mic) in(m1) in(m2[0:SIZE] : ALLOC) nocopy(struct1)
{
struct1.m1 = m1;
struct1.m2 = m2;
printf("MIC offload1: struct1.m2[0] = %d, struct1.m2[SIZE-1] = %d\n", struct1.m2[0], struct1.m2[SIZE-1]);
fflush(0);
}
}
void use_the_data()
{
// In this offload data is used and updated
#pragma offload target(mic) nocopy(struct1)
{
for (int i=0; i<SIZE; i++)
{
struct1.m2 += i;
}
printf("MIC offload2: struct1.m2[0] = %d, struct1.m2[SIZE-1] = %d\n", struct1.m2[0], struct1.m2[SIZE-1]);
fflush(0);
}
}
void receive_results()
{
int *m2;
// In this offload data is used,, updated, freed on MIC and brought back to the CPU
m2 = struct1.m2;
#pragma offload target(mic) out(m2[0:SIZE] : FREE) nocopy(struct1)
{
for (int i=0; i<SIZE; i++)
{
struct1.m2 += i;
}
printf("MIC offload3: struct1.m2[0] = %d, struct1.m2[SIZE-1] = %d\n", struct1.m2[0], struct1.m2[SIZE-1]);
fflush(0);
}
printf("CPU: struct1.m2[0] = %d, struct1.m2[SIZE-1] = %d\n", struct1.m2[0], struct1.m2[SIZE-1]);
}
int main()
{
send_inputs();
use_the_data();
receive_results();
return 0;
}
[/cpp]
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello Sumedh,
Thank you for your answer.
That's the work around that we used. We just wanted to be sure that we didn't miss something that made the example not work.
Vincent

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page