• <xmp id="om0om">
  • <table id="om0om"><noscript id="om0om"></noscript></table>
  • Compute Graph Framework SDK Reference  5.22
    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-2023 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 <dwshared/dwfoundation/dw/core/base/ExceptionWithStatus.hpp>
    35#include <dw/core/base/Status.h>
    36#include <dwshared/dwfoundation/dw/core/container/BaseString.hpp>
    37#include <dwshared/dwfoundation/dw/core/language/Function.hpp>
    38#include <dwshared/dwfoundation/dw/core/logger/Logger.hpp>
    39
    40#define THROW_ON_PARAM_NULL(param) \
    41 if (nullptr == param) \
    42 { \
    43 throw dw::core::ExceptionWithStatus(DW_INVALID_ARGUMENT, #param " == nullptr ", DW_FUNCTION_NAME, ":", __LINE__); \
    44 }
    45
    46#define GET_STRING(s) #s
    47
    48//------------------------------------------------------------------------------
    49// Macro to easily check for DW errors (non-DW_SUCCESS status) and throw exception. Exception message includes file name/line number, actual return code and user-provided description
    50#define FRWK_CHECK_DW_ERROR_MSG(x, description) \
    51 { \
    52 dwStatus FRWK_CHECK_DW_ERROR_result{x}; \
    53 if (DW_SUCCESS != FRWK_CHECK_DW_ERROR_result) \
    54 { \
    55 throw dw::core::ExceptionWithStatus(FRWK_CHECK_DW_ERROR_result, __FILE__, ":", __LINE__, " DriveWorks Error ", dwGetStatusName(FRWK_CHECK_DW_ERROR_result), ": ", description); \
    56 } \
    57 };
    58// Macro that includes the failing code line as default description. Use FRWK_CHECK_DW_ERROR_MSG to provide a customized, hand-written description.
    59#define FRWK_CHECK_DW_ERROR(x) FRWK_CHECK_DW_ERROR_MSG(x, GET_STRING(x));
    60
    61#define FRWK_CHECK_DW_ERROR_IGNORE_SOME(x, fallback, ...) \
    62 { \
    63 dwStatus FRWK_CHECK_DW_ERROR_IGNORE_SOME_result{x}; \
    64 if (DW_SUCCESS != FRWK_CHECK_DW_ERROR_IGNORE_SOME_result) \
    65 { \
    66 dwStatus ignoreErros[]{__VA_ARGS__}; \
    67 if (std::find(std::begin(ignoreErros), std::end(ignoreErros), FRWK_CHECK_DW_ERROR_IGNORE_SOME_result) != std::end(ignoreErros)) \
    68 { \
    69 DW_LOGD << __FILE__ << ":" << __LINE__ \
    70 << " Ignoring Error: " \
    71 << dwGetStatusName(FRWK_CHECK_DW_ERROR_IGNORE_SOME_result) << ". Falling back on calling " << GET_STRING(fallback) \
    72 << dw::core::Logger::State::endl; \
    73 FRWK_CHECK_DW_ERROR_IGNORE_SOME_result = fallback; \
    74 if (DW_SUCCESS != FRWK_CHECK_DW_ERROR_IGNORE_SOME_result) \
    75 { \
    76 throw dw::core::ExceptionWithStatus(FRWK_CHECK_DW_ERROR_IGNORE_SOME_result, "After ignoring errors from ignore list, fallback operation %s encountered DriveWorks error.", GET_STRING(fallback)); \
    77 } \
    78 } \
    79 } \
    80 if (DW_SUCCESS != FRWK_CHECK_DW_ERROR_IGNORE_SOME_result) \
    81 { \
    82 throw dw::core::ExceptionWithStatus(FRWK_CHECK_DW_ERROR_IGNORE_SOME_result, "DriveWorks error not in ignore list."); \
    83 } \
    84 };
    85
    86#define FRWK_CHECK_DW_ERROR_NOTHROW(x) \
    87 { \
    88 dwStatus FRWK_CHECK_DW_ERROR_NOTHROW_result{x}; \
    89 if (DW_SUCCESS != FRWK_CHECK_DW_ERROR_NOTHROW_result) \
    90 { \
    91 DW_LOGE << __FILE__ << ":" << __LINE__ \
    92 << " DriveWorks exception but not thrown: " \
    93 << dwGetStatusName(FRWK_CHECK_DW_ERROR_NOTHROW_result) \
    94 << dw::core::Logger::State::endl; \
    95 } \
    96 };
    97
    98#define FRWK_CHECK_DW_ERROR_NOTHROW_IGNORE_SOME(x, fallback, ...) \
    99 { \
    100 dwStatus FRWK_CHECK_DW_ERROR_NOTHROW_IGNORE_SOME_result{x}; \
    101 dwStatus ignoreErros[]{__VA_ARGS__}; \
    102 if (std::find(std::begin(ignoreErros), std::end(ignoreErros), FRWK_CHECK_DW_ERROR_NOTHROW_IGNORE_SOME_result) != std::end(ignoreErros)) \
    103 { \
    104 FRWK_CHECK_DW_ERROR_NOTHROW_IGNORE_SOME_result = fallback; \
    105 } \
    106 if (DW_SUCCESS != FRWK_CHECK_DW_ERROR_NOTHROW_IGNORE_SOME_result) \
    107 { \
    108 DW_LOGE << __FILE__ << ":" << __LINE__ \
    109 << " DriveWorks exception but not thrown: " \
    110 << dwGetStatusName(FRWK_CHECK_DW_ERROR_NOTHROW_IGNORE_SOME_result) \
    111 << dw::core::Logger::State::endl; \
    112 } \
    113 };
    114
    115//------------------------------------------------------------------------------
    116// macro to easily check for cuda errors
    117#define FRWK_CHECK_CUDA_ERROR(x) \
    118 { \
    119 x; \
    120 cudaError_t FRWK_CHECK_CUDA_ERROR_result{cudaGetLastError()}; \
    121 if (cudaSuccess != FRWK_CHECK_CUDA_ERROR_result) \
    122 { \
    123 throw dw::core::ExceptionWithStatus(DW_CUDA_ERROR, cudaGetErrorString(FRWK_CHECK_CUDA_ERROR_result)); \
    124 } \
    125 };
    126
    127#define FRWK_CHECK_CUDA_ERROR_NOTHROW(x) \
    128 { \
    129 x; \
    130 cudaError_t FRWK_CHECK_CUDA_ERROR_NOTHROW_result{cudaGetLastError()}; \
    131 if (cudaSuccess != FRWK_CHECK_CUDA_ERROR_NOTHROW_result) \
    132 { \
    133 DW_LOGE << __FILE__ << ":" << __LINE__ \
    134 << " CUDA error but not thrown: " \
    135 << cudaGetErrorString(FRWK_CHECK_CUDA_ERROR_NOTHROW_result) \
    136 << dw::core::Logger::State::endl; \
    137 } \
    138 };
    139
    140#define FRWK_CHECK_NVMEDIA_ERROR(e) \
    141 { \
    142 NvMediaStatus FRWK_CHECK_NVMEDIA_ERROR_ret{e}; \
    143 if (NVMEDIA_STATUS_OK != FRWK_CHECK_NVMEDIA_ERROR_ret) \
    144 { \
    145 throw dw::core::ExceptionWithStatus(DW_NVMEDIA_ERROR, "NvMedia error occured"); \
    146 } \
    147 }
    148
    149namespace dw
    150{
    151namespace framework
    152{
    153
    154// coverity[autosar_cpp14_a0_1_6_violation]
    156{
    157 ExceptionGuard() = delete;
    158
    159public:
    160 template <typename TryBlock>
    161 static dwStatus guardWithReturn(TryBlock const& tryBlock, ::dw::core::Logger::Verbosity verbosity = ::dw::core::Logger::Verbosity::ERROR)
    162 {
    163 return guardWithReturnFunction(tryBlock, verbosity);
    164 }
    165
    166 template <typename TryBlock>
    167 static dwStatus guard(TryBlock const& tryBlock, ::dw::core::Logger::Verbosity verbosity = ::dw::core::Logger::Verbosity::ERROR)
    168 {
    169 static_assert(std::is_same<void, typename std::result_of<TryBlock()>::type>::value,
    170 "tryBlock must return void");
    171 dw::core::Function<dwStatus()> tryBlockFunc{[&]() -> dwStatus {
    172 tryBlock();
    173 return DW_SUCCESS;
    174 }};
    175 return guardWithReturnFunction(tryBlockFunc, verbosity);
    176 }
    177
    178private:
    179 static dwStatus guardWithReturnFunction(dw::core::Function<dwStatus()> const& tryBlock, dw::core::Logger::Verbosity verbosity);
    180};
    181
    182} // namespace framework
    183} // namespace dw
    184
    185#endif // DW_FRAMEWORK_EXCEPTION_HPP_
    static dwStatus guardWithReturn(TryBlock const &tryBlock, ::dw::core::Logger::Verbosity verbosity=::dw::core::Logger::Verbosity::ERROR)
    Definition: Exception.hpp:161
    static dwStatus guard(TryBlock const &tryBlock, ::dw::core::Logger::Verbosity verbosity=::dw::core::Logger::Verbosity::ERROR)
    Definition: Exception.hpp:167
    Definition: Buffer.hpp:41
    人人超碰97caoporen国产