Problem in global memory access

Hi,

<>
I am kind of stuck at a very simple problem…

Here are the details:

  • I have a 2225 x 9635 2D array as input
  • From this one I want to generate a 2225 x 2225 array, which is just Dot product of 2 rows in input array

Here is the Kernel for the same:
#define DOCS 2225
#define TERM 9635

global void compute_similarity(float * term_doc_M, float * weight_mat,float cut_off)
{
int bx = blockIdx.x;
int tx = threadIdx.x;
int by = blockIdx.y;
int ty = threadIdx.y;

int i = by* blockDim.y + ty;
int j = bx* blockDim.x + tx;

if(i < DOCS && j < DOCS)
weight_mat[i* DOCS + j ]= 0 ;

float tmp =0, tmp1=0, tmp2=0;

if(i < DOCS && j < DOCS)
{
if(i == j)
{
weight_mat[i* DOCS + j ]=1 ;
return ;
}
if(j > i)
return;

for(int k =0 ; k < TERMS; k++)
{
tmp += term_doc_M[j* TERMS + k] * term_doc_M[i*TERMS+k];
}
weight_mat[i* DOCS + j ]= tmp;
weight_mat[j* DOCS + i ]=tmp ;
}
}

Now, problem here is: I am getting answer as all 0s. Dont know why…

Here are things I have verified:

  1. The input array contains correct data and its not 0.
  2. When i try to access ith row, it is givin correct data. But when i try to access jth row, it is returning all 0s :( It does not seem to follow any logic. If i try to access a single element instead of entire row for j, it returns correct value again… I am totally clueless what is happening here… :(

Any help is really appreciated!

Thank you!

Hi,

<>
I am kind of stuck at a very simple problem…

Here are the details:

  • I have a 2225 x 9635 2D array as input
  • From this one I want to generate a 2225 x 2225 array, which is just Dot product of 2 rows in input array

Here is the Kernel for the same:
#define DOCS 2225
#define TERM 9635

global void compute_similarity(float * term_doc_M, float * weight_mat,float cut_off)
{
int bx = blockIdx.x;
int tx = threadIdx.x;
int by = blockIdx.y;
int ty = threadIdx.y;

int i = by* blockDim.y + ty;
int j = bx* blockDim.x + tx;

if(i < DOCS && j < DOCS)
weight_mat[i* DOCS + j ]= 0 ;

float tmp =0, tmp1=0, tmp2=0;

if(i < DOCS && j < DOCS)
{
if(i == j)
{
weight_mat[i* DOCS + j ]=1 ;
return ;
}
if(j > i)
return;

for(int k =0 ; k < TERMS; k++)
{
tmp += term_doc_M[j* TERMS + k] * term_doc_M[i*TERMS+k];
}
weight_mat[i* DOCS + j ]= tmp;
weight_mat[j* DOCS + i ]=tmp ;
}
}

Now, problem here is: I am getting answer as all 0s. Dont know why…

Here are things I have verified:

  1. The input array contains correct data and its not 0.
  2. When i try to access ith row, it is givin correct data. But when i try to access jth row, it is returning all 0s :( It does not seem to follow any logic. If i try to access a single element instead of entire row for j, it returns correct value again… I am totally clueless what is happening here… :(

Any help is really appreciated!

Thank you!

Hi,

Adding to the previous post… well the for loop within the Kernel, it loops from 0 to 9635… this being a big value i tried to loop from 0 to smaller value of k… and i got non-zero correct results!

This is weird but if i did K=0 to 5000 i got correct result :P

Umm… Has anyone faced this kind of issue before…?

Thanks!

Hi,

Adding to the previous post… well the for loop within the Kernel, it loops from 0 to 9635… this being a big value i tried to loop from 0 to smaller value of k… and i got non-zero correct results!

This is weird but if i did K=0 to 5000 i got correct result :P

Umm… Has anyone faced this kind of issue before…?

Thanks!