1 /* 2 * Copyright 2016 Google Inc. 3 * 4 * Use of this source code is governed by a BSD-style license that can be 5 * found in the LICENSE file. 6 * 7 */ 8 9 #include <stdlib.h> 10 #include <stdio.h> 11 12 // 13 // 14 // 15 16 #include <cuda_runtime_api.h> 17 18 // 19 // 20 // 21 22 #include "assert_cuda.h" 23 24 // 25 // 26 // 27 28 cudaError_t 29 assert_cuda(cudaError_t const code, 30 char const * const file, 31 int const line, 32 bool const abort) 33 { 34 if (code != cudaSuccess) 35 { 36 const char* const cuda_err_str = cudaGetErrorString(code); 37 38 fprintf(stderr, 39 "\"%s\", line %d: assert_cuda ( %d ) = \"%s\"", 40 file,line,code,cuda_err_str); 41 42 if (abort) 43 { 44 cudaDeviceReset(); 45 exit(code); 46 } 47 } 48 49 return code; 50 } 51 52 // 53 // 54 // 55