Access vector type OpenCL

后端 未结 6 897
礼貌的吻别
礼貌的吻别 2020-12-14 11:53

I have a variable whithin a kernel like:

int16 element;

I would like to know if there is a way to adress the third int in element like

6条回答
  •  再見小時候
    2020-12-14 12:32

    AMD recommends getting vector components this way:

    Put the array of masks into an OpenCl constant buffer:

    cl_uint const_masks[4][4] =
    {
        {0xffffffff, 0, 0, 0},
        {0, 0xffffffff, 0, 0},
        {0, 0, 0xffffffff, 0},
        {0, 0, 0, 0xffffffff},
    }
    

    Inside the kernel write something like this:

    uint getComponent(uint4 a, int index, __constant uint4 * const_masks)
    {
        uint b;
        uint4 masked_a = a & const_masks[index];
        b = masked_a.s0 + masked_a.s1 + masked_a.s2 + masked_a.s3;
        return (b);
    }
    
    __kernel void foo(…, __constant uint4 * const_masks, …)
    {
        uint4 a = ….;
        int index = …;
        uint b = getComponent(a, index, const_masks);
    }
    

提交回复
热议问题