I have two problems about constant and shared memory on CUDA
(1) Can I copy a float “array” on host memory to device
constant memory? If it can, how to do that? Can anyone give
me a simple example copy a float array from host memory
to device constant memory?
(2) I want to create shared memory dynamically. Suppose I want to
create two 2D float array on shared memory depend on a variable
like __shared__ float array1;
__shared__ float array2;
I know it has to use the dynamical creation from calling the kernel function,
but I encountered some problems on compiling.
Can anyone give me a very simple example to do that?
Your kernel can then read (but not write) from the dFloats array.
#2
No, you can’t dynamically allocate shared memory.
But you could statically allocate a large chunk and just use whatever portion you like of it. If the dimensions keep changing dynamically, you could change to a 1D array and do your own array multiplies, ie array1[x+y*xsize] .
(1) constant memory has nothing with the type of data element, just make sure that its declaration is placed outside any function, and it seem can’t be dynamically allocated, copying data between constant mem and other mem region should use
(2) dynamically allocated array in shared memory by execution configuration should be one dimension, i suggest that you access it as the way to one-dimension array, not the way to 2D
You’re not using the right arguments for the copy to symbol function. It specifies an offset (probably 0). You’re giving only 4 arguments to a 5 argument function.
See the CUDA reference manual for the function definition.