Reputation: 31
I have a problem to send some data to my device.
The data type I want to receive in my kernel is :
typedef struct{uint3 nbCells;
float3 worldOrigin;
float3 cellSize;
float3 gridSize;
float radius;
} grid_t;
and the data type I send from the host is :
typedef struct{
uint nbCells[3];
float worldOrigin[3];
float cellSize[3];
float gridSize[3];
float radius;
} grid_t;
but it didn't work well.
I send that:
8, 8, 8; 0, 0, 0; 1.03368e-06, 1.03368e-06, 1.03368e-06; 8.2694e-06, 8.2694e-06, 8.2694e-06; 3e-07
but in my kernel I receive that :
8, 8, 8; 0, 0 1.03368e-06; 1.03368e-06, 8.2694e-06, 8.2694e-06; 3e-07, 8.2694e-06, 0; 1.16428e-05
I known the float3 is in reality considered like float4 in Opencl, so I try with float4 and array of 4 float, but it didn't work too. I try to receive the data with array of 3 float instead float3 and it work perfectly. Its seems, in opencl, a structure composed with 3 float haven't got the same memory size that an array of 3 float. And with the same structure, but with double instead of float, that work perfectly.
Upvotes: 2
Views: 1344
Reputation: 8410
You should never try to match CL types to non-CL types. Unless you really know they do match.
If this is your kernel type:
typedef struct{
uint3 nbCells;
float3 worldOrigin;
float3 cellSize;
float3 gridSize;
float radius;
} grid_t;
This should be your host types:
typedef struct{
cl_uint3 nbCells;
cl_float3 worldOrigin;
cl_float3 cellSize;
cl_float3 gridSize;
cl_float radius;
} grid_t;
Thats the use case for the cl data types defined on the host side (when you include the cl.h).
Your error comes from using a float3 type (same as float4), and emulating that type with a float[3]
instead of float[4]
.
Upvotes: 5