Posts

Showing posts with the label gpgpu

OpenCL allocating struct on GPU results in garbage

OpenCL allocating struct on GPU results in garbage I have defined the following struct in C++ host code : struct __declspec(align(16)) MyNode { cl_uchar mData; cl_int3 mPos; }; and in OpenCL : struct __attribute__((aligned(16))) MyNode { uchar mData; int3 mPos; }; now from host code Im calling : MyNode node= {0}; node.mPos.x = 1; node.mPos.y = 2; node.mPos.z = 3; cl_mem clnode_mem = clCreateBuffer( mOpenCLctx, CL_MEM_READ_ONLY | CL_MEM_USE_HOST_PTR, sizeof(MyNode), &node, &err); clSetKernelArg(m_kernel_test, 0, sizeof(cl_mem), &clnode_mem)); then Im calling a test kernel on GPU which is defined as : __kernel void test(__global MyNode* node) { printf("pos = %d,%d,%dn", node->mPos.x, node->mPos.y, node->mPos.z); } but what I see as output is pos = 0,0,0 , and if I remove the mData member from host and device struct definitions, then it is printing correc...