Results 1 to 7 of 7

Thread: Problem with matrix

  1. #1
    Junior Member
    Join Date
    Mar 2011
    Posts
    5

    Problem with matrix

    Hi

    I have big, but I think simple, problem. I have to do kernel that calculates value of function. I have points in one matrix:

    args = [x1,x2,x3,y1,y2,y3,z1,z2,z3]

    I have to calculate:

    f(x1,y1,z1), f(x2,y2,z2), f(x3,y3,z3)

    In what ways I can write kernel to do this function?

    I don't have problems with adding vectors in kernel, but this is too much for me.
    Big thanks for all of replies and sorry for my English .

  2. #2
    Senior Member
    Join Date
    May 2010
    Location
    Toronto, Canada
    Posts
    845

    Re: Problem with matrix

    Hi lesiupoland,

    I'm not sure I understand the problem. Could you explain how to solve the problem in C? Then we can then help you with OpenCL.
    Disclaimer: Employee of Qualcomm Canada. Any opinions expressed here are personal and do not necessarily reflect the views of my employer. LinkedIn profile.

  3. #3
    Junior Member
    Join Date
    Mar 2011
    Posts
    5

    Re: Problem with matrix

    I have many points P(x,y,z) written in convention of 1D array:

    D = [x1,x2,x3....,xn,y1,y2,y3.....,yn,z1,z2,z3.....,zn]

    Where n is number of all points.

    I have ecuation in example:

    F = x+y+z

    I have to write kernel that takes all of needed variables from a 1D array and gives me back value F.

    in C:
    F1 = D[0]+D[n]+D[2*n]
    F2 = D[1]+D[n+1]+D[2*n+1]
    etc.

    I know how to write kernel which use all of elements from array, or many arrays of the same size. Example is adding vectors.
    I don't know how to write kernel which choose specified elements from array and do operations on them. I searched many tutorials, and I didn't find any solution of my problem.

  4. #4
    Senior Member
    Join Date
    May 2010
    Location
    Toronto, Canada
    Posts
    845

    Re: Problem with matrix

    Okay, this is roughly what your kernel will look like:

    Code :
     
    float my_function(float x, float y, float z)
    {
        // For example
        return x + y + z;
    }
     
    __kernel void myKernel(__global float* input, __global float* output)
    {
        size_t gid = get_global_id(0);
     
        // Notice that '3' is the number of input arguments (x,y,z)
        float x = input[3*gid];
        float y = input[3*gid+1];
        float z = input[3*gid+2];
     
        float result = my_function(x,y,z);
     
        output[gid] = result;
    }

    Let me know if you have any questions.
    Disclaimer: Employee of Qualcomm Canada. Any opinions expressed here are personal and do not necessarily reflect the views of my employer. LinkedIn profile.

  5. #5
    Junior Member
    Join Date
    Mar 2011
    Posts
    5

    Re: Problem with matrix

    Thanks for quick reply. I'll check this suggestion tomorrow!

  6. #6
    Junior Member
    Join Date
    Mar 2011
    Posts
    5

    Re: Problem with matrix

    Code :
    __kernel void Fitness(__global float* functions_args, __global float* functions_values, __global int* N)
    {
    size_t idx = get_global_id(0);
    functions_values[idx] = pow(functions_args[N*idx],2)+pow(functions_args[N*idx+1],2);",
    }
    Can I pass N as argument to kernel? Above kernel don't work, but this works good:
    Code :
    __kernel void Fitness(__global float* functions_args, __global float* functions_values, __global int* N)
    {
    size_t idx = get_global_id(0);
    functions_values[idx] = pow(functions_args[2*idx],2)+pow(functions_args[2*idx+1],2);",
    }

    Value of passed argument is 2.
    What I'm doing wrong?
    Explicit "2" in 2nd kernel generates good program, but N from first kernel don't work -> it generates error when compiler tries to compile kernel.

  7. #7
    Junior Member
    Join Date
    Mar 2011
    Posts
    5

    Re: Problem with matrix

    I found solution!
    I had a mistake in passing args to kernel. Sorry .

Similar Threads

  1. Replies: 0
    Last Post: 03-27-2012, 06:40 AM
  2. matrix addition problem
    By bubu in forum OpenCL
    Replies: 6
    Last Post: 04-23-2011, 01:29 PM

Posting Permissions

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