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

Passing of pointers through channels

Altera_Forum
Honored Contributor II
1,279 Views

Here I want my kernel2 to be autorun kernel and as we cannot pass any arguments to kernel2, we are passing an address of a buffer from Kernel1 to Kernel2 through channel and trying to access the contents of that buffer from Kernel2. It's giving segmentation fault. 

1. Is their any limitation for the size of pointers to be passed through channels ? 

2. Can we use memcpy from host ? 

 

 

Implementation is as shown below: 

 

 

channel_kernel.cl:# pragma OPENCL EXTENSION cl_altera_channels : enable 

channel long ch; 

__attribute__((max_global_work_dim(0))) 

__kernel void Kernel1(__global uchar *fptr) 

write_channel_altera(ch, fptr); 

 

 

__attribute__((max_global_work_dim(0))) 

__kernel void Kernel2() 

__global uchar *fptrTemp = read_channel_altera(ch); 

printf("%d\n", fptrTemp[0]); //segmentation fault 

 

 

main.cpp: 

voi main() 

... 

unsigned char *fptr; 

unsigned char *fptr_dup; 

fptr = (unsigned char *)valloc(100); 

fptr_dup = (unsigned char *)valloc(3968 * 2224); 

 

 

for(int i=0;i<100;i++) 

fptr=fptrin

 

//memcpy(fptr, fptrIn, 100);//it leads to segmentation fault 

 

//Below implementation leads to segmentation fault 

//for(int i=0;i<3968 * 2224;i++) 

// fptr_dup=fptrin

 

 

 

 

 

 

In main.cpp, if we are using memcpy() to copy contents from fptrIn to fptr then it is throwing segmentation fault. 

Instead of memcpy() if we are using for loop to copy contents, then it's working for less number of iterations(In above implementation it's 100).  

If we increase iterations to (3968*2224) then again it is giving segmentation fault.
0 Kudos
3 Replies
Altera_Forum
Honored Contributor II
495 Views

Autorum kernels do not have an interface to host or external memory and you cannot access external memory directly from an autorun kernel, even if you pass the pointer through channels. Instead of passing the pointer, you should pass the actual data through channels to the autorun kernel. Autorun kernels should be accompanied by another non-autorun kernel that reads data from external memory and streams it to the autorun kernel via a channel.

0 Kudos
Altera_Forum
Honored Contributor II
495 Views

Thanks for the reply. currently i am not using autorun kernel

I need to pass a 4K Image(3840x2160) pixels from kernel1 to kernel2 via channels.  

1. Is there any restriction on the size of buffer to pass address from one kernel to another ? 

2. "Instead of passing pointer, send the actual data" For this we need to pass an array of size pix[3840x2160], which is really big. Is their any alternative approach for passing this kind of huge buffers from one kernel to other.
0 Kudos
Altera_Forum
Honored Contributor II
495 Views

You should not keep all the image on the FPGA, it is certainly too big for that purpose. If you are doing image filtering/processing, most such algorithms can be "streamed". i.e., store the image in off-chip memory and stream it pixel by pixel to your compute kernel. You can also temporarily store parts of the image in a shift register buffer. If, however, you cannot stream your computation, then you should "block" it. i.e. store all the image in off-chip memory, transfer one [rectangular] part/block of it to a local buffer, compute it, write it back to off-chip memory, then go to the next block. 

 

Autorun kernels work well for "streaming" applications. The size of all local buffers, be it shift register, multi-pored RAM/ROM or FIFOs/channels is limited by the amount of on-chip memory available on your FPGA/
0 Kudos
Reply