Hello ,
I wanted to ask if Iam using the dynamic shared size properly becaause running my code ,it shows illegal address and I have to use a large size ,for example 500 in order to work.
typedef struct
{
float X,Y;
int Value;
} Points;
In the kernel:
int x = ( blockIdx.x * blockDim.x ) + threadIdx.x;
int y = ( blockIdx.y * blockDim.y ) + threadIdx.y;
extern __shared__ Points points[ ];
float distX , distY;
if ( x < blockDim.x * gridDim.x && y < blockDim.y * gridDim.y )
{
for ( int i = 0; i < NbOfNodes; i++ )
{
//load data to shared memory
points[ gridDim.x * threadIdx.y + threadIdx.x ].X = X[ i ];
points[ gridDim.x * threadIdx.y + threadIdx.x ].Y = Y[ i ];
points[ gridDim.x * threadIdx.y + threadIdx.x ].Value = V[ i ];
__syncthreads();
//Calculate distances for all the points
for ( int j = 0; j < NbOfNodes; j++ )
{
distX = points[ j ].X - x;
distY = points[ j ].Y - y;
...
So , my shared memory size should be : ThreadsPerBlockX + ThreadsPerBlockY * BlocksPerGridX , right?
I am receiving the illegal address at distX.
In the calling function:
dim3 BlocksDim ( BlocksPerGridX , BlocksPerGridY );
dim3 ThreadsPerBlock ( ThreadsPerBlockX , ThreadsPerBlockY );
size_t DynamicSharedSize = ThreadsPerBlockX + ThreadsPerBlockY * BlocksPerGridX;
for ( int i = 0; i < NbOfNodes; i++ )
{
//Call kernel
mykernel<<< BlocksDim,ThreadsPerBlock, DynamicSharedSize * sizeof(Points) >>>(
...
Any ideas?
Thanks!