Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Altera_Forum
Honored Contributor I
989 Views

Pass an array of structs as a buffer

Hi everyone. I am trying to pass an array of structs to the kernel using a buffer. 

So what I have tried to do at the moment is: 

 

dev_probConfig = (ProbConfig*)_aligned_malloc(N* sizeof(ProbConfig),64); for (int i = 0; i < N; ++i) { memcpy(&dev_probConfig, h_probConfig, sizeof(ProbConfig)); }  

 

But the second thread or work-item doesn't work. Actually even if I allocate two times the object and then I launch only 1 work item then it fails. 

If I set N to 1 and I launch it with 1 work item it works... 

I cannot explain what is going wrong. 

 

I have done data padding so the size of ProbConfig is 8192 bytes which is multiple of 64. 

 

In the kernel this is my modified pointer depending on the value of the id of the work item. 

 

if(id>0) w_probConfig = &probConfig;  

 

Basically my work items are doing the exact same thing on the exact same data (that's why I need duplicates of structs) and I can't figure out why the second is not getting correct data. 

 

Thanks everyone.
0 Kudos
3 Replies
Altera_Forum
Honored Contributor I
41 Views

What do you mean it "doesn't work"? You get some error or segfault or just incorrect output? 

 

Your syntax for replicating the struct seems correct to me, but why do you even need to replicate it? If you just pass the struct itself as a kernel argument, every work-item in your kernel can access it without any issues. 

 

You should absolutely avoid pointer arithmetic in the kernel, though; it generally won't work as you expect it. You can always use printf in your kernel to see what is happening.
Altera_Forum
Honored Contributor I
41 Views

 

--- Quote Start ---  

What do you mean it "doesn't work"? You get some error or segfault or just incorrect output? 

 

Your syntax for replicating the struct seems correct to me, but why do you even need to replicate it? If you just pass the struct itself as a kernel argument, every work-item in your kernel can access it without any issues. 

 

You should absolutely avoid pointer arithmetic in the kernel, though; it generally won't work as you expect it. You can always use printf in your kernel to see what is happening. 

--- Quote End ---  

 

 

I have tried printf but I was getting zeros when trying to print a double value. I did enable the intel specification for printf but nothing. 

 

Anyway I need a method to get copies of structs and transfer them to the kernel because I cannot make the work-items to work on the same data. It must be duplicated. 

The types of errors I am getting now are of type violation reading/writing.
Altera_Forum
Honored Contributor I
41 Views

Ok I have found out that what I need is to use subBuffers but then again I need to specify these buffers in the kernel... I need to pass a dynamic number of objects and I cannot use offsets on buffers hence no pointer aritmetic on buffers.. This sucks! 

Basically if I need a dynamic NDRange which means more buffers to pass or data I cannot do it!... Is there anyone with a good suggestion?
Reply