Reputation: 65
I am new in OpenCL. I want to tranfer a type int parameter in the kernel to do the operations, but I don't know how to do this. I have only worked with vectors and matrix, but I have never transfer an atribute.
If I have this code example below:
typedef struct{
int fila;
int columna;
int value;
}Matrix;
int main(){
Matrix matrix;
matrix.row = 56;
matrix.column = 64;
matrix.value = 0;
float A[matrix.fila][matrix.columna];
}
In the kernel:
__kernel void matrix(__global int vue) {
value = value + 10; //it is only an example
}
Can I do that operation above of "matrix.valor" (value + 10) in the kernel?? Or it is only for vectors and matrix operations? Do I need cl_mem or it is not necessary? I'am currently lost with this.
Upvotes: 5
Views: 7933
Reputation: 6343
Remove the __global
from the kernel parameter. Then, in your C/C++ code, have a variable of type cl_int
(declared in cl.h) and set it to the value you want to pass into the kernel. Before enqueing the kernel (with clEnqueueNDRangeKernel
) call clSetKernelArg
with parameters of your kernel, the parameter index (0), sizeof(cl_int), and the address of your variable (e.g., clSetKernelArg(myKernel, 0, sizeof(cl_int), &myVariable)
.
Here is the documentation for clSetKernelArg. Also, search for just about any piece of OpenCL sample code.
Upvotes: 7