- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
hi ,
I am writing the OpenCL on de5. But inside my kernel function , I want to pass a parameter of structure type to other function to do compute . It seems that it can not work. A simple example as below : typedef struct { int count; } cnt; void funcA(cnt * cnt_temp) { } __kernel void photon(__global cnt * temp) { int gid = get_global_id(0); funcA(&temp); } But in general opencl , this syntax can work ! So , doesn't it pass a address to a function ? thanks.Link Copied
3 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
you need to add __global to the parameter on the function to indicate it is global memory space. Also, you don't need address(&) of temp in the kernel function because the kernel argument is already a pointer here is a modified version of the code: typedef struct { int count; } cnt; -void funcA(cnt * cnt_temp) +void funcA(__global cnt * cnt_temp) { } __kernel void photon(__global cnt * temp) { int gid = get_global_id(0); -funcA(&temp); +funcA(temp); }- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
hi ,
If I want to pass the array like temp[gid] (temp is an array of strcture cnt), the error message will say that "change the address space of pointer". But I need to get the temp[gid]'s final value by passing the temp[gid] to other function. Simple code as below typedef struct { int count; } cnt; void funcA(__global cnt * cnt_temp) { } __kernel void photon(__global cnt * temp) { int gid = get_global_id(0); funcA(temp[gid]); } regards.,- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
In your latest code, what happens is the following:
"temp[gid]" returns a struct of type "cnt" by value. This now is in private memory space, but you specify the argument to funcA has to be global. Hence why you get the error. If I understand well, you want to be able to change the "cnt" struct in global memory from funcA. In that case, you would keep the argument as a pointer to global memory space, and make sure to pass a pointer to global.
typedef struct {
int count;
} cnt;
void funcA(__global cnt * cnt_temp)
{
}
__kernel void photon(__global cnt * temp)
{
int gid = get_global_id(0);
funcA(&temp);
}

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