Results 1 to 4 of 4

Thread: How to use struct in OpenCL

  1. #1
    Junior Member
    Join Date
    Feb 2018
    Posts
    4

    How to use struct in OpenCL

    How can I use my custom struct in OpenCL? Because there are no array of objects in OpenCL, or 2D array beside image.
    Code :
    struct Block {
    char item[4][4];
    };

    I would like to use array of these structs in OpenCL and access its elements by indices like in C/C++. For example

    Code :
    Block *keys = new Block[11];
    keys[3].item[2][2];

  2. #2
    Senior Member
    Join Date
    Apr 2015
    Posts
    321
    You should declare this struct in the OpenCL C code as well. There are usually caveats related to struct alignment, but with your simple structure it should just work.
    Code :
    __kernel void k(__global Block* array){}

  3. #3
    Junior Member
    Join Date
    Feb 2018
    Posts
    4
    I read that there can be some problems with bits and bytes with custom data types. Is it better to use array of this custom struct Block or make 1D array of chars with length 16*number of blocks?

  4. #4
    Senior Member
    Join Date
    Apr 2015
    Posts
    321
    It won't be a problem since you struct is 16-aligned. It could be if you used different data types like char3 and arrays of shorts, but in your case it is unlikely.
    Last edited by Salabar; 03-05-2018 at 04:05 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean