Results 1 to 2 of 2

Thread: Semaphor problem atomic_xchg function

  1. #1
    Junior Member
    Join Date
    Jun 2012
    Posts
    1

    Semaphor problem atomic_xchg function

    Hi all,

    I have an issue using my Nvidia card and atomic function atom_xchg, in order to implement semaphor. I need to lock for a work-item an array of float named "v" passing as argument to a kernel function: (below the code). When i launch the kernel the semaphor is initialize with 0 (<=> the resource is available)

    Code :
    __kernel void my_ker (__global float* v, __global int* semaphor)
    {
    // Retrieve the index of the work-item
    int g = get_global_id(0);

    // wait for resurce to be available
    while (atom_xchg (semaphor, 1) != 0) {}

    // use the array for the current work-item
    v[g] = (float)g;

    // unlock the resource
    atom_xchg (semaphor, 0);



    return;
    }

    But the program crashes all the timeand i do not understand why? Could someone help me please and explain me why it does not work correctly
    Algernon

  2. #2
    Senior Member
    Join Date
    Aug 2011
    Posts
    271

    Re: Semaphor problem atomic_xchg function

    you cannot implement per-work item semaphores this way.

    e.g. on a gpu if you have say 64 work items running concurrently, the first work item will get the semaphore, but every other one will not - and thus the whole compute unit will go into an infinite loop. on a gpu remember all work items in the work group execute the same instructions at the same time, the code cannot diverge at the work-item level.

    do a search on the various opencl forums for more information, or just give up and use a more appropriate algorithm.

    per work-group semaphores are possible but not very useful since global memory isn't consistent outside of a work-group.


    Quote Originally Posted by Algernon
    Hi all,

    I have an issue using my Nvidia card and atomic function atom_xchg, in order to implement semaphor. I need to lock for a work-item an array of float named "v" passing as argument to a kernel function: (below the code). When i launch the kernel the semaphor is initialize with 0 (<=> the resource is available)

    Code :
    __kernel void my_ker (__global float* v, __global int* semaphor)
    {
    // Retrieve the index of the work-item
    int g = get_global_id(0);

    // wait for resurce to be available
    while (atom_xchg (semaphor, 1) != 0) {}

    // use the array for the current work-item
    v[g] = (float)g;

    // unlock the resource
    atom_xchg (semaphor, 0);



    return;
    }

    But the program crashes all the timeand i do not understand why? Could someone help me please and explain me why it does not work correctly
    Algernon

Similar Threads

  1. OpenGL ES 1.x and LookAt function problem
    By lucasescucha in forum OpenGL ES 1.X - fixed function hardware
    Replies: 1
    Last Post: 03-17-2010, 05:15 AM
  2. problem at using function glLoadMatrix
    By freesui1984 in forum OpenGL ES general technical discussions
    Replies: 2
    Last Post: 03-14-2008, 01:05 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
  •