# Bug in float3\* addressing

**URL:** <https://forums.developer.nvidia.com/t/bug-in-float3-addressing/26572>\
**Category:** CUDA Programming and Performance\
**Created:** [May 4, 2012, 3:24pm UTC](https://forums.developer.nvidia.com/t/bug-in-float3-addressing/26572 "2012-05-04T15:24:23Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![KazA\_Csaba](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@KazA\_Csaba](https://forums.developer.nvidia.com/u/KazA_Csaba)\
**Post date:** [May 4, 2012, 3:24pm UTC](https://forums.developer.nvidia.com/t/bug-in-float3-addressing/26572/1 "2012-05-04T15:24:23Z")

</div>

Hello,

I have this simple test kernel:

```auto
__kernel void vectest(__global float3* data, __global float* ret) {

    float3 v=data[1];

    ret[0]=v.x; ret[1]=v.y; ret[2]=v.z;

}

```

data = [0, 1, 2, 3, 4, 5, 6]

ret = [4, 5, 6]

According to the data I receive in the ret array, the float3 variable v consists of the floats at index positions 4-6, instead of 3-5. It seems that when the driver converts the float3 array access to byte offset, it incorrectly assumes that the array element size is 4_4 bytes instead of 3_4.

Using the 64-bit Linux driver version 295.49, running on a GeForce GTX 285.

Csaba

---

<div class="post-metadata">

**Author:** ![Meteorhead](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@Meteorhead](https://forums.developer.nvidia.com/u/Meteorhead)\
**Post date:** [May 9, 2012, 11:25am UTC](https://forums.developer.nvidia.com/t/bug-in-float3-addressing/26572/2 "2012-05-09T11:25:56Z")

</div>

Hi Csaba!

Indeed, that is very frustrating, however I would discourage the use of any type aligned to 3\*sizeof(), because GPUs don’t handle it well. If on host side you ask the size of these types, you will get sizeof(cl\_float3) = sizeof(cl\_float4). So when even host side does not use it properly, it gets very messy, even if device would use it properly.

GPUs are highly optimized for types aligned to either 4 bytes, or 16 bytes. Even if you need only 3 variables in a vector, use float4 and just disregard the last element. If you don’t want to waste the memory, use three independant arrays of floats.

Regards,  
MÃ¡tÃ©

---

<div class="post-metadata">

**Author:** ![KazA\_Csaba](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@KazA\_Csaba](https://forums.developer.nvidia.com/u/KazA_Csaba)\
**Post date:** [May 17, 2012, 8:49am UTC](https://forums.developer.nvidia.com/t/bug-in-float3-addressing/26572/3 "2012-05-17T08:49:34Z")

</div>

Wow, you’re right. In fact, I was very wrong. I blindly assumed that the size of float3 was 12 bytes, but it is in fact 16 bytes, as clearly stated in the specification, section 6.1.5.

I apologize for falsely accusing NVIDIA out of sheer ignorance.

Csaba
