我正在使用CUDA
cudppScan
來計算元素數組的前綴和。 當輸入數據量很小時,情況會好一些。 但是當數據大小大於700,000時,輸出的某些元素會變成錯誤的值。當輸入數據大小大於700,000時,cudppscan會給出錯誤的輸出
我在做一個所有的數組的cudppScan
,所以輸出應該是1, 2, 3, 4, ...
。
這裏是我的代碼:
void
runTest(int argc, char** argv)
{
// use command-line specified CUDA device, otherwise use device with highest Gflops/s
if(cutCheckCmdLineFlag(argc, (const char**)argv, "device"))
cutilDeviceInit(argc, argv);
else
cudaSetDevice(cutGetMaxGflopsDeviceId());
int num_elements = 670000;
int *h_isCommon;
int *d_isCommon;
int *d_scan_odata;
h_isCommon = (int *) malloc(sizeof(int) * num_elements);
CUDA_SAFE_CALL(cudaMalloc((void**)&d_isCommon, sizeof(int) * num_elements));
CUDA_SAFE_CALL(cudaMalloc((void**)&d_scan_odata, sizeof(int) * num_elements));
for(int i = 0; i < num_elements; i++) h_isCommon[i] = 1;
CUDA_SAFE_CALL(cudaMemcpy(d_isCommon, h_isCommon, sizeof(int) * num_elements,
cudaMemcpyHostToDevice));
CUDPPConfiguration config;
CUDPPHandle scanplan;
config.op = CUDPP_ADD;
config.datatype = CUDPP_INT;
config.algorithm = CUDPP_SCAN;
config.options = CUDPP_OPTION_FORWARD | CUDPP_OPTION_INCLUSIVE;
scanplan = 0;
CUDPPResult result_cudpp = cudppPlan(&scanplan, config, 4000000, 1, 0);
cudppScan(scanplan, d_scan_odata, d_isCommon, num_elements);
CUDA_SAFE_CALL(cudaThreadSynchronize());
CUDA_SAFE_CALL(cudaMemcpy(
h_isCommon,
d_scan_odata,
sizeof(int) * num_elements,
cudaMemcpyDeviceToHost));
for(int i = 1; i < num_elements; i++) {
if(h_isCommon[i] != h_isCommon[i - 1] + 1)
printf("error %d, %d\n", h_isCommon[i], h_isCommon[i - 1]);
//if(i != 0 && i % 10 == 0) printf("\n");
//printf("%8d", h_isCommon[i]);
}
printf("\n");
CUDA_SAFE_CALL(cudaFree(d_isCommon));
CUDA_SAFE_CALL(cudaFree(d_scan_odata));
free(h_isCommon);
cudaThreadExit();
}
所以,請大家幫幫忙指出,我做錯了。 在此先感謝。
此外,我使用的'cudppScan'原型與[that]有點不同(http://www.gpgpu.org/static/developer/cudpp/rel /rel_gems3/html/group__public_interface.html#gb72e7559d9e22c00ea6412d92b0efe11)在官方網站上發佈。 – user435644