• <xmp id="om0om">
  • <table id="om0om"><noscript id="om0om"></noscript></table>
  • Compute Graph Framework SDK Reference  5.10
    All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
    Exception.hpp
    Go to the documentation of this file.
    1
    2//
    3// Notice
    4// ALL NVIDIA DESIGN SPECIFICATIONS AND CODE ("MATERIALS") ARE PROVIDED "AS IS" NVIDIA MAKES
    5// NO REPRESENTATIONS, WARRANTIES, EXPRESSED, IMPLIED, STATUTORY, OR OTHERWISE WITH RESPECT TO
    6// THE MATERIALS, AND EXPRESSLY DISCLAIMS ANY IMPLIED WARRANTIES OF NONINFRINGEMENT,
    7// MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
    8//
    9// NVIDIA CORPORATION & AFFILIATES assumes no responsibility for the consequences of use of such
    10// information or for any infringement of patents or other rights of third parties that may
    11// result from its use. No license is granted by implication or otherwise under any patent
    12// or patent rights of NVIDIA CORPORATION & AFFILIATES. No third party distribution is allowed unless
    13// expressly authorized by NVIDIA. Details are subject to change without notice.
    14// This code supersedes and replaces all information previously supplied.
    15// NVIDIA CORPORATION & AFFILIATES products are not authorized for use as critical
    16// components in life support devices or systems without express written approval of
    17// NVIDIA CORPORATION & AFFILIATES.
    18//
    19// SPDX-FileCopyrightText: Copyright (c) 2019-2022 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
    20// SPDX-License-Identifier: LicenseRef-NvidiaProprietary
    21//
    22// NVIDIA CORPORATION, its affiliates and licensors retain all intellectual
    23// property and proprietary rights in and to this material, related
    24// documentation and any modifications thereto. Any use, reproduction,
    25// disclosure or distribution of this material and related documentation
    26// without an express license agreement from NVIDIA CORPORATION or
    27// its affiliates is strictly prohibited.
    28//
    30
    31#ifndef DW_FRAMEWORK_EXCEPTION_HPP_
    32#define DW_FRAMEWORK_EXCEPTION_HPP_
    33
    34#include <dw/core/base/Exception.hpp>
    35#include <dw/core/base/Status.h>
    36#include <dw/core/container/BaseString.hpp>
    37#include <dw/core/logger/Logger.hpp>
    38
    39#define THROW_ON_PARAM_NULL(param) \
    40 if (param == nullptr) \
    41 { \
    42 throw dw::core::ExceptionWithStatus(DW_INVALID_ARGUMENT, #param " == nullptr ", DW_FUNCTION_NAME, ":", __LINE__); \
    43 }
    44
    45//------------------------------------------------------------------------------
    46// macro to easily check for dw errors
    47#define FRWK_CHECK_DW_ERROR(x) \
    48 { \
    49 dwStatus result{}; \
    50 result = (x); \
    51 if (result != DW_SUCCESS) \
    52 { \
    53 throw dw::core::ExceptionWithStatus(result, __FILE__, ":", __LINE__, " - DriveWorks Error"); \
    54 } \
    55 };
    56#define GET_STRING(s) #s
    57#define FRWK_CHECK_DW_ERROR_IGNORE_SOME(x, fallback, ...) \
    58 { \
    59 dwStatus result = x; \
    60 dwStatus ignoreErros[] = {__VA_ARGS__}; \
    61 if (result != DW_SUCCESS) \
    62 { \
    63 if (std::find(std::begin(ignoreErros), std::end(ignoreErros), result) != std::end(ignoreErros)) \
    64 { \
    65 DW_LOGD << __FILE__ \
    66 << "(" << __LINE__ << ") " \
    67 << "Ignoring Error: " \
    68 << dwGetStatusName(result) << ". Falling back on calling " << GET_STRING(fallback) \
    69 << dw::core::Logger::State::endl; \
    70 result = fallback; \
    71 if (result != DW_SUCCESS) \
    72 { \
    73 throw dw::core::ExceptionWithStatus(result, "After ignoring errors from ignore list, fallback operation %s encountered DriveWorks error.", GET_STRING(fallback)); \
    74 } \
    75 } \
    76 } \
    77 if (result != DW_SUCCESS) \
    78 { \
    79 throw dw::core::ExceptionWithStatus(result, "DriveWorks error not in ignore list."); \
    80 } \
    81 };
    82
    83#define FRWK_CHECK_DW_ERROR_NOTHROW(x) \
    84 { \
    85 dwStatus result = x; \
    86 if (result != DW_SUCCESS) \
    87 { \
    88 DW_LOGE << __FILE__ \
    89 << "(" << __LINE__ << ") " \
    90 << "DriveWorks exception but not thrown: " \
    91 << dwGetStatusName(result) \
    92 << dw::core::Logger::State::endl; \
    93 } \
    94 };
    95
    96#define FRWK_CHECK_DW_ERROR_NOTHROW_IGNORE_SOME(x, fallback, ...) \
    97 { \
    98 dwStatus result = x; \
    99 dwStatus ignoreErros[] = {__VA_ARGS__}; \
    100 if (std::find(std::begin(ignoreErros), std::end(ignoreErros), result) != std::end(ignoreErros)) \
    101 { \
    102 result = fallback; \
    103 } \
    104 if (result != DW_SUCCESS) \
    105 { \
    106 DW_LOGE << __FILE__ \
    107 << "(" << __LINE__ << ") " \
    108 << "DriveWorks exception but not thrown: " \
    109 << dwGetStatusName(result) \
    110 << dw::core::Logger::State::endl; \
    111 } \
    112 };
    113
    114#define FRWK_CHECK_DW_ERROR_MSG(x, description) \
    115 { \
    116 dwStatus result{}; \
    117 result = (x); \
    118 if (result != DW_SUCCESS) \
    119 { \
    120 throw dw::core::ExceptionWithStatus(result, (description)); \
    121 } \
    122 };
    123
    124//------------------------------------------------------------------------------
    125// macro to easily check for cuda errors
    126#define FRWK_CHECK_CUDA_ERROR(x) \
    127 { \
    128 x; \
    129 auto result = cudaGetLastError(); \
    130 if (result != cudaSuccess) \
    131 { \
    132 throw dw::core::ExceptionWithStatus(DW_CUDA_ERROR, cudaGetErrorString(result)); \
    133 } \
    134 };
    135
    136#define FRWK_CHECK_CUDA_ERROR_NOTHROW(x) \
    137 { \
    138 x; \
    139 auto result = cudaGetLastError(); \
    140 if (result != cudaSuccess) \
    141 { \
    142 DW_LOGE << __FILE__ \
    143 << "(" << __LINE__ << ") " \
    144 << "CUDA error but not thrown: " \
    145 << cudaGetErrorString(result) \
    146 << dw::core::Logger::State::endl; \
    147 } \
    148 };
    149
    150#define FRWK_CHECK_NVMEDIA_ERROR(e) \
    151 { \
    152 auto FRWK_CHECK_NVMEDIA_ERROR_ret = (e); \
    153 if (FRWK_CHECK_NVMEDIA_ERROR_ret != NVMEDIA_STATUS_OK) \
    154 { \
    155 throw dw::core::ExceptionWithStatus(DW_NVMEDIA_ERROR, "NvMedia error occured"); \
    156 } \
    157 }
    158
    159#endif // DW_FRAMEWORK_TYPES_HPP_
    人人超碰97caoporen国产