vector component addressing with operator [] is legal?

vector component addressing with operator [] is legal?

Hi,

After checking OpenCL 1.1, 1,2 specification (6.1.7 Vector Components)
http://www.khronos.org/registry/cl/specs/opencl-1.1.pdf
http://www.khronos.org/registry/cl/specs/opencl-1.2.pdf
I was unable to find that following vector component addressing construction is legal in OpenCL:

float4 var;
for(uint i=0; i<4; i++)
{
var[i] = 0.0f;
}

I can understand that for Intel creating overloaded operator [] could make some code elegant.
And personally as programmer, I would prefer to have it as well. Nowadays with OpenCL 1.1
sometimes you forced to write something like this:

float foo(float8 v)
{
float[8] v1;
v1[0] = v.s0; v1[1] = v.s1; v1[2] = v.s2; v1[3] = v.s3;
v1[4] = v.s4; v1[5] = v.s5; v1[6] = v.s6; v1[7] = v.s7;

// compute something using loop, just an example
float res;
for (uint i=0, i<8; i++)
{
res += v1[i];
}
return res;
}

But strictly saying, if that is not legal according to OpenCL 1.1 specification
standard, I would vote to remove this operator from Intel OpenCL as well.
The main argument would be that code become not portable to other platforms.
For example try it on NVidia or AMD OpenCL 1.1 and you will get en error like this:

Build Log:
:27:3: error: subscripted value is not an array, pointer, or vector
var[i] = 0.0f;
^ ~
It could be that I've missed some document.
Could you provide reference that such constructions are legal in OpenCL 1.1, 1.2?

Thanks,
-Denis

4 帖子 / 0 全新
最新文章
如需更全面地了解编译器优化,请参阅优化注意事项

Hello Denis,

Allowing a square bracket notation for indexing vectors means the components accessed are not known during compile time. So, the change is not just syntactic in nature - it would actually be a full-fledged feature.

Doron Singer

Hello Denis,

Allowing a square bracket notation for indexing vectors means the components accessed are not known during compile time. So, the change is not just syntactic in nature - it would actually be a full-fledged feature.

Doron Singer

Hi Denis,
Using operator [] to access a single vector element is not supported according to the OpenCL spec, and it's also inefficient. This usage will be disabled in subsequent versions of the Intel OpenCL SDK.

Thanks
Guy

发表评论

登录添加评论。还不是成员?立即加入