简体   繁体   English

将结构传递给openCL Kernel

[英]Passing structure to openCL Kernel

I want to pass a structure to opencl kernel, the structure is 我想将一个结构传递给opencl内核,结构是

struct test
{
    int *x;
    float *y;
    char *z;
};

and the memory allocation and initialization is like 和内存分配和初始化是一样的

    struct test t;
t.x = (int*)malloc(sizeof(int)*100);
t.y = (float*) malloc (sizeof(float)*50);
t.z = (char*) malloc (sizeof(char) *25);
  for(i = 0;i<100;i++)
  {
      t.x[i] = i;
      if(i<50)
          {
              t.y[i] = i;
          if(i<25)
              t.z[i] = 'a';
          }
  }

can i pass such a structure to opencl kernel 我可以将这样的结构传递给opencl内核吗?

You can pass such a structure, but it will be pointless because x , y and z point to different memory regions. 可以传递这样一个结构,但它没有意义,因为xyz指向不同的内存区域。 Each of these memory buffers must be transferred on its own. 每个内存缓冲区必须自己传输。

而不是结构,最好在主机端分配内存并将它们作为内核参数发送到内核。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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