how to pass pointer arguments to non-kernel function in device code

Hello,

I try to build a simple OpenCL program for a lesson I have. I’ve done a little search but I haven’t figured out yet how to procceed. So my problem is this:

I want to have 2 functions in the device, one kernel that calls the other one that is not kernel. The thing is I want to pass pointer arguments, but I read that this is not possible.

__kernel void kernel_func(__global double *startpt, __global double *endpt) {

   //something with startpt

   normal_func(endpt);

}

double normal_func(double *endpt){

   for(i = 0; i < 8; i++) endpt[i] = 1;

}

Also, I would prefer to have endpt as private to each thread and in the end of kernel_func perform a reduction by minimum to some of the values of endpt and return to device the endpt of one thread.

Any help would be appreciated. Even links.

Edit: Problem Solved!

Hi,

I’am also interested in this problem.
Can you please tell us what was the solution in your case?

Thanks!

I had a similar problem when passing a matrix (4x4 float) to the kernel for some operations.

I needed a matrix multiplication with float4, so I wrote a short function, that should take

the matrix:

float4 mult_mat_vec(const float4 *mat, const float4 vec)

{

	float4 res;

	res.x = dot(mat[0], vec);

	res.y = dot(mat[1], vec);

	res.z = dot(mat[2], vec);

	res.w = dot(mat[3], vec);

	return res;

}

The problem was, that the matrix was in [font=“Courier New”]__global[/font] space. But as all my matrices were

I simply modified the function header to look like:

float4 mult_mat_vec(__global const float4 *mat, const float4 vec)

{

	float4 res;

	res.x = dot(mat[0], vec);

	res.y = dot(mat[1], vec);

	res.z = dot(mat[2], vec);

	res.w = dot(mat[3], vec);

	return res;

}

And the compiler stopped complaining.

I guess you simply have to use the same memory space qualifier as in the kernel to pass the argument.

What I did not try, was to pass an offset pointer (like [font=“Courier New”]mult_mat_vec(mat_array + 4, vec)[/font]).

Thanks for the reply.
Indeed, it seems the address space qualifier often solves the problem.
However, it’s not yet very clear to me what the default address space is when talking about pointers as function parameters. I’ll check the documentation once again.