#ifndef _UTILS_H_ #define _UTILS_H_ #include #include #include #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 *)(buf), [](uint8_t* p) { acldvppFree(p); })) #define SHARED_PRT_U8_BUF(buf) (shared_ptr((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 std::shared_ptr MakeSharedNoThrow() { try { return std::make_shared(); } catch (...) { return nullptr; } } #define MAKE_SHARED_NO_THROW(memory, memory_type) \ do { \ memory = MakeSharedNoThrow(); \ }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