CUTLASS
CUDA Templates for Linear Algebra Subroutines and Solvers
include/cutlass/util/debug.h
Go to the documentation of this file.
1 /***************************************************************************************************
2  * Copyright (c) 2017-2019, NVIDIA CORPORATION. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without modification, are permitted
5  * provided that the following conditions are met:
6  * * Redistributions of source code must retain the above copyright notice, this list of
7  * conditions and the following disclaimer.
8  * * Redistributions in binary form must reproduce the above copyright notice, this list of
9  * conditions and the following disclaimer in the documentation and/or other materials
10  * provided with the distribution.
11  * * Neither the name of the NVIDIA CORPORATION nor the names of its contributors may be used
12  * to endorse or promote products derived from this software without specific prior written
13  * permission.
14  *
15  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
16  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
17  * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL NVIDIA CORPORATION BE LIABLE
18  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
19  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
20  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
21  * STRICT LIABILITY, OR TOR (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
22  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23  *
24  **************************************************************************************************/
25 
26 #pragma once
27 
33 #include <stdio.h>
34 
35 namespace cutlass {
36 
37 /******************************************************************************
38  * Debug and logging macros
39  ******************************************************************************/
40 
44 #if !defined(CUDA_LOG)
45 #if !defined(__CUDA_ARCH__)
46 #define CUDA_LOG(format, ...) printf(format, __VA_ARGS__)
47 #else
48 #define CUDA_LOG(format, ...) \
49  printf("[block (%d,%d,%d), thread (%d,%d,%d)]: " format, \
50  blockIdx.x, \
51  blockIdx.y, \
52  blockIdx.z, \
53  threadIdx.x, \
54  threadIdx.y, \
55  threadIdx.z, \
56  __VA_ARGS__);
57 #endif
58 #endif
59 
63 #if !defined(CUDA_LOG_DEBUG)
64 #ifdef DEBUG
65 #define CUDA_LOG_DEBUG(format, ...) CUDA_LOG(format, __VA_ARGS__)
66 #else
67 #define CUDA_LOG_DEBUG(format, ...)
68 #endif
69 #endif
70 
77 __host__ CUTLASS_DEVICE cudaError_t cuda_perror_impl(cudaError_t error,
78  const char* filename,
79  int line) {
80  (void)filename;
81  (void)line;
82  if (error) {
83 #if !defined(__CUDA_ARCH__)
84  fprintf(
85  stderr, "CUDA error %d [%s, %d]: %s\n", error, filename, line, cudaGetErrorString(error));
86  fflush(stderr);
87 #else
88  printf("CUDA error %d [%s, %d]\n", error, filename, line);
89 #endif
90  }
91  return error;
92 }
93 
97 #ifndef CUDA_PERROR
98 #define CUDA_PERROR(e) cuda_perror_impl((cudaError_t)(e), __FILE__, __LINE__)
99 #endif
100 
104 #ifndef CUDA_PERROR_EXIT
105 #define CUDA_PERROR_EXIT(e) \
106  if (cuda_perror_impl((cudaError_t)(e), __FILE__, __LINE__)) { \
107  exit(1); \
108  }
109 #endif
110 
114 #ifndef CUDA_PERROR_DEBUG
115 #ifdef DEBUG
116 #define CUDA_PERROR_DEBUG(e) CUDA_PERROR(e)
117 #else
118 #define CUDA_PERROR_DEBUG(e) (e)
119 #endif
120 #endif
121 
122 } // namespace cutlass
Definition: aligned_buffer.h:35
__host__ CUTLASS_DEVICE cudaError_t cuda_perror_impl(cudaError_t error, const char *filename, int line)
The corresponding error message is printed to stderr (or stdout in device code) along with the suppli...
Definition: include/cutlass/util/debug.h:77