Here is my kernel call:
const size_t numBins = 1024;
const dim3 blockSize(512);
unsigned int * d_binHistogram, * d_cdf;
checkCudaErrors(cudaMalloc((void**) &d_binHistogram, sizeof(unsigned int)*numBins));
checkCudaErrors(cudaMemset(d_binHistogram, 0, sizeof(unsigned int)*numBins));
checkCudaErrors(cudaMalloc((void**) &d_cdf, sizeof(unsigned int)*numBins));
checkCudaErrors(cudaMemset(d_cdf, 0, sizeof(unsigned int)*numBins));
blellochScan<<<(numBins/512+1,1,1),blockSize,blockSize.x*sizeof(float)>>>(d_binHistogram, numBins, d_cdf);
cudaDeviceSynchronize(); checkCudaErrors(cudaGetLastError());
Here is the kernel:
__global__ void blellochScan(const unsigned int* const d_bin, const size_t numBins,
unsigned int* const d_cdf){
unsigned int i = blockIdx.x*blockDim.x+threadIdx.x;
unsigned int result = 0;
for(unsigned int j = 0; j<i; j++){
result += d_bin[j];
}
d_cdf[i] = result;
printf("%u %u\n", i, d_cdf[i]);
}
In the output, there are only i value from 0 to 511, there is no i value from 512 to 1023 of the second block. What did I do wrong?
Also, I am not sure of the third parameter in kernel launch blockSize.x*sizeof(float). How should I determine what to put in this third parameter?
blocksizewith a lowercase s as your dim3 variable, andblockSizewith an uppercase S as the variable you're using in your kernel call. This code seems to have a number of syntax errors, and is also incomplete. SO expects: "Questions concerning problems with code you've written must describe the specific problem — and include valid code to reproduce it — in the question itself. See SSCCE.org for guidance. " You haven't provided a SSCCE.org code, and the snippets you've provided don't make sense. - Robert Crovella(numBins/512+1,1,1)(which is not valid, the compiler should at least have indicated a warning on that line), you can passdim3(numBins/512+1,1,1)(which is valid). However, that would end up launching 3 blocks, not 2, and since your kernel has no thread check, it would have other problems. Furthermore,printfmay not be a reliable mechanism for large amounts of kernel output. - Robert Crovellad_binHistogram- Nam Thai