How to enable float4 (OpenCL)

Discussion in 'Mac Programming' started by :-), Oct 5, 2011.

  1. :-) macrumors member

    Joined:
    Sep 4, 2009
    #1
    Hello. I'm new in OpenCL. I would like to take advantage of vector data types (like float4...). I'm working with NBody problem and would like to store location and charge of particles in 1D array of float4 (like struct -> x, y, z, charge). I've included in my main program library like this:

    #include <vecLib/vecLib.h>

    But it seems like it doesn't work this way. Have I forgotten anything? Is there anything else I need to include so that float4 would work?
     
  2. gnasher729 macrumors P6

    gnasher729

    Joined:
    Nov 25, 2005
    #2
    vecLib has nothing to do with OpenCL.

    Download the OpenCL sample code from Apple which lucky for you handles the N-body problem. That's what sample code is there for.
     
  3. holmesf, Oct 24, 2011
    Last edited: Oct 24, 2011

    holmesf macrumors 6502a

    Joined:
    Sep 30, 2001
    #3
    Your question reveals some misunderstanding about what OpenCL is. OpenCL is both runtime and a programming language:

    The OpenCL runtime is used to query available compute devices, compile programs, manage memory buffers, run programs (kernels), and other things. The OpenCL runtime is accessed via C based APIs which you use in your traditional C, C++, or Objective-C program. The runtime acts as the "glue" between your traditional program running on the CPU and your OpenCL programs (kernels) that may either be running in parallel on the CPU, GPU, or (in theory) some other compute device.

    The OpenCL programming language is a special programming language used to write OpenCL programs. This is the language that is actually compiled and run in parallel on the compute device (CPU, GPU, or other). The compilation happens at run-time, which is why you see OpenCL programs included as text files (often using the extension .cl) alongside the program executable. float4 is a feature of the OpenCL programming language, in other words not something you use in your C, C++, or Objective-C program source code (the client side). It is a built in feature of OpenCL 1.0, so there is nothing you need to do to "enable" it. #include doesn't even exist in the OpenCL programming language to do that anyway.

    OpenCL is a very different architecture from what people are used to dealing with. It takes reading to really understand it. It also takes a lot of code to even get very simple programs running.

    If you haven't already, you should read Apple's OpenCL programming guide:
    http://developer.apple.com/library/mac/documentation/Performance/Conceptual/OpenCL_MacProgGuide/OpenCL_MacProgGuide.pdf
     

Share This Page