Problem with Shared Memory What allocate dynamic shared memory???

I can allocated dynamic shared memory beacuse i don’t know dimension of this in compile time.

In my shared memory i must have a more type of variable (int,float…and more)

Now, as manual of CUDA 2.0 say, my code for allocate dynamic memory is:

[codebox]extern shared char *numeroIntero;

global void HelloCUDA(int *numeroDevice)

{

int *numero = (int *)numeroIntero;

*numero = 20;

*numeroDevice = *numero;

}[/codebox]

this code give me this error: “error: local and shared variables cannot have external linkage”

OK, change my code in this:

[codebox]global void HelloCUDA(int *numeroDevice)

{

__shared__ char numeroIntero[];

int *numero = (int *)numeroIntero;

*numero = 20;

*numeroDevice = *numero;

}[/codebox]

this code give me this error : “error: incomplete type is not allowed”

OK, change my code in this:

[codebox]shared char numeroIntero;

global void HelloCUDA(int *numeroDevice1)

{

int *numero = (int *)numeroIntero;

*numero = 20;

*numeroDevice1 = *numero;

}[/codebox]

this code give me this error: “Error: Unaligned memory accesses not supported”… but in cuda 2.0 is supported

OK, change my code in this:

[codebox]global void HelloCUDA(int *numeroDevice)

{

__shared__ char *numeroIntero;

int *numero = (int *)numeroIntero;

*numero = 20;

*numeroDevice = *numero;

}[/codebox]

this code give me nothing error, but when i call "cudaMemcpy(&numeroHost,numeroDevice,sizeof(int),cudaMemcpyDeviceToHo

st);" numeroHost don’t change and in emulation mode give me about this error “Access write violation”

BECAUSE? Please help me…

What allocate dynamic shared memory???

use “extern shared int numeroIntero;”

extern __shared__ int numeroIntero[];

__global__ void HelloCUDA(int *numeroDevice)

{	

	int *numero = (int *)numeroIntero;	

	*numero = 20;	

	*numeroDevice = *numero;

}

I have no idea about error message of “extern shared char numeroIntero;”

second, your code

__global__ void HelloCUDA(int *numeroDevice)

{	

	__shared__ char *numeroIntero;	

	int *numero = (int *)numeroIntero;	

	*numero = 20;	

	*numeroDevice = *numero;

}

does not make sense, since you allocate a pointer “numeroIntero” in shared memory,

but its content is not a valid address.