Altera_Forum
Honored Contributor
7 years agoPassing of pointers through channels
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.