Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

代码5有误 #3

Open
JuncFang-git opened this issue Sep 5, 2021 · 1 comment
Open

代码5有误 #3

JuncFang-git opened this issue Sep 5, 2021 · 1 comment

Comments

@JuncFang-git
Copy link

代码5中,使用到cpu printMatrix代码中有误,应将C[j] 改为 ic[j]:
void printMatrix(float * C,const int nx,const int ny)
{
float *ic=C;
printf("Matrix<%d,%d>:",ny,nx);
for(int i=0;i<ny;i++)
{
for(int j=0;j<nx;j++)
{
printf("%6f ",ic[j]); // change C[j] -> ic[j]
}
ic+=nx;
printf("\n");
}
}

代码5中,使用到gpu printThreadIndex代码中有误,应将最后的格式化%d 改为 %f, 否则输出全为0:
global void printThreadIndex(float *A, const int nx, const int ny){
int ix = threadIdx.x + blockIdx.x * blockDim.x;
int iy = threadIdx.y + blockIdx.y * blockDim.y;
unsigned int idx = iy * nx + ix;
printf("thread_id(%d,%d) block_id(%d,%d) coordinate(%d,%d)"
"global index %2d ival %2f\n",threadIdx.x,threadIdx.y, // change %2d -> %2f
blockIdx.x,blockIdx.y,ix,iy,idx,A[idx]);
}

@wscjxky
Copy link

wscjxky commented Apr 24, 2022

正想说这个问题!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants