Results 1 to 3 of 3

Thread: OpenCL on Visual Studio 2008. Some unknown types and macros.

  1. #1
    Junior Member
    Join Date
    Mar 2010
    Posts
    3

    OpenCL on Visual Studio 2008. Some unknown types and macros.

    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 200. 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:
    Code :
    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
    Code :
    clCreateImage3D
    is understood. The code compile.
    But I can't check if it really works because the function
    Code :
    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":
    Code :
     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:
    Code :
     #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):
    Code :
    // 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

  2. #2
    Junior Member
    Join Date
    Mar 2010
    Posts
    3

    Re: OpenCL on Visual Studio 2008. Some unknown types and macros.

    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:
    Code :
    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.
    Code :
    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

  3. #3
    Junior Member
    Join Date
    Mar 2010
    Posts
    3

    Re: OpenCL on Visual Studio 2008. Some unknown types and macros.

    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

    Next time maybe.
    Ganesh

Similar Threads

  1. openCL using visual studio 2008..
    By phoebe0105 in forum OpenCL
    Replies: 0
    Last Post: 04-19-2010, 09:50 AM
  2. Replies: 2
    Last Post: 03-19-2010, 09:55 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •