// ------------------------------------------------------------------ // definition of a macro instruction that checks if a CUDA function // was successull or not. If the execution of the function resulted // in some error we display it and stop the program // ------------------------------------------------------------------ #define cume_check(value) { \ cudaError_t err = value; \ if (err != cudaSuccess) { \ cerr << endl; \ cerr << "============================================\n"; \ cerr << "Error: " << cudaGetErrorString(err) << " at line "; \ cerr << __LINE__ << " in file " << __FILE__; \ cerr << endl; \ exit(EXIT_FAILURE); \ } \ } // ------------------------------------------------------------------ // Same as cuda_check but for kernel. This macro instruction is used // after the execution of the kernel (see the macros KERNEL_EXECUTE_NR // and KERNEL_EXECUTE_WR in cume_kernel.h) // ------------------------------------------------------------------ #define cume_check_kernel() { \ cudaError_t err = cudaGetLastError(); \ if (err != cudaSuccess) { \ cerr << endl; \ cerr << "============================================\n"; \ cerr << "Kernel Error: " << cudaGetErrorString(err) << " at line "; \ cerr << __LINE__ << " in file " << __FILE__; \ cerr << endl; \ exit(EXIT_FAILURE); \ } \ } // check that cudaMalloc was executed successfully cume_check( cudaMalloc((void**) &x_gpu, SIZE * sizeof(float)) ); // check that kernel was executed successfully sum<<< grid, block >>>(x_gpu, y_gpu, z_gpu, SIZE); cume_check_kernel();