Intel® Quartus® Prime Software
Intel® Quartus® Prime Design Software, Design Entry, Synthesis, Simulation, Verification, Timing Analysis, System Design (Platform Designer, formerly Qsys)
17244 Discussions

Error in writing opencl kernel

Altera_Forum
Honored Contributor II
1,637 Views

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.
0 Kudos
3 Replies
Altera_Forum
Honored Contributor II
702 Views

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); 

}
0 Kudos
Altera_Forum
Honored Contributor II
702 Views

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.,
0 Kudos
Altera_Forum
Honored Contributor II
702 Views

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); }
0 Kudos
Reply