09c2d08c
Hu Chunming
arm交付版
|
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
|
#ifndef _UTILS_H_
#define _UTILS_H_
#include <iostream>
#include <fstream>
#include <vector>
#include "acl/acl.h"
#include "stream_data.h"
#include "sy_common.h"
// #include "opencv2/opencv.hpp"
// #include "opencv2/imgcodecs/legacy/constants_c.h"
// #include "opencv2/imgproc/types_c.h"
using namespace std;
#define INFO_LOG(fmt, args...) fprintf(stdout, "[INFO] " fmt "\n", ##args)
#define WARN_LOG(fmt, args...) fprintf(stdout, "[WARN] " fmt "\n", ##args)
#define ERROR_LOG(fmt, args...) fprintf(stdout, "[ERROR] " fmt "\n", ##args)
#define RGBU8_IMAGE_SIZE(width, height) ((width) * (height) * 3)
#define YUV420SP_SIZE(width, height) ((width) * (height) * 3 / 2)
#define ALIGN_UP(num, align) (((num) + (align) - 1) & ~((align) - 1))
#define ALIGN_UP2(num) ALIGN_UP(num, 2)
#define ALIGN_UP16(num) ALIGN_UP(num, 16)
#define ALIGN_UP64(num) ALIGN_UP(num, 64) //230316added
#define ALIGN_UP128(num) ALIGN_UP(num, 128)
#define SHARED_PRT_DVPP_BUF(buf) (shared_ptr<uint8_t>((uint8_t *)(buf), [](uint8_t* p) { acldvppFree(p); }))
#define SHARED_PRT_U8_BUF(buf) (shared_ptr<uint8_t>((uint8_t *)(buf), [](uint8_t* p) { delete[](p); }))
#define ACL_CALL(ret, expect, errCode)\
do {\
if (ret != expect) {\
if (errCode == 0)\
return ret;\
else\
return errCode;\
}\
} while(0)
template<class Type>
std::shared_ptr<Type> MakeSharedNoThrow() {
try {
return std::make_shared<Type>();
}
catch (...) {
return nullptr;
}
}
#define MAKE_SHARED_NO_THROW(memory, memory_type) \
do { \
memory = MakeSharedNoThrow<memory_type>(); \
}while(0);
struct Resolution {
uint32_t width = 0;
uint32_t height = 0;
};
/**
* Utils
*/
class Utils {
public:
static aclrtRunMode runMode_;
static void* CopyDataToDevice(void* data, uint32_t dataSize, aclrtMemcpyKind policy);
static void* CopyDataDeviceToLocal(void* deviceData, uint32_t dataSize);
static void* CopyDataHostToDevice(void* deviceData, uint32_t dataSize);
static void* CopyDataDeviceToDevice(void* deviceData, uint32_t dataSize);
static int ReadImageFile(ImageData& image, std::string fileName);
static int CopyImageDataToDevice(ImageData& imageDevice, ImageData srcImage, aclrtRunMode mode);
static int CopyImageDataToDvpp(ImageData& imageDevice, ImageData srcImage);
static int CopysyImageDataToDvpp(ImageData& imageDevice, sy_img srcImage);
static void* CopyDataHostToDvpp(void* data, int size);
static bool CreateFolder(std::string folderPath, mode_t mode = 0700);
static bool WriteImage(unsigned char* data, int32_t size, const char* filename);
static void* CopyDataDeviceToDvpp(void* data, int size);
// static float sigmoid1(float val);
static float sigmoid(float val);
static float FastSigmoid(float x);
};
#endif
|