# cudaMemcpyToSymbol

**URL:** <https://forums.developer.nvidia.com/t/cudamemcpytosymbol/2881>\
**Category:** CUDA Programming and Performance\
**Created:** [March 4, 2008, 7:04pm UTC](https://forums.developer.nvidia.com/t/cudamemcpytosymbol/2881 "2008-03-04T19:04:40Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![gpugpu](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@gpugpu](https://forums.developer.nvidia.com/u/gpugpu)\
**Post date:** [March 4, 2008, 7:04pm UTC](https://forums.developer.nvidia.com/t/cudamemcpytosymbol/2881/1 "2008-03-04T19:04:40Z")

</div>

I’m trying to use

```auto
CUDA_SAFE_CALL( cudaMemcpyToSymbol(d_A, h_A, mem_size_A) );

```

to load data from host to constant memory. But the timing I get is much much larger than when I use

```auto
CUDA_SAFE_CALL(cudaMemcpy(d_A, h_A, mem_size_A,cudaMemcpyHostToDevice));

```

to load the same data from host to device.

Am I doing anything wrong here Or is it supposed to be this way?

Thanks.

---

<div class="post-metadata">

**Author:** ![wumpus](https://sea2.discourse-cdn.com/nvidia/user_avatar/forums.developer.nvidia.com/wumpus/32/12040_2.png) [@wumpus](https://forums.developer.nvidia.com/u/wumpus)\
**Post date:** [March 4, 2008, 9:00pm UTC](https://forums.developer.nvidia.com/t/cudamemcpytosymbol/2881/2 "2008-03-04T21:00:30Z")

</div>

If you manage to get the memory address if the constant you can just use the second. But last time I tried this wasn’t possible when using the Cuda runtime, only when using the API directly [External Image](http://hqnveipbwb20/public/style_emoticons/<#EMO_DIR#>/blarg.gif "Image hosted on another site. Click to open in a new tab.")

---

<div class="post-metadata">

**Author:** ![gpugpu](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@gpugpu](https://forums.developer.nvidia.com/u/gpugpu)\
**Post date:** [March 4, 2008, 10:51pm UTC](https://forums.developer.nvidia.com/t/cudamemcpytosymbol/2881/3 "2008-03-04T22:51:00Z")

</div>

My main question is: Is writing to constant memory slower than writing to global memory?

---

<div class="post-metadata">

**Author:** ![jordyvaneijk](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@jordyvaneijk](https://forums.developer.nvidia.com/u/jordyvaneijk)\
**Post date:** [March 5, 2008, 5:26pm UTC](https://forums.developer.nvidia.com/t/cudamemcpytosymbol/2881/4 "2008-03-05T17:26:26Z")

</div>

> [@](#):
>
> My main question is: Is writing to constant memory slower than writing to global memory?
> 
> [snapback]337736[/snapback]

What do you mean with slower?

It can be that the memCpyToSymbol is the first cuda method and the card need to be initialized this can cause a large slowdown. I’m using cudaMemcpyToSymbol like this:

```auto
CUDA_SAFE_CALL(cudaMemcpyToSymbol("const_d_a", h_a, sizeof(h_a)));

```

Don’t pin me down on it doing this out of my head.

I know accessing Global memory is a little slower than Constant.

But I don’t know about initializing.

---

<div class="post-metadata">

**Author:** ![wumpus](https://sea2.discourse-cdn.com/nvidia/user_avatar/forums.developer.nvidia.com/wumpus/32/12040_2.png) [@wumpus](https://forums.developer.nvidia.com/u/wumpus)\
**Post date:** [March 5, 2008, 5:50pm UTC](https://forums.developer.nvidia.com/t/cudamemcpytosymbol/2881/5 "2008-03-05T17:50:33Z")

</div>

It should be the same speed…

---

<div class="post-metadata">

**Author:** ![AndreiB](https://sea2.discourse-cdn.com/nvidia/user_avatar/forums.developer.nvidia.com/andreib/32/9727_2.png) [@AndreiB](https://forums.developer.nvidia.com/u/AndreiB)\
**Post date:** [March 6, 2008, 9:53am UTC](https://forums.developer.nvidia.com/t/cudamemcpytosymbol/2881/6 "2008-03-06T09:53:45Z")

</div>

Constant memory size is limited to 64 kilobytes so I don’t see how slower memcpy can affect overall performance. And I don’t see why copying to const space should be slower than copying to global space: const is just global with some caching.
