Access vector type OpenCL

后端 未结 6 899
礼貌的吻别
礼貌的吻别 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:28

    It is possible, but it not as efficient as direct array accessing.

    float index(float4 v, int i) {
        if (i==0) return v.x;
        if (i==1) return v.y;
        if (i==2) return v.z;
        if (i==3) return v.w;
    }
    

    But of course, if you need component-wise access this way, then chances are that you're better off not using vectors.

提交回复
热议问题