# Basic Performance Ques.. ? from a non-CS .. noob

**URL:** <https://forums.developer.nvidia.com/t/basic-performance-ques-from-a-non-cs-noob/10543>\
**Category:** CUDA Programming and Performance\
**Created:** [July 1, 2009, 2:15pm UTC](https://forums.developer.nvidia.com/t/basic-performance-ques-from-a-non-cs-noob/10543 "2009-07-01T14:15:22Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![nitin.life](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@nitin.life](https://forums.developer.nvidia.com/u/nitin.life)\
**Post date:** [July 1, 2009, 2:15pm UTC](https://forums.developer.nvidia.com/t/basic-performance-ques-from-a-non-cs-noob/10543/1 "2009-07-01T14:15:22Z")

</div>

I have doubt, which has always been back of my mind…

THIS MAY REALLY SEEM A NOOBISH QUESTION to some of you :"\> , but am not a CS guy hence I don’t understand how this all actually works to the core so I want to learn…

if we have situation a:

```auto
shared double a;

  b is some global double array variable;

 // then we do read in a from b

  a[tid] = b[indx]; // assume access coalesced

 //compute (no sync between threads required)

 a[tid] = a[tid]*2.0;

//read out to b

 b[indx] = a[tid];

```

and we have Situation b:

```auto
b is some global double array variable;

 // assume access from device memory as coalesced

 b[indx] =b[indx]*2.0;

```

say if we launch say 32768 threads with 128 threads per block…

would situation A be faster than B ? If so then why ? … because in both case we have one read and write from global memory, and in situation A we have small overhead of copying from and to b to a also…

does doing 1 flop require multiple reads from the memory (it should be just be one read from intuition) ?

or is it because multiplying a global variable with some constant/variable is slower than mutliplying with a shared variable ?

I am not sure what is the exact answer to the above question…

Thanks

NA

---

<div class="post-metadata">

**Author:** ![Nico](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@Nico](https://forums.developer.nvidia.com/u/Nico)\
**Post date:** [July 1, 2009, 2:22pm UTC](https://forums.developer.nvidia.com/t/basic-performance-ques-from-a-non-cs-noob/10543/2 "2009-07-01T14:22:37Z")

</div>

IMHO both situations are comparable in terms of speed. Note that, even in the second situation, the variable gets loaded from DDR memory into a register on chip. Then it gets multiplied by 2 using the register, and afterwards it stores the value of the register back in global memory.  
So the only difference between situation A and B is that you’re using shared memory in A and a register in B. And because accessing shared memory is as fast as accessing a register ( assuming no bank conflicts), then the performance will be approximately the same but with a small overhead for situation A.

N.

---

<div class="post-metadata">

**Author:** ![nitin.life](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@nitin.life](https://forums.developer.nvidia.com/u/nitin.life)\
**Post date:** [July 1, 2009, 2:31pm UTC](https://forums.developer.nvidia.com/t/basic-performance-ques-from-a-non-cs-noob/10543/3 "2009-07-01T14:31:13Z")

</div>

> [@](#):
>
> IMHO both situations are comparable in terms of speed. Note that, even in the second situation, the variable gets loaded from DDR memory into a register on chip. Then it gets multiplied by 2 using the register, and afterwards it stores the value of the register back in global memory.

Dint knew this !!

Thanks… for the input :) …

NA

---

<div class="post-metadata">

**Author:** ![Sarnath](https://sea2.discourse-cdn.com/nvidia/user_avatar/forums.developer.nvidia.com/sarnath/32/9742_2.png) [@Sarnath](https://forums.developer.nvidia.com/u/Sarnath)\
**Post date:** [July 2, 2009, 5:10am UTC](https://forums.developer.nvidia.com/t/basic-performance-ques-from-a-non-cs-noob/10543/4 "2009-07-02T05:10:10Z")

</div>

Shared memory should be used like a cache for staging data.

And, cache thrives on “Locality of Reference” i.e. same data being accessed again and again in a small piece of code.
