25 #include <type_traits> 29 #include <android/log.h> 34 #define FASTDEPLOY_DECL __declspec(dllexport) 36 #define FASTDEPLOY_DECL __declspec(dllimport) 37 #endif // FASTDEPLOY_LIB 39 #define FASTDEPLOY_DECL __attribute__((visibility("default"))) 44 class FASTDEPLOY_DECL FDLogger {
46 static bool enable_info;
47 static bool enable_warning;
51 prefix_ =
"[FastDeploy]";
54 explicit FDLogger(
bool verbose,
const std::string& prefix =
"[FastDeploy]");
56 template <
typename T> FDLogger& operator<<(
const T& val) {
66 FDLogger& operator<<(std::ostream& (*os)(std::ostream&));
69 if (verbose_ && line_ !=
"") {
70 std::cout << line_ << std::endl;
72 __android_log_print(ANDROID_LOG_INFO, prefix_.c_str(),
"%s",
84 FASTDEPLOY_DECL
bool ReadBinaryFromFile(
const std::string& file,
85 std::string* contents);
88 #define __REL_FILE__ __FILE__ 92 FDLogger(true, "[ERROR]") \ 93 << __REL_FILE__ << "(" << __LINE__ << ")::" << __FUNCTION__ << "\t" 96 FDLogger(fastdeploy::FDLogger::enable_warning, "[WARNING]") \ 97 << __REL_FILE__ << "(" << __LINE__ << ")::" << __FUNCTION__ << "\t" 100 FDLogger(fastdeploy::FDLogger::enable_info, "[INFO]") \ 101 << __REL_FILE__ << "(" << __LINE__ \ 102 << ")::" << __FUNCTION__ << "\t" 104 #define FDASSERT(condition, format, ...) \ 105 if (!(condition)) { \ 106 int n = std::snprintf(nullptr, 0, format, ##__VA_ARGS__); \ 107 std::vector<char> buffer(n + 1); \ 108 std::snprintf(buffer.data(), n + 1, format, ##__VA_ARGS__); \ 109 FDERROR << buffer.data() << std::endl; \ 115 #define FD_PRIVATE_CASE_TYPE_USING_HINT(NAME, enum_type, type, HINT, ...) \ 122 #define FD_PRIVATE_CASE_TYPE(NAME, enum_type, type, ...) \ 123 FD_PRIVATE_CASE_TYPE_USING_HINT(NAME, enum_type, type, data_t, __VA_ARGS__) 126 #define FD_VISIT_ALL_TYPES(TYPE, NAME, ...) \ 128 const auto& __dtype__ = TYPE; \ 129 switch (__dtype__) { \ 130 FD_PRIVATE_CASE_TYPE(NAME, ::fastdeploy::FDDataType::UINT8, uint8_t, \ 132 FD_PRIVATE_CASE_TYPE(NAME, ::fastdeploy::FDDataType::BOOL, bool, \ 134 FD_PRIVATE_CASE_TYPE(NAME, ::fastdeploy::FDDataType::INT32, int32_t, \ 136 FD_PRIVATE_CASE_TYPE(NAME, ::fastdeploy::FDDataType::INT64, int64_t, \ 138 FD_PRIVATE_CASE_TYPE(NAME, ::fastdeploy::FDDataType::FP32, float, \ 140 FD_PRIVATE_CASE_TYPE(NAME, ::fastdeploy::FDDataType::FP64, double, \ 144 "Invalid enum data type. Expect to accept data " \ 145 "type BOOL, INT32, " \ 146 "INT64, FP32, FP64, but receive type %s.", \ 147 Str(__dtype__).c_str()); \ 151 #define FD_VISIT_INT_FLOAT_TYPES(TYPE, NAME, ...) \ 153 const auto& __dtype__ = TYPE; \ 154 switch (__dtype__) { \ 155 FD_PRIVATE_CASE_TYPE(NAME, ::fastdeploy::FDDataType::INT32, int32_t, \ 157 FD_PRIVATE_CASE_TYPE(NAME, ::fastdeploy::FDDataType::INT64, int64_t, \ 159 FD_PRIVATE_CASE_TYPE(NAME, ::fastdeploy::FDDataType::FP32, float, \ 161 FD_PRIVATE_CASE_TYPE(NAME, ::fastdeploy::FDDataType::FP64, double, \ 163 FD_PRIVATE_CASE_TYPE(NAME, ::fastdeploy::FDDataType::UINT8, uint8_t, \ 167 "Invalid enum data type. Expect to accept data type INT32, " \ 168 "INT64, FP32, FP64, UINT8 but receive type %s.", \ 169 Str(__dtype__).c_str()); \ 173 #define FD_VISIT_FLOAT_TYPES(TYPE, NAME, ...) \ 175 const auto& __dtype__ = TYPE; \ 176 switch (__dtype__) { \ 177 FD_PRIVATE_CASE_TYPE(NAME, ::fastdeploy::FDDataType::FP32, float, \ 179 FD_PRIVATE_CASE_TYPE(NAME, ::fastdeploy::FDDataType::FP64, double, \ 183 "Invalid enum data type. Expect to accept data type FP32, " \ 184 "FP64, but receive type %s.", \ 185 Str(__dtype__).c_str()); \ 189 #define FD_VISIT_INT_TYPES(TYPE, NAME, ...) \ 191 const auto& __dtype__ = TYPE; \ 192 switch (__dtype__) { \ 193 FD_PRIVATE_CASE_TYPE(NAME, ::fastdeploy::FDDataType::INT32, int32_t, \ 195 FD_PRIVATE_CASE_TYPE(NAME, ::fastdeploy::FDDataType::INT64, int64_t, \ 197 FD_PRIVATE_CASE_TYPE(NAME, ::fastdeploy::FDDataType::UINT8, uint8_t, \ 201 "Invalid enum data type. Expect to accept data type INT32, " \ 202 "INT64, UINT8 but receive type %s.", \ 203 Str(__dtype__).c_str()); \ 207 FASTDEPLOY_DECL std::vector<int64_t>
208 GetStride(
const std::vector<int64_t>& dims);
210 template <
typename T>
211 std::string Str(
const std::vector<T>& shape) {
212 std::ostringstream oss;
213 oss <<
"[ " << shape[0];
214 for (
size_t i = 1; i < shape.size(); ++i) {
215 oss <<
" ," << shape[i];
222 FASTDEPLOY_DECL
void SetLogger(
bool enable_info =
true,
223 bool enable_warning =
true);
225 template <
typename T>
226 void CalculateStatisInfo(
const void* src_ptr,
int size,
double* mean,
227 double* max,
double* min) {
228 const T* ptr =
static_cast<const T*
>(src_ptr);
229 *mean =
static_cast<double>(0);
230 *max =
static_cast<double>(-99999999);
231 *min =
static_cast<double>(99999999);
232 for (
int i = 0; i < size; ++i) {
233 if (*(ptr + i) > *max) {
236 if (*(ptr + i) < *min) {
241 *mean = *mean / size;
void SetLogger(bool enable_info, bool enable_warning)
Set behaviour of logging while using FastDeploy.
Definition: utils.cc:24
All C++ FastDeploy APIs are defined inside this namespace.
Definition: option.h:16