The Khronos Group - a non-profit industry consortium to develop, publish and promote open standard, royalty-free media authoring and acceleration standards for desktop and handheld devices, combined with conformance qualification programs for platform and device interoperability.

If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

The OpenCL C compiler has no access to your struct definition. While it does have some #include capabilities, I'd start by just repeating your struct definition inside the kernel source. Also, you have to be super careful about element alignment when using structs, because they have to line up between your host and your compute device. If possible, stick with basic parameter types and vector parameter types if you can before moving to using a struct.

The above is declared in a separate file. I declare an object of the above type , initialize some values, create a device buffer of the above type and then send the struct type as kernel arguments. Then again i am defining the following inside the kernel source:

Yes, that's what I meant. Perhaps more complex that you'd like, but using #include files in OpenCL can be equally tricky.

One approach that I have used is to create a #include file that has just my types in it and is included from the host. Then this header and the .cl source file(s) are passed to clCreateProgramFromSource as multiple strings (or concatenated into one string). That way you don't need to mess with #include in CL source, but you get the same effect. The downside is that you then need to package the header and .cl files with your application, but each OS usually has a way to do this sort of resource packaging.

The common source approach does suffer from the problem that the types in the host API and the kernel language differ, so you may need to introduce some typedef'ing to get things to work. Also, exercise caution around struct alignment and packing -- the OpenCL spec doesn't contain explicit guarantees about how structs are laid out.

One last note, don't try to pass structs to your kernels by value. Put them in buffer objects and pass those to the kernels as typed pointers.