PDA

View Full Version : OpenCL on Visual Studio 2008. Some unknown types and macros.



Ganesh
03-03-2010, 04:43 AM
Hello everyone.

I'm french, so please excuse my spelling mistakes.

I need to implement an octree structure on GPU (using 3D texture).
I thought OpenCL was a good idea to do that: 3D Image reading and writing seem easy to use.

Unfortunately, I really don't know OpenCL, and more I'm searching, more lost I am.
Plus, I'm working in a really unfriendly environment (Windows 7 + Visual Studio 2008). That's not my choice.
I'm not even sure that Visual Studio is able to understand OpenCL.

I found the headers here: http://www.khronos.org/registry/cl/
I have: cl.h, cl.hpp, cl_ext.h, cl_gl.h, cl_gl_ext.h, cl_platform.h, opencl.h.
And I have OpenCL.lib (I don't remember where I got it).

However, even a very simple code doesn't compile. A lot of functions, types, and macros are not know by the compiler.
I get 4 errors on this line:

sampler_t sampler = CLK_NORMALIZED_COORDS_TRUE | CLK_ADDRESS_REPEAT | CLK_FILTER_NEAREST; Type sampler_t, and the 3 next macros are unknown (undeclared identifiers).

The function
clCreateImage3D is understood. The code compile.
But I can't check if it really works because the function
read_imageui is unknown.

A last example.
All the types float2, float4, int2, int4, unsigned int4, etc... are undefined.
If I add 'cl_' before the names, it "works":

cl_float4 v;
float test = v.s[1]; However, I can only access to v.s, which is a table of float. I can't acces to v.x, v.y, v.z, and v.w I expected.
The types float4 and cl_float4 seem different.


I put in my header the following:
#include <CL/opencl.h> And VS is set to use "CL/openCL.lib".

I have this basic code compiling (I don't really know if it is working):


// OpenCL Init
cl_uint numDevicesReturned;
cl_device_id devices[1];

cl_int err = clGetDeviceIDs(NULL, CL_DEVICE_TYPE_GPU, 1, &devices[0], &numDevicesReturned);

cl_context context;
context = clCreateContext (0, 1, devices, NULL, NULL, &err);

cl_command_queue queueGpu;
queueGpu = clCreateCommandQueue (context, devices[0], 0, &err);
// OpenCL Init end



Is there something I did wrong ?
Do you have any idea on where I can find the headers which declares the functions, variables, and macros I need ?
Or if it is a problem from Visual Studio, do you know how to configure it correctly ?

If you need more information to help me, don't hesitate to ask me.

And, of course, do you know where I can find a complete implementation of octree on GPU using OpenCL ? ;)

Anyway
Thank you for your help.

Ganesh

Ganesh
03-04-2010, 02:34 AM
I begin to understand OpenCL a little better.

So I have to precise that I tried to declare a float4 in the "standard code", and not in the kernel code.

It may appear completely stupid to some of you, but I hope my mistake will help other people.

Here is my little program, which seems to work:

const char *KernelImage = "\n" \
"__kernel void info( \n" \
" __read_only __global image3d_t input, \n" \
" const int x, \n" \
" const int y, \n" \
" const int z, \n" \
" __write_only __global int4* output) \n" \
"{ \n" \
" int4 coord; \n" \
" coord.x = x; \n" \
" coord.y = y; \n" \
" coord.z = z; \n" \
" sampler_t sampler = CLK_NORMALIZED_COORDS_TRUE | CLK_FILTER_NEAREST | CLK_ADDRESS_REPEAT; \n" \
" int4 res = read_imagei (input, sampler, coord); \n" \
" *output = res; \n" \
"} \n" \
"\n";

Input is an empty 3D Image of size 128x128x128.

cl_mem input = clCreateImage3D (context, CL_MEM_READ_WRITE, (const cl_image_format*) &format, 128, 128, 128, 0, 0, NULL, &err);

Output is the color of the voxel at coord(x,y,z). It's (0,0,0,0) whatever the coord.
That seems normal because I didn't fill the image.

In fact, I'm not really sure that my code works, because the result is 0 even if the coords are out of range.

Is that normal ?

Thank you again.
Ganesh

Ganesh
03-04-2010, 09:02 AM
I finally understood what did sampler_t.
And it appears that CLK_ADDRESS_REPEAT makes the texture coordinates loop.
So my out-of-range were not.

I now have a new problem with write_imagei, but it's no longer the theme of this thread.
So I will close it. (or let an admin closes it)

Sorry if I didn't let you enough time to help me :wink:

Next time maybe.
Ganesh