Results 1 to 2 of 2

Thread: opencl problems

  1. #1

    Default opencl problems

    I want to use the opencl framework in my project but i'm stuck on the parts that I need. I think I need the Compute, GL, D3D, Core, Display, and SWRender libraries, but I know that I don't need all of them to create a single OpenCL library that I can use. I'm trying to totally integrate it into my project, so I don't want have to handle a lot of extra overhead. Can anyone point me in the right direction?

  2. #2
    ClanLib Developer
    Join Date
    Sep 2006
    Location
    Denmark
    Posts
    554

    Default

    I assume you mean the clanCompute project in the ClanLib 3.0 SVN branch. It was designed around the idea that you create your OpenCL compute context from a GraphicContext. It doesn't have a way of initializing OpenCL without, although itself OpenCL does support such a thing.

    A code example for the clanCompute library:

    Code:
    using namespace clan;
    
    SetupCore setup_core; // Initialize clanCore
    SetupDisplay setup_display; // Initialize clanDisplay
    SetupD3D setup_d3d; // Initialize clanD3D (could also be clanGL)
    SetupCompute setup_compute; // Initialize clanCompute
    
    DisplayWindow window("Hello", 640, 480); // create window with either OpenGL or Direct3D target
    GraphicContext gc = window.get_gc(); // fetch graphics command queue object
    
    ComputeContext cc(gc); // create OpenCL compute context object
    ComputeCommandQueue cq(cc); // create OpenCL command queue for the context
    
    // Create silly compute program that fills a buffer with incrementing values
    ComputeProgram program(cc, "kernel void increment(global unsigned char *buffer) { buffer[get_global_id(0)] = get_global_id(0); }");
    program.build();
    
    ComputeBuffer buffer(cc, 16*1024); // create GPU buffer for output values
    
    ComputeKernel kernel(program, "increment"); // create kernel object for the 'increment' function in our program
    kernel.set_arg_buffer(0, buffer); // bind buffer to first function parameter
    
    ComputeEvent e_run = cq.run_1d(kernel, 16*1024); // dispatch function to be run 16*1024 times
    
    char result[16*1024];
    ComputeEvent e_download = cq.read_buffer(buffer, false, 0, 16*1024, result, e_run); // copy from buffer to a CPU memory buffer (after e_run finished)
    
    e_download.wait(); // wait for transfer to complete
    
    // result should now contain a buffer with values: 0 1 2 3 4 5 .. 253 254 255 0 1 2 ..
    Personally I am no longer using clanCompute for my graphical needs anymore since both OpenGL and Direct3D has compute shaders now. Theoretically OpenCL is more powerful but unfortuantely my own tests revealed that Nvidia's OpenCL/OpenGL interop is so crap that it effectively became useless. You can create compute shaders using ProgramObject in clanDisplay.

    Out of curiosity what do you intend to use it for?

Similar Threads

  1. Problems
    By slunder in forum Tanked
    Replies: 11
    Last Post: 06-27-2012, 01:53 AM
  2. OSX 10.5 problems
    By hmroz in forum Proton SDK
    Replies: 2
    Last Post: 09-16-2011, 07:48 AM
  3. ClanLib and OpenCL 1.1
    By rombust in forum Official ClanLib SDK Forums
    Replies: 12
    Last Post: 07-23-2011, 03:12 PM
  4. FQ Problems?
    By Hawk in forum Funeral Quest
    Replies: 2
    Last Post: 02-11-2010, 10:22 PM
  5. Problems
    By Fr3DBr in forum Official ClanLib SDK Forums
    Replies: 5
    Last Post: 08-23-2009, 09:39 PM

Bookmarks

Bookmarks

Posting Permissions

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