Copying shared 2d matrix values into another 2d matrix

I am wodering how to copy values from one 2d matrix into another 2d matrix
I tried using pointer but it didn’t work:

// store the sub-matrix of A
	__shared__ float As[BLOCK_SIZE][BLOCK_SIZE];
	__shared__ float As2[BLOCK_SIZE][BLOCK_SIZE];
	// Declaration of the shared memory array Bs used to
	// store the sub-matrix of B
	__shared__ float Bs[BLOCK_SIZE][BLOCK_SIZE];
	__shared__ float Bs2[BLOCK_SIZE][BLOCK_SIZE];

	float* pA, pB;


pA = As;
		pB = Bs;

		As2 = pA;
		Bs2 = pB;

If you actually want to copy values, you’ll need to use a loop or some library function (e.g. memcpy) to copy data from one place to another. Unlike perhaps some other languages, AFAIK C and C++ have no concept of copying data by assignment of pointers or array names.

Furthermore, this construct will lead to undefined behavior in C or C++:

As2 = pA;
		Bs2 = pB;

The name of an array is not a pointer, although it decays to a pointer for certain kinds of usages. An array name cannot be reassigned to “point” to something else, the way a pointer can.

So if you intend to use some kind of reference mechanism instead of copying the data (which seems like smart idea to me), don’t use the array names as pointers. Instead, do something like:

float *Aref, *Bref;
   Aref = As2;
   Bref = Bs2;
   Aref = pA;
   Bref = pB;

Note that these are C or C++ programming concepts. Nothing unique or specific to CUDA that I can see.