简体   繁体   中英

OpenCL kernel parameters

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.

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 (eg, clSetKernelArg(myKernel, 0, sizeof(cl_int), &myVariable) .

Here is the documentation for clSetKernelArg. Also, search for just about any piece of OpenCL sample code .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM