0

I'm pretty new to OpenCL. My OpenCL-code is pretty simple. It contains 2 functions where the __kernel-functions calls another (non-kernel) function. I want pass the array to this function, but when I do that, my function (add) always returns 0. The complete array is 0. But when I access the same index in my kernel-function, the result is as expected... here's the code I'm using:

    int add(__global  int * numArray) {
        return numArray[1]+numArray[2];

    }

    __kernel void sum(__global int * numArray, __global int * result) {
        result[get_global_id(0)] = numArray[0] //
        result[get_global_id(0)] = add(numArray); // = 0
    }

Is there anything I doing wrong here?

5
  • "The complete array is 0." Does this mean that all the elements of your array has the value 0? Commented Nov 11, 2013 at 19:23
  • My host generats random numbers which I'm passing to my kernel-function. When I access the numbers in my kernel-function, everything is fine. But when I pass the array to a helper function like add, all the elements of my array has the value 0. Commented Nov 11, 2013 at 19:28
  • Which OpenCL implementation you are using? Commented Nov 11, 2013 at 20:03
  • OpenCL 1.1 and library is cl4d (D programming language) Commented Nov 11, 2013 at 20:41
  • From what vendor is the implementation? 1.1 would imply nVidia. Commented Nov 11, 2013 at 22:02

2 Answers 2

1

You are missing a semicolon on this line:

result[get_global_id(0)] = numArray[0] //

Therefore the second line is just a continuation of the first (although I'd expect it to generate an error).

If that's not it, I'd change add() to use "numArray[0]" to do an exact comparison against the version that doesn't call add(), so you are comparing apples to apples (and not relying on the values in elements 1 and 2).

Sign up to request clarification or add additional context in comments.

Comments

0

Thanks to all... it was my mistake. I assigned some values to 0 and I just tried to add these.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.