# float2 to float array Bank conflicts question

**URL:** <https://forums.developer.nvidia.com/t/float2-to-float-array-bank-conflicts-question/4473>\
**Category:** CUDA Programming and Performance\
**Created:** [July 8, 2008, 9:32am UTC](https://forums.developer.nvidia.com/t/float2-to-float-array-bank-conflicts-question/4473 "2008-07-08T09:32:59Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![oreo1](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@oreo1](https://forums.developer.nvidia.com/u/oreo1)\
**Post date:** [July 8, 2008, 9:32am UTC](https://forums.developer.nvidia.com/t/float2-to-float-array-bank-conflicts-question/4473/1 "2008-07-08T09:32:59Z")

</div>

Hi,

I have a float2 array. I want to get the ‘x’ part of it to create a float array.

My problem is that i do not know how to avoid bank conflicts.

Here’s what i do :

```auto
void complex2real_kernel(Complex* in, Real* out,

       int width, int heigth)

{

   __shared__ Complex block[BLOCK_DIM*BLOCK_DIM];

  

  int xIndex = blockIdx.x * blockDim.x + threadIdx.x;

  int yIndex = blockIdx.y * blockDim.y + threadIdx.y;

  

  int index = yIndex * width + xIndex;

 // copy to shared mem

  block[threadIdx.x + threadIdx.y*BLOCK_DIM] = in[index];

 __syncthreads();

 out[index] = block[threadIdx.x + threadIdx.y*BLOCK_DIM].x;

}

```

The shared mem reading cause bank conflicts.

Is there a way to avoid them ?

Thanks a lot. =)

oYo

---

<div class="post-metadata">

**Author:** ![MisterAnderson42](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@MisterAnderson42](https://forums.developer.nvidia.com/u/MisterAnderson42)\
**Post date:** [July 8, 2008, 1:00pm UTC](https://forums.developer.nvidia.com/t/float2-to-float-array-bank-conflicts-question/4473/2 "2008-07-08T13:00:59Z")

</div>

1. In the kernel you give, global memory is going to be the bottleneck so a few piddly bank conflicts will not slow your performance.

2. Why do you even need shared memory in this kernel? You aren’t sharing values between threads in a block, so just dump in[index] into a local float2 variable.

---

<div class="post-metadata">

**Author:** ![oreo1](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@oreo1](https://forums.developer.nvidia.com/u/oreo1)\
**Post date:** [July 8, 2008, 2:06pm UTC](https://forums.developer.nvidia.com/t/float2-to-float-array-bank-conflicts-question/4473/3 "2008-07-08T14:06:38Z")

</div>

First, thanks for your answer.

> [@](#):
>
> 1. In the kernel you give, global memory is going to be the bottleneck so a few piddly bank conflicts will not slow your performance.
> 
> 2. Why do you even need shared memory in this kernel? You aren’t sharing values between threads in a block, so just dump in[index] into a local float2 variable.
> 
> [snapback]407271[/snapback]

1. I see. I ask the question about this kernel because i have this kind of problems with another one, a float2 array transpose.

I wanted to use the SDK example and modify it to transpose a float2 array. But i get a lot of bank conflicts. I’m wondering about how i could avoid them.

1. That’s what i thought. But when i just use a variable, like this :

```auto
float2 a;

a = in[index];

out[index] = a.x;

```

I get uncoalesced loads and bad performance. Does nvcc “optimizes” this by removing the “useless” variable ?

---

<div class="post-metadata">

**Author:** ![mfatica](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@mfatica](https://forums.developer.nvidia.com/u/mfatica)\
**Post date:** [July 8, 2008, 2:13pm UTC](https://forums.developer.nvidia.com/t/float2-to-float-array-bank-conflicts-question/4473/4 "2008-07-08T14:13:50Z")

</div>

Take a look at slide 50 of [url=“[http://www.gpgpu.org/sc2007/SC07\_CUDA\_3\_Libraries.pdf](http://www.gpgpu.org/sc2007/SC07_CUDA_3_Libraries.pdf)”][http://www.gpgpu.org/sc2007/SC07\_CUDA\_3\_Libraries.pdf[/url]](http://www.gpgpu.org/sc2007/SC07_CUDA_3_Libraries.pdf%5B/url%5D).  
You need to use a volatile to force the vector read.

---

<div class="post-metadata">

**Author:** ![oreo1](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@oreo1](https://forums.developer.nvidia.com/u/oreo1)\
**Post date:** [July 8, 2008, 2:25pm UTC](https://forums.developer.nvidia.com/t/float2-to-float-array-bank-conflicts-question/4473/5 "2008-07-08T14:25:51Z")

</div>

> [@](#):
>
> Take a look at slide 50 of http://www.gpgpu.org/sc2007/SC07\_CUDA\_3\_Libraries.pdf.
> 
> You need to use a volatile to force the vector read.
> 
> [snapback]407311[/snapback]

Thank you, that’s exactly what i needed.

---

<div class="post-metadata">

**Author:** ![oreo1](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@oreo1](https://forums.developer.nvidia.com/u/oreo1)\
**Post date:** [July 8, 2008, 3:50pm UTC](https://forums.developer.nvidia.com/t/float2-to-float-array-bank-conflicts-question/4473/6 "2008-07-08T15:50:56Z")

</div>

I should create a new topic, but…

Is there an easy way to transpose a float2 array avoiding bank conflicts ? :huh:

Thanks again.
