- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
In my project, I need to pass pointer among different offload functions. However, I do not want to use global variables. For example.
I want to allocate an array on accelerator in new_array function, and hope that it would return an address on accelerator side so that I could pass the address to the next function exe_array. But, the following codes do not work.
Any solution to this case? Say again, I do not want to use global variables. Thanks!
#include <stdio.h>
#include <stdlib.h>
void* new_array();
void exe_array(int *);
int main()
{
int i;
int * p;
p = new_array();
exe_array(p);
for(i=0;i<32;i++)
printf("p=%p: %d\n",&p, p);
#pragma offload target(mic) nocopy(p)
free(p);
}
void* new_array()
{
int i;
int *p;
#pragma offload target(mic) nocopy(p)
{
p=(int *) malloc(32*sizeof(int));
for(i=0; i<32; i++)
p=i;
}
return p;
}
void exe_array(int *p)
{
int i;
#pragma offload target(mic) nocopy(p)
{
for(i=0; i<32;i++)
p=-1;
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Maybe you want something like this.
#include <stdio.h>
#include <stdlib.h>
void* new_array();
void exe_array(void *);
int main()
{
int i;
void * p;
p = new_array();
exe_array(p);
#pragma offload target(mic)
free(p);
}
void* new_array()
{
void *p;
#pragma offload target(mic)
{
p=malloc(32*sizeof(int));
int i;
int* q=(int*)p;
for(i=0; i<32; i++)
q=i;
}
return p;
}
void exe_array(void *p)
{
#pragma offload target(mic)
{
int i;
int* q=(int*)p;
for(i=0; i<32;i++)
printf("%d ",q);
printf("\n");
}
}
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Maybe you want something like this.
#include <stdio.h>
#include <stdlib.h>
void* new_array();
void exe_array(void *);
int main()
{
int i;
void * p;
p = new_array();
exe_array(p);
#pragma offload target(mic)
free(p);
}
void* new_array()
{
void *p;
#pragma offload target(mic)
{
p=malloc(32*sizeof(int));
int i;
int* q=(int*)p;
for(i=0; i<32; i++)
q=i;
}
return p;
}
void exe_array(void *p)
{
#pragma offload target(mic)
{
int i;
int* q=(int*)p;
for(i=0; i<32;i++)
printf("%d ",q);
printf("\n");
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Yes, it work! Thanks a lot!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Greg,
Is there a requirement that the copy of the pointer on the host be void*?
I would imagine that it is not, however, use of void* will hinder your using the pointer unintentionally and would be good programming practice.
Jim Dempsey
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Jim,
I think we do have to use a void type to get a pointer from the coprocessor.
Gregg Skinner
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page