Intel® Quartus® Prime Software
Intel® Quartus® Prime Design Software, Design Entry, Synthesis, Simulation, Verification, Timing Analysis, System Design (Platform Designer, formerly Qsys)
Intel Support hours are Monday-Fridays, 8am-5pm PST, except Holidays. Thanks to our community members who provide support during our down time or before we get to your questions. We appreciate you!

Need Forum Guidance? Click here
Search our FPGA Knowledge Articles here.
15311 Discussions

Structure Padding or Memory Transferring

Honored Contributor I

I have develop a C code to do some calculations on some data made of structures. It works perfectly on CPU with C code. I have then implemented the same code with OpenCL and it is outputting wrong results and by debugging on CPU I can see it's reading wrong values from the structures. I have developed different codes on OpenCl even big codes and didn't have this problem. I am using doubles to avoid precision differences but the problem here is that the data looks getting transferred wrongly. I have no idea why is this happening. What suggestions would you guys give me? I have done already structure packaging correctly I guess. Looks like the memory allocation might be giving some problems but I am not sure why. I am running just 1 work-item and no use of local memory only global. Before I was trying a similar code and it was not giving so many problems. I am thinking it's a problem of memory allocation but I have always done like this in other codes. 

Sorry if I am not posting any code but I can't share it because of my job.
0 Kudos
3 Replies
Honored Contributor I

Without seeing the code, it would be pretty difficult to guess what the problem is.

Honored Contributor I

Let's start with memory allocation. This is how I allocate memory for structures: 


d_orders_size = sizeof(SimpleOrder) * orders->size(); 

d_orders = (SimpleOrder*)_aligned_malloc(d_orders_size, 64); 

for (int i = 0; i < orders->size(); i++) 

d_orders[i] = orders->at(i); 


This is the definition of the structure: 


struct SimpleOrder { 

cl_double a; 

cl_int b; 

enum anEnum c; 


cl_int d; 

cl_int e; 

cl_int padding[10]; 



So it's size of 64 bytes. 


Is there any problem with these two parts? 


The rest of the OpenCL code is the same as the C version so I don't see why there should be any problem since it's a one work item kernel.
Honored Contributor I

I have just realized I was passing the wrong buffer to a function inside the kernel... Sorry for wasting a thread here. Thanks it can be closed.