- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I'm trying to offload a dynamically allocated 2d array of floats. I can't seem to get it to work however. My code is this:
[cpp]
#include <stdio.h>
#include <stdlib.h>
float **alloc_2d(int rows, int cols);
void dealloc_2d(float **array, int rows);
int main()
{
/* array size */
const int d1 = 10;
const int d2 = 10;
/* malloc some 2d c arrays */
float **x;
x = alloc_2d(d1,d2);
/* assign some values to them */
int i,j;
for (i=0; i<d1; i++)
for (j=0; j<d2; j++)
{
x
}
printf("x[0][0] = %f\n", x[0][0]);
/* offload to the mic and check value there */
#pragma offload target(mic:0) in( x[0:d1][0:d2] : alloc( x[0:d1][0:d2] ) )
{
printf("x[0][0] = %f\n", x[0][0]);
}
dealloc_2d(x, d1);
return 0;
}
float **alloc_2d(int rows, int cols)
{
float **array;
array = malloc( rows * sizeof *array );
int i;
for (i=0; i<rows; i++)
array = malloc( cols * sizeof *array );
return array;
}
void dealloc_2d(float **array, int rows)
{
int i;
for (i=0; i<rows; i++)
free(array);
free(array);
}
[/cpp]
I compile with icc main.c and I get the error:
": internal error: backend signals
compilation aborted for main.c (code 4)
What's the correct way to offload multidimensional arrays in C/C++? Would it be wiser to just store my data as a 1D array and compute the memory locations manually?
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
James B. wrote:
What's the correct way to offload multidimensional arrays in C/C++? Would it be wiser to just store my data as a 1D array and compute the memory locations manually?
Yes. You cannot offload a pointer to a point with a #pragma offload directive. The best solution is malloc a single block of memory and set up the pointers later. You will need an array of pointers on the host and a separate one on the coprocessor because the actual addresses will be different.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Good. Thanks for confirming that for me.
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page