e41a52bb
Hu Chunming
1.优化数据读取线程;2. 添加A...
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
|
/**
* Copyright 1993-2015 NVIDIA Corporation. All rights reserved.
*
* Please refer to the NVIDIA end user license agreement (EULA) associated
* with this source code for terms and conditions that govern your use of
* this software. Any use, reproduction, disclosure, or distribution of
* this software and related documentation outside the terms of the EULA
* is strictly prohibited.
*
*/
#ifndef NV_UTIL_NPP_EXCEPTIONS_H
#define NV_UTIL_NPP_EXCEPTIONS_H
#include <string>
#include <sstream>
#include <iostream>
/// All npp related C++ classes are put into the npp namespace.
namespace npp
{
/// Exception base class.
/// This exception base class will be used for everything C++ throught
/// the NPP project.
/// The exception contains a string message, as well as data fields for a string
/// containing the name of the file as well as the line number where the exception was thrown.
/// The easiest way of throwing exceptions and providing filename and line number is
/// to use one of the ASSERT macros defined for that purpose.
class Exception
{
public:
/// Constructor.
/// \param rMessage A message with information as to why the exception was thrown.
/// \param rFileName The name of the file where the exception was thrown.
/// \param nLineNumber Line number in the file where the exception was thrown.
explicit
Exception(const std::string &rMessage = "", const std::string &rFileName = "", unsigned int nLineNumber = 0)
: sMessage_(rMessage), sFileName_(rFileName), nLineNumber_(nLineNumber)
{ };
Exception(const Exception &rException)
: sMessage_(rException.sMessage_), sFileName_(rException.sFileName_), nLineNumber_(rException.nLineNumber_)
{ };
virtual
~Exception()
{ };
/// Get the exception's message.
const
std::string &
message()
const
{
return sMessage_;
}
/// Get the exception's file info.
const
std::string &
fileName()
const
{
return sFileName_;
}
/// Get the exceptions's line info.
unsigned int
lineNumber()
const
{
return nLineNumber_;
}
/// Create a clone of this exception.
/// This creates a new Exception object on the heap. It is
/// the responsibility of the user of this function to free this memory
/// (delete x).
virtual
Exception *
clone()
const
{
return new Exception(*this);
}
/// Create a single string with all the exceptions information.
/// The virtual toString() method is used by the operator<<()
/// so that all exceptions derived from this base-class can print
/// their full information correctly even if a reference to their
/// exact type is not had at the time of printing (i.e. the basic
/// operator<<() is used).
virtual
std::string
toString()
const
{
std::ostringstream oOutputString;
oOutputString << fileName() << ":" << lineNumber() << ": " << message();
return oOutputString.str();
}
private:
std::string sMessage_; ///< Message regarding the cause of the exception.
std::string sFileName_; ///< Name of the file where the exception was thrown.
unsigned int nLineNumber_; ///< Line number in the file where the exception was thrown
};
/// Output stream inserter for Exception.
/// \param rOutputStream The stream the exception information is written to.
/// \param rException The exception that's being written.
/// \return Reference to the output stream being used.
std::ostream &
operator << (std::ostream &rOutputStream, const Exception &rException)
{
rOutputStream << rException.toString();
return rOutputStream;
}
/// Basic assert macro.
/// This macro should be used to enforce any kind of pre or post conditions.
/// Unlike the C-runtime assert macro, this macro does not abort execution, but throws
/// a C++ exception. The exception is automatically filled with information about the failing
/// condition, the filename and line number where the exception was thrown.
/// \note The macro is written in such a way that omitting a semicolon after its usage
/// causes a compiler error. The correct way to invoke this macro is:
/// NPP_ASSERT(n < MAX);
#define NPP_ASSERT(C) do {if (!(C)) throw npp::Exception(#C " assertion faild!", __FILE__, __LINE__);} while(false)
// ASSERT macro.
// Same functionality as the basic assert macro with the added ability to pass
// a message M. M should be a string literal.
// Note: Never use code inside ASSERT() that causes a side-effect ASSERT macros may get compiled
// out in release mode.
#define NPP_ASSERT_MSG(C, M) do {if (!(C)) throw npp::Exception(#C " assertion faild! Message: " M, __FILE__, __LINE__);} while(false)
#ifdef _DEBUG
/// Basic debug assert macro.
/// This macro is identical in every respect to NPP_ASSERT(C) but it does get compiled to a
/// no-op in release builds. It is therefor of utmost importance to not put statements into
/// this macro that cause side effects required for correct program execution.
#define NPP_DEBUG_ASSERT(C) do {if (!(C)) throw npp::Exception(#C " debug assertion faild!", __FILE__, __LINE__);} while(false)
#else
#define NPP_DEBUG_ASSERT(C)
#endif
/// ASSERT for null-pointer test.
/// It is safe to put code with side effects into this macro. Also: This macro never
/// gets compiled to a no-op because resource allocation may fail based on external causes not under
/// control of a software developer.
#define NPP_ASSERT_NOT_NULL(P) do {if ((P) == 0) throw npp::Exception(#P " not null assertion faild!", __FILE__, __LINE__);} while(false)
/// Macro for flagging methods as not implemented.
/// The macro throws an exception with a message that an implementation was missing
#define NPP_NOT_IMPLEMENTED() do {throw npp::Exception("Implementation missing!", __FILE__, __LINE__);} while(false)
/// Macro for checking error return code of CUDA (runtime) calls.
/// This macro never gets disabled.
#define NPP_CHECK_CUDA(S) do {cudaError_t eCUDAResult; \
eCUDAResult = S; \
if (eCUDAResult != cudaSuccess) std::cout << "NPP_CHECK_CUDA - eCUDAResult = " << eCUDAResult << std::endl; \
NPP_ASSERT(eCUDAResult == cudaSuccess);} while (false)
/// Macro for checking error return code for NPP calls.
#define NPP_CHECK_NPP(S) do {NppStatus eStatusNPP; \
eStatusNPP = S; \
if (eStatusNPP != NPP_SUCCESS) std::cout << "NPP_CHECK_NPP - eStatusNPP = " << _cudaGetErrorEnum(eStatusNPP) << "("<< eStatusNPP << ")" << std::endl; \
NPP_ASSERT(eStatusNPP == NPP_SUCCESS);} while (false)
/// Macro for checking error return codes from cuFFT calls.
#define NPP_CHECK_CUFFT(S) do {cufftResult eCUFFTResult; \
eCUFFTResult = S; \
if (eCUFFTResult != NPP_SUCCESS) std::cout << "NPP_CHECK_CUFFT - eCUFFTResult = " << eCUFFTResult << std::endl; \
NPP_ASSERT(eCUFFTResult == CUFFT_SUCCESS);} while (false)
} // npp namespace
#endif // NV_UTIL_NPP_EXCEPTIONS_H
|