Skip to content
Snippets Groups Projects
Commit 64e3c3be authored by Neil Gershenfeld's avatar Neil Gershenfeld
Browse files

CUDA error check

parent b08534ce
Branches
No related tags found
No related merge requests found
Pipeline #16404 passed
...@@ -28,16 +28,25 @@ void reduce(double *arr) { ...@@ -28,16 +28,25 @@ void reduce(double *arr) {
uint64_t len = npts >> 1; uint64_t len = npts >> 1;
while (1) { while (1) {
reduce_sum<<<blocks,threads>>>(arr,len); reduce_sum<<<blocks,threads>>>(arr,len);
cudaCheck("reduce");
len = len >> 1; len = len >> 1;
if (len == 0) if (len == 0)
return; return;
} }
} }
void cudaCheck(string msg) {
cudaError err;
err = cudaGetLastError();
if (cudaSuccess != err)
cerr << msg << ": " << cudaGetErrorString(err) << endl;
}
int main(void) { int main(void) {
double harr[1],*darr; double harr[1],*darr;
cudaMalloc(&darr,npts*sizeof(double)); cudaMalloc(&darr,npts*sizeof(double));
cudaCheck("cudaMalloc");
auto tstart = std::chrono::high_resolution_clock::now(); auto tstart = std::chrono::high_resolution_clock::now();
init<<<blocks,threads>>>(darr,nloop); init<<<blocks,threads>>>(darr,nloop);
cudaCheck("init");
reduce(darr); reduce(darr);
cudaDeviceSynchronize(); cudaDeviceSynchronize();
auto tend = std::chrono::high_resolution_clock::now(); auto tend = std::chrono::high_resolution_clock::now();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment