arrays - Simple CUDA kernel with Bizarre Result? -
arrays - Simple CUDA kernel with Bizarre Result? -
i using cuda kernel object in matlab in order fill 2d array '55's. result strange. 2d array fills point shown below. after row 1025, array zeros. thought going wrong?
as mentioned in comment above, mistakenly offsetting matrix rows. code below total working illustration proving point.
#include<thrust\device_vector.h> __global__ void mykern(double* masterforces, int r_max, int iterations) { int threadsperblock = blockdim.x * blockdim.y; int blockid = blockidx.x + (blockidx.y * griddim.x); int threadid = threadidx.x + (threadidx.y * blockdim.x); int globalidx = (blockid * threadsperblock) + threadid; //for (int i=0; i<iterations; i++) masterforces[globalidx * r_max + i] = 55; (int i=0; i<iterations; i++) masterforces[globalidx * iterations + i] = 55; } void main() { int threadblocksize = 32; int gridsize = 32; int reps = 1024; int iterations = 2000; thrust::device_vector<double> gpuf_m(reps*iterations, 0); mykern<<<gridsize,threadblocksize>>>(thrust::raw_pointer_cast(gpuf_m.data()),reps,iterations); int numerrors = 0; (int i=0; i<reps*iterations; i++) { double test = gpuf_m[i]; if (test != 55) { printf("error %i %f\n",i,test); numerrors++; } } printf("finished!\n"); printf("the number of errors = %i\n",numerrors); getchar(); }
arrays matlab visual-studio-2012 cuda kernel
Comments
Post a Comment