CUTLASS
CUDA Templates for Linear Algebra Subroutines and Solvers
tools/util/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 
30 #pragma once
31 
32 #include "device_dump.h"
33 
35 
36 /******************************************************************************
37  * Debug and logging macros
38  ******************************************************************************/
39 
43 #if !defined(CUDA_LOG)
44 #if !defined(__CUDA_ARCH__)
45 #define CUDA_LOG(format, ...) printf(format, __VA_ARGS__)
46 #else
47 #define CUDA_LOG(format, ...) \
48  printf("[block (%d,%d,%d), thread (%d,%d,%d)]: " format, \
49  blockIdx.x, \
50  blockIdx.y, \
51  blockIdx.z, \
52  threadIdx.x, \
53  threadIdx.y, \
54  threadIdx.z, \
55  __VA_ARGS__);
56 #endif
57 #endif
58 
62 #if !defined(CUDA_LOG_DEBUG)
63 #ifdef DEBUG
64 #define CUDA_LOG_DEBUG(format, ...) CUDA_LOG(format, __VA_ARGS__)
65 #else
66 #define CUDA_LOG_DEBUG(format, ...)
67 #endif
68 #endif
69 
76 __host__ CUTLASS_DEVICE cudaError_t cuda_perror_impl(cudaError_t error,
77  const char* filename,
78  int line) {
79  (void)filename;
80  (void)line;
81  if (error) {
82 #if !defined(__CUDA_ARCH__)
83  fprintf(
84  stderr, "CUDA error %d [%s, %d]: %s\n", error, filename, line, cudaGetErrorString(error));
85  fflush(stderr);
86 #else
87  printf("CUDA error %d [%s, %d]\n", error, filename, line);
88 #endif
89  }
90  return error;
91 }
92 
96 #ifndef CUDA_PERROR
97 #define CUDA_PERROR(e) cuda_perror_impl((cudaError_t)(e), __FILE__, __LINE__)
98 #endif
99 
103 #ifndef CUDA_PERROR_EXIT
104 #define CUDA_PERROR_EXIT(e) \
105  if (cuda_perror_impl((cudaError_t)(e), __FILE__, __LINE__)) { \
106  exit(1); \
107  }
108 #endif
109 
113 #ifndef CUDA_PERROR_DEBUG
114 #ifdef DEBUG
115 #define CUDA_PERROR_DEBUG(e) CUDA_PERROR(e)
116 #else
117 #define CUDA_PERROR_DEBUG(e) (e)
118 #endif
119 #endif
120 
122 
123 // A small helper class to dump a type at compile time
124 // Usage:: DumpType<Class>::Class
125 template <typename T>
126 struct DebugType {};
127 
128 template <typename T>
129 void DebugTypeFunc(T const& t) {
130  T::t;
131 }
132 
133 // A small helper class to dump a compile time constant at compile time
134 // Usage: DumpValue<Class::kConstant>::kConstant
135 template <int Value>
136 struct DebugValue {};
Definition: tools/util/include/cutlass/util/debug.h:136
C++ interface to dump fragments and shared memory contents for debugging.
Definition: tools/util/include/cutlass/util/debug.h:126
__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: tools/util/include/cutlass/util/debug.h:76
void DebugTypeFunc(T const &t)
Definition: tools/util/include/cutlass/util/debug.h:129