Results 1 to 2 of 2

Thread: Same function in kernel returning different values.

  1. #1
    Junior Member
    Join Date
    Feb 2010
    Posts
    1

    Same function in kernel returning different values.

    Hi

    I have a program that passes a matrix into a kernel does some maths and then returns the new matrix. It worked fine in CUDA but have had this slight problem in OpenCL. However it does not always return the same value and if I return the matrix through two different variables as shown in the code through data and t_data I get slightly different numbers.

    Why do test and data return different values, when they are defined in exactly the same way and have the same calculation done on them in the kernel?

    What kind of problem could cause this to happen? Sorry about the poor description any thoughts at all would be greatly appreciated.

    This is the maths thats not giving the same value for every point in the matrix, through some are correct and it changes from time to time.
    Code :
    test[loc] = data[loc] -1 ;
    data[loc] = data[loc] -1;

  2. #2
    Senior Member
    Join Date
    Jul 2009
    Location
    Northern Europe
    Posts
    311

    Re: Same function in kernel returning different values.

    Are you certain that no other work-items are changing data[loc] while you do this? You can test by doing:

    temp a = data[loc];
    test[loc] = a -1;
    data[loc] = a -1;

    This will eliminate questions about data[loc] being modified between the two statements, but not what happens later. (E.g., could another work-item write to data[loc] after your last write?)

    This could result in different results from CUDA if the thread scheduling is different due to different work-group sizes or thread code generation. Does your CUDA code rely on any synchronization between warps? Has that been ported over to OpenCL? Are you trying to synchronize between work-groups through global variables perhaps?

Similar Threads

  1. Replies: 3
    Last Post: 11-02-2011, 09:28 PM
  2. Returning a single value from kernel!
    By Atmapuri in forum OpenCL
    Replies: 1
    Last Post: 05-10-2011, 04:08 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
  •