tutility.cu - cuda-memscrub - scrubs the global device memory of CUDA GPUs
 (HTM) git clone git://src.adamsgaard.dk/cuda-memscrub
 (DIR) Log
 (DIR) Files
 (DIR) Refs
 (DIR) README
 (DIR) LICENSE
       ---
       tutility.cu (1249B)
       ---
            1 #include <stdio.h>
            2 
            3 // MISC. UTILITY FUNCTIONS
            4 
            5 // Error handler for CUDA GPU calls. 
            6 //   Returns error number, filename and line number containing the error to the terminal.
            7 //   Please refer to CUDA_Toolkit_Reference_Manual.pdf, section 4.23.3.3 enum cudaError
            8 //   for error discription. Error enumeration starts from 0.
            9 void checkForCudaErrors(const char* checkpoint_description)
           10 {
           11     cudaError_t err = cudaGetLastError();
           12     if (err != cudaSuccess) {
           13         fprintf(stderr, "CUDA error detected at: %s\n"
           14                 "System error string: %s\n", checkpoint_description,
           15                 cudaGetErrorString(err));
           16         exit(EXIT_FAILURE);
           17     }
           18 }
           19 
           20 void checkForCudaErrors(const char* checkpoint_description, int iteration)
           21 {
           22     cudaError_t err = cudaGetLastError();
           23     if (err != cudaSuccess) {
           24         fprintf(stderr, "CUDA error detected at: %s at iteration %d.\n"
           25                 "System error string: %s\n", checkpoint_description, iteration,
           26                 cudaGetErrorString(err));
           27         exit(EXIT_FAILURE);
           28     }
           29 }
           30 
           31 //Round a / b to nearest higher integer value
           32 unsigned int iDivUp(unsigned int a, unsigned int b)
           33 {
           34     return (a % b != 0) ? (a / b + 1) : (a / b);
           35 }
           36 
           37 // vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4