Constant memory confusion

First of all how do you allocate constant memory and assign values to the locations?
Is this the only possibility to declare constant memory:
constant float a[100];

or can you use cudaMalloc? Can I write into the locations of a, inside the host code, whitout any restrictions?

Secondly, I know what bank conflicts are when talking about shared memory, but what are bank conflicts when talking about constant cache?

And third, I also found a research article stating the following for constant memory: 8KB cache per SM, with data originally residing in global memory. I thought data can be moved into constant memory only from the host…

Thank you very much!

First of all how do you allocate constant memory and assign values to the locations?
Is this the only possibility to declare constant memory:
constant float a[100];

or can you use cudaMalloc? Can I write into the locations of a, inside the host code, whitout any restrictions?

Secondly, I know what bank conflicts are when talking about shared memory, but what are bank conflicts when talking about constant cache?

And third, I also found a research article stating the following for constant memory: 8KB cache per SM, with data originally residing in global memory. I thought data can be moved into constant memory only from the host…

Thank you very much!

You allocate constant memory the way you have stated, then use cudaMemcpyToSymbol() to copy data from the host to “a”.

There are no bank conflicts with the constant cache, but i think the constant cache works best with broadcast accesses, i.e when all threads access the same location.

Refer to the Nvidia programming guide for more details on constant memory.

As for the article, I suppose constant memory first resides in global mem and the cache is populated as constant memory is accessed.

You allocate constant memory the way you have stated, then use cudaMemcpyToSymbol() to copy data from the host to “a”.

There are no bank conflicts with the constant cache, but i think the constant cache works best with broadcast accesses, i.e when all threads access the same location.

Refer to the Nvidia programming guide for more details on constant memory.

As for the article, I suppose constant memory first resides in global mem and the cache is populated as constant memory is accessed.

Ok, thanks.

But which is actually the difference between cudaMemcpy and cudaMemcpyToSymbol other than the fact that the former can have as destination host memory and the latter only device memory?

Also, cudaMalloc can be used to allocate device memory only of type global memory?

Ok, thanks.

But which is actually the difference between cudaMemcpy and cudaMemcpyToSymbol other than the fact that the former can have as destination host memory and the latter only device memory?

Also, cudaMalloc can be used to allocate device memory only of type global memory?

cudaMemcpy() takes two pointers, where cudaMemcpyToSymbol() takes a pointer and the name of a variable (making up for not having a linker on the device side).
The apparent asymmetry is resolved by also having cudaMemcpyFromSymbol().

cudaMemcpy() takes two pointers, where cudaMemcpyToSymbol() takes a pointer and the name of a variable (making up for not having a linker on the device side).
The apparent asymmetry is resolved by also having cudaMemcpyFromSymbol().

Ok, but then why does the prototype ofthe function contain two pointers (a void and a char one):
cudaError_t cudaMemcpyToSymbol (const char * symbol, const void * src, size_t count, size_t offset, enum cudaMemcpyKind)

Can someone please explain?

Ok, but then why does the prototype ofthe function contain two pointers (a void and a char one):
cudaError_t cudaMemcpyToSymbol (const char * symbol, const void * src, size_t count, size_t offset, enum cudaMemcpyKind)

Can someone please explain?

The [font=“Courier New”]const char * symbol[/font] points to a string containing the name of the variable, not to the variable itself.

The [font=“Courier New”]const char * symbol[/font] points to a string containing the name of the variable, not to the variable itself.