NVIDIA DeepStream SDK API Reference

8.0 Release
check.hpp
Go to the documentation of this file.
1 /*
2  * SPDX-FileCopyrightText: Copyright (c) 2022-2024 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
3  * SPDX-License-Identifier: LicenseRef-NvidiaProprietary
4  *
5  * NVIDIA CORPORATION, its affiliates and licensors retain all intellectual
6  * property and proprietary rights in and to this material, related
7  * documentation and any modifications thereto. Any use, reproduction,
8  * disclosure or distribution of this material and related documentation
9  * without an express license agreement from NVIDIA CORPORATION or
10  * its affiliates is strictly prohibited.
11  */
12 
13 #ifndef DS3D_COMMON_HELPER_CHECK_HPP
14 #define DS3D_COMMON_HELPER_CHECK_HPP
15 
16 #include <assert.h>
17 #include <cuda_runtime.h>
18 #include <stdarg.h>
19 #include <stdio.h>
20 
21 #include <string>
22 
23 namespace ds3d {
24 
25 #define DS3D_NVUNUSED2(a, b) \
26  { \
27  (void)(a); \
28  (void)(b); \
29  }
30 #define DS3D_NVUNUSED(a) \
31  { (void)(a); }
32 
33 #ifndef DS3D_INFER_ASSERT
34 #define DS3D_INFER_ASSERT(expr) \
35  do { \
36  if (!(expr)) { \
37  fprintf(stderr, "%s:%d ASSERT(%s) \n", __FILE__, __LINE__, #expr); \
38  std::abort(); \
39  } \
40  } while (0)
41 #endif
42 
43 #define checkRuntime(call) ds3d::check_runtime(call, #call, __LINE__, __FILE__)
44 
45 #define checkKernel(...) \
46  do { \
47  __VA_ARGS__; \
48  ds3d::check_runtime(cudaPeekAtLastError(), #__VA_ARGS__, __LINE__, __FILE__); \
49  } while (false)
50 #define dprintf(...)
51 
52 #define checkCudaErrors(cudaErrorCode) \
53  { \
54  cudaError_t status = cudaErrorCode; \
55  if (status != 0) { \
56  std::cout << "Cuda failure: " << cudaGetErrorString(status) << " at line " << __LINE__ \
57  << " in file " << __FILE__ << " error status: " << status << std::endl; \
58  abort(); \
59  } \
60  }
61 
62 #define Assertf(cond, fmt, ...) \
63  do { \
64  if (!(cond)) { \
65  fprintf(stderr, "Assert failed 💀. %s in file %s:%d, message: " fmt "\n", #cond, __FILE__, __LINE__, __VA_ARGS__); \
66  abort(); \
67  } \
68  } while (false)
69 
70 #define Asserts(cond, s) \
71  do { \
72  if (!(cond)) { \
73  fprintf(stderr, "Assert failed 💀. %s in file %s:%d, message: " s "\n", #cond, __FILE__, __LINE__); \
74  abort(); \
75  } \
76  } while (false)
77 
78 #define Assert(cond) \
79  do { \
80  if (!(cond)) { \
81  fprintf(stderr, "Assert failed 💀. %s in file %s:%d\n", #cond, __FILE__, __LINE__); \
82  abort(); \
83  } \
84  } while (false)
85 
86 static inline bool check_runtime(cudaError_t e, const char *call, int line, const char *file) {
87  if (e != cudaSuccess) {
88  fprintf(stderr,
89  "CUDA Runtime error %s # %s, code = %s [ %d ] in file "
90  "%s:%d\n",
91  call, cudaGetErrorString(e), cudaGetErrorName(e), e, file, line);
92  abort();
93  return false;
94  }
95  return true;
96 }
97 
98 }; // namespace ds3d
99 
100 #endif // DS3D_COMMON_HELPER_CHECK_HPP
ds3d::check_runtime
static bool check_runtime(cudaError_t e, const char *call, int line, const char *file)
Definition: check.hpp:86
ds3d
Definition: abi_dataprocess.h:21