From: @lizhenglong1992 Reviewed-by: @liucunwei,@jonyguo,@heleiwang Signed-off-by: @liucunweitags/v1.1.0
| @@ -692,10 +692,11 @@ Status DvppDecodeResizeCropOperation::ValidateParams() { | |||||
| } | } | ||||
| if (*min_element(crop_.begin(), crop_.end()) < 32 || *max_element(crop_.begin(), crop_.end()) > 2048) { | if (*min_element(crop_.begin(), crop_.end()) < 32 || *max_element(crop_.begin(), crop_.end()) > 2048) { | ||||
| std::string err_msg = "Dvpp module supports crop image with resolution in range [32, 2048], got Crop Parameters: "; | std::string err_msg = "Dvpp module supports crop image with resolution in range [32, 2048], got Crop Parameters: "; | ||||
| if (crop_.size() == 2) | |||||
| if (crop_.size() == 2) { | |||||
| MS_LOG(ERROR) << err_msg << "[" << crop_[0] << ", " << crop_[1] << "]"; | MS_LOG(ERROR) << err_msg << "[" << crop_[0] << ", " << crop_[1] << "]"; | ||||
| else | |||||
| } else { | |||||
| MS_LOG(ERROR) << err_msg << "[" << crop_[0] << ", " << crop_[0] << "]"; | MS_LOG(ERROR) << err_msg << "[" << crop_[0] << ", " << crop_[0] << "]"; | ||||
| } | |||||
| RETURN_STATUS_SYNTAX_ERROR(err_msg); | RETURN_STATUS_SYNTAX_ERROR(err_msg); | ||||
| } | } | ||||
| if (*min_element(resize_.begin(), resize_.end()) < 32 || *max_element(resize_.begin(), resize_.end()) > 2048) { | if (*min_element(resize_.begin(), resize_.end()) < 32 || *max_element(resize_.begin(), resize_.end()) > 2048) { | ||||
| @@ -14,9 +14,9 @@ | |||||
| */ | */ | ||||
| #include "AclProcess.h" | #include "AclProcess.h" | ||||
| #include <sys/stat.h> | |||||
| #include <sys/time.h> | #include <sys/time.h> | ||||
| #include <thread> | #include <thread> | ||||
| #include <sys/stat.h> | |||||
| namespace { | namespace { | ||||
| const int BUFFER_SIZE = 2048; | const int BUFFER_SIZE = 2048; | ||||
| @@ -125,7 +125,7 @@ APP_ERROR AclProcess::InitResource() { | |||||
| * @param: imageFile specifies the image path to be processed | * @param: imageFile specifies the image path to be processed | ||||
| * @return: aclError which is error code of ACL API | * @return: aclError which is error code of ACL API | ||||
| */ | */ | ||||
| APP_ERROR AclProcess::Preprocess(RawData &ImageInfo) { | |||||
| APP_ERROR AclProcess::Preprocess(const RawData &ImageInfo) { | |||||
| // Decode process | // Decode process | ||||
| APP_ERROR ret = dvppCommon_->CombineJpegdProcess(ImageInfo, PIXEL_FORMAT_YUV_SEMIPLANAR_420, true); | APP_ERROR ret = dvppCommon_->CombineJpegdProcess(ImageInfo, PIXEL_FORMAT_YUV_SEMIPLANAR_420, true); | ||||
| if (ret != APP_ERR_OK) { | if (ret != APP_ERR_OK) { | ||||
| @@ -179,7 +179,7 @@ APP_ERROR AclProcess::Preprocess(RawData &ImageInfo) { | |||||
| * @param: imageFile specifies the image path to be processed | * @param: imageFile specifies the image path to be processed | ||||
| * @return: aclError which is error code of ACL API | * @return: aclError which is error code of ACL API | ||||
| */ | */ | ||||
| APP_ERROR AclProcess::Process(RawData &ImageInfo) { | |||||
| APP_ERROR AclProcess::Process(const RawData &ImageInfo) { | |||||
| struct timeval begin = {0}; | struct timeval begin = {0}; | ||||
| struct timeval end = {0}; | struct timeval end = {0}; | ||||
| gettimeofday(&begin, nullptr); | gettimeofday(&begin, nullptr); | ||||
| @@ -219,28 +219,6 @@ APP_ERROR AclProcess::Process(RawData &ImageInfo) { | |||||
| return APP_ERR_OK; | return APP_ERR_OK; | ||||
| } | } | ||||
| /* | |||||
| * @description: Rename the image for saving | |||||
| * @Param: primary name of image | |||||
| * @return: aclError which is error code of ACL API | |||||
| */ | |||||
| APP_ERROR AclProcess::RenameFile(std::string &filename) { | |||||
| std::string delimiter = "/"; | |||||
| size_t pos = 0; | |||||
| std::string token; | |||||
| while ((pos = filename.find(delimiter)) != std::string::npos) { | |||||
| token = filename.substr(0, pos); | |||||
| filename.erase(0, pos + delimiter.length()); | |||||
| } | |||||
| delimiter = "."; | |||||
| pos = filename.find(delimiter); | |||||
| filename = filename.substr(0, pos); | |||||
| if (filename.length() == 0) { | |||||
| return APP_ERR_COMM_WRITE_FAIL; | |||||
| } | |||||
| return APP_ERR_OK; | |||||
| } | |||||
| void AclProcess::CropConfigFilter(CropRoiConfig &cfg, DvppCropInputInfo &cropinfo) { | void AclProcess::CropConfigFilter(CropRoiConfig &cfg, DvppCropInputInfo &cropinfo) { | ||||
| cfg.up = (resizeHeight_ - cropHeight_) / 2; | cfg.up = (resizeHeight_ - cropHeight_) / 2; | ||||
| if (cfg.up % 2 != 0) { | if (cfg.up % 2 != 0) { | ||||
| @@ -274,4 +252,4 @@ void AclProcess::set_mode(bool flag) { repeat_ = flag; } | |||||
| bool AclProcess::get_mode() { return repeat_; } | bool AclProcess::get_mode() { return repeat_; } | ||||
| void AclProcess::device_memory_release() { dvppCommon_->ReleaseDvppBuffer(); } | |||||
| void AclProcess::device_memory_release() { dvppCommon_->ReleaseDvppBuffer(); } | |||||
| @@ -16,10 +16,15 @@ | |||||
| #ifndef ACLMANAGER_H | #ifndef ACLMANAGER_H | ||||
| #define ACLMANAGER_H | #define ACLMANAGER_H | ||||
| #include <climits> | |||||
| #include <string> | |||||
| #include <stdio.h> | |||||
| #include <unistd.h> | |||||
| #include <sys/stat.h> | |||||
| #include <string.h> | #include <string.h> | ||||
| #include <sys/types.h> | |||||
| #include <string> | |||||
| #include <map> | #include <map> | ||||
| #include <climits> | |||||
| #include <string> | |||||
| #include <iostream> | #include <iostream> | ||||
| #include <memory> | #include <memory> | ||||
| #include "acl/acl.h" | #include "acl/acl.h" | ||||
| @@ -27,10 +32,6 @@ | |||||
| #include "mindspore/core/utils/log_adapter.h" | #include "mindspore/core/utils/log_adapter.h" | ||||
| #include "ErrorCode.h" | #include "ErrorCode.h" | ||||
| #include "DvppCommon.h" | #include "DvppCommon.h" | ||||
| #include <stdio.h> | |||||
| #include <unistd.h> | |||||
| #include <sys/stat.h> | |||||
| #include <sys/types.h> | |||||
| mode_t SetFileDefaultUmask(); | mode_t SetFileDefaultUmask(); | ||||
| @@ -39,14 +40,14 @@ class AclProcess { | |||||
| AclProcess(uint32_t resizeWidth, uint32_t resizeHeight, uint32_t cropWidth, uint32_t cropHeight, aclrtContext context, | AclProcess(uint32_t resizeWidth, uint32_t resizeHeight, uint32_t cropWidth, uint32_t cropHeight, aclrtContext context, | ||||
| aclrtStream stream = nullptr, std::shared_ptr<DvppCommon> dvppCommon = nullptr); | aclrtStream stream = nullptr, std::shared_ptr<DvppCommon> dvppCommon = nullptr); | ||||
| ~AclProcess(){}; | |||||
| ~AclProcess() {} | |||||
| // Release all the resource | // Release all the resource | ||||
| APP_ERROR Release(); | APP_ERROR Release(); | ||||
| // Create resource for this sample | // Create resource for this sample | ||||
| APP_ERROR InitResource(); | APP_ERROR InitResource(); | ||||
| // Process the result | // Process the result | ||||
| APP_ERROR Process(RawData &ImageInfo); | |||||
| APP_ERROR Process(const RawData &ImageInfo); | |||||
| // API for access memory | // API for access memory | ||||
| std::shared_ptr<void> Get_Memory_Data(); | std::shared_ptr<void> Get_Memory_Data(); | ||||
| // API for access device memory | // API for access device memory | ||||
| @@ -64,9 +65,7 @@ class AclProcess { | |||||
| // Initialize the modules used by this sample | // Initialize the modules used by this sample | ||||
| APP_ERROR InitModule(); | APP_ERROR InitModule(); | ||||
| // Preprocess the input image | // Preprocess the input image | ||||
| APP_ERROR Preprocess(RawData &ImageInfo); | |||||
| // Filename process | |||||
| APP_ERROR RenameFile(std::string &filename); | |||||
| APP_ERROR Preprocess(const RawData &ImageInfo); | |||||
| aclrtContext context_; | aclrtContext context_; | ||||
| aclrtStream stream_; | aclrtStream stream_; | ||||
| @@ -21,6 +21,7 @@ | |||||
| #include <stdio.h> | #include <stdio.h> | ||||
| #include <iostream> | #include <iostream> | ||||
| #include <memory> | #include <memory> | ||||
| #include <string> | |||||
| #include <vector> | #include <vector> | ||||
| #include "acl/acl.h" | #include "acl/acl.h" | ||||
| #include "acl/ops/acl_dvpp.h" | #include "acl/ops/acl_dvpp.h" | ||||
| @@ -15,7 +15,6 @@ | |||||
| #include <iostream> | #include <iostream> | ||||
| #include <memory> | #include <memory> | ||||
| #include "mindspore/core/utils/log_adapter.h" | #include "mindspore/core/utils/log_adapter.h" | ||||
| #include "DvppCommon.h" | #include "DvppCommon.h" | ||||
| #include "CommonDataType.h" | #include "CommonDataType.h" | ||||
| @@ -25,9 +24,9 @@ static auto g_picDescDeleter = [](acldvppPicDesc *picDesc) { acldvppDestroyPicDe | |||||
| static auto g_roiConfigDeleter = [](acldvppRoiConfig *p) { acldvppDestroyRoiConfig(p); }; | static auto g_roiConfigDeleter = [](acldvppRoiConfig *p) { acldvppDestroyRoiConfig(p); }; | ||||
| static auto g_jpegeConfigDeleter = [](acldvppJpegeConfig *p) { acldvppDestroyJpegeConfig(p); }; | static auto g_jpegeConfigDeleter = [](acldvppJpegeConfig *p) { acldvppDestroyJpegeConfig(p); }; | ||||
| DvppCommon::DvppCommon(aclrtStream dvppStream) { dvppStream_ = dvppStream; } | |||||
| DvppCommon::DvppCommon(aclrtStream dvppStream) : dvppStream_(dvppStream) {} | |||||
| DvppCommon::DvppCommon(const VdecConfig &vdecConfig) { vdecConfig_ = vdecConfig; } | |||||
| DvppCommon::DvppCommon(const VdecConfig &vdecConfig) : vdecConfig_(vdecConfig) {} | |||||
| /* | /* | ||||
| * @description: Create a channel for processing image data, | * @description: Create a channel for processing image data, | ||||
| @@ -16,9 +16,10 @@ | |||||
| #ifndef DVPP_COMMON_H | #ifndef DVPP_COMMON_H | ||||
| #define DVPP_COMMON_H | #define DVPP_COMMON_H | ||||
| #include <vector> | |||||
| #include <memory> | |||||
| #include "CommonDataType.h" | #include "CommonDataType.h" | ||||
| #include "ErrorCode.h" | #include "ErrorCode.h" | ||||
| #include "acl/ops/acl_dvpp.h" | #include "acl/ops/acl_dvpp.h" | ||||
| const int MODULUS_NUM_2 = 2; | const int MODULUS_NUM_2 = 2; | ||||
| @@ -37,14 +37,14 @@ std::string GetAppErrCodeInfo(const APP_ERROR err) { | |||||
| } | } | ||||
| } | } | ||||
| void AssertErrorCode(int code, std::string file, std::string function, int line) { | |||||
| void AssertErrorCode(const int code, const std::string file, const std::string function, const int line) { | |||||
| if (code != APP_ERR_OK) { | if (code != APP_ERR_OK) { | ||||
| MS_LOG(ERROR) << "Failed at " << file << "->" << function << "->" << line << ": error code=" << code; | MS_LOG(ERROR) << "Failed at " << file << "->" << function << "->" << line << ": error code=" << code; | ||||
| exit(code); | exit(code); | ||||
| } | } | ||||
| } | } | ||||
| void CheckErrorCode(int code, std::string file, std::string function, int line) { | |||||
| void CheckErrorCode(const int code, const std::string file, const std::string function, const int line) { | |||||
| if (code != APP_ERR_OK) { | if (code != APP_ERR_OK) { | ||||
| MS_LOG(ERROR) << "Failed at " << file << "->" << function << "->" << line << ": error code=" << code; | MS_LOG(ERROR) << "Failed at " << file << "->" << function << "->" << line << ": error code=" << code; | ||||
| } | } | ||||
| @@ -249,10 +249,10 @@ const std::string APP_ERR_FACE_LOG_STRING[] = { | |||||
| }; | }; | ||||
| std::string GetAppErrCodeInfo(APP_ERROR err); | std::string GetAppErrCodeInfo(APP_ERROR err); | ||||
| void AssertErrorCode(int code, std::string file, std::string function, int line); | |||||
| void CheckErrorCode(int code, std::string file, std::string function, int line); | |||||
| void AssertErrorCode(const int code, const std::string file, const std::string function, const int line); | |||||
| void CheckErrorCode(const int code, const std::string file, const std::string function, const int line); | |||||
| #define RtAssert(code) AssertErrorCode(code, __FILE__, __FUNCTION__, __LINE__); | #define RtAssert(code) AssertErrorCode(code, __FILE__, __FUNCTION__, __LINE__); | ||||
| #define RtCheckError(code) CheckErrorCode(code, __FILE__, __FUNCTION__, __LINE__); | #define RtCheckError(code) CheckErrorCode(code, __FILE__, __FUNCTION__, __LINE__); | ||||
| #endif // ERROR_CODE_H_ | |||||
| #endif // ERROR_CODE_H_ | |||||
| @@ -16,14 +16,16 @@ | |||||
| #ifndef RESOURCEMANAGER_H | #ifndef RESOURCEMANAGER_H | ||||
| #define RESOURCEMANAGER_H | #define RESOURCEMANAGER_H | ||||
| #include <sys/stat.h> | |||||
| #include <vector> | #include <vector> | ||||
| #include <set> | #include <set> | ||||
| #include <cstring> | #include <cstring> | ||||
| #include <string> | |||||
| #include <unordered_map> | #include <unordered_map> | ||||
| #include <memory> | |||||
| #include <mutex> | #include <mutex> | ||||
| #include "CommonDataType.h" | #include "CommonDataType.h" | ||||
| #include "ErrorCode.h" | #include "ErrorCode.h" | ||||
| #include <sys/stat.h> | |||||
| #include "mindspore/core/utils/log_adapter.h" | #include "mindspore/core/utils/log_adapter.h" | ||||
| #include "mindspore/ccsrc/cxx_api/graph/acl/acl_env_guard.h" | #include "mindspore/ccsrc/cxx_api/graph/acl/acl_env_guard.h" | ||||
| @@ -62,9 +64,9 @@ APP_ERROR ExistFile(const std::string &filePath); | |||||
| class ResourceManager { | class ResourceManager { | ||||
| public: | public: | ||||
| ResourceManager(){}; | |||||
| ResourceManager() {} | |||||
| ~ResourceManager(){}; | |||||
| ~ResourceManager() {} | |||||
| // Get the Instance of resource manager | // Get the Instance of resource manager | ||||
| static std::shared_ptr<ResourceManager> GetInstance(); | static std::shared_ptr<ResourceManager> GetInstance(); | ||||
| @@ -87,4 +89,4 @@ class ResourceManager { | |||||
| std::shared_ptr<mindspore::api::AclEnvGuard> acl_env_; | std::shared_ptr<mindspore::api::AclEnvGuard> acl_env_; | ||||
| }; | }; | ||||
| #endif | |||||
| #endif | |||||
| @@ -74,7 +74,7 @@ TEST_F(TestDE, TestDvpp) { | |||||
| ASSERT_EQ(img->Shape().size(), 3); | ASSERT_EQ(img->Shape().size(), 3); | ||||
| int32_t real_h = 0; | int32_t real_h = 0; | ||||
| int32_t real_w = 0; | int32_t real_w = 0; | ||||
| int remainder = crop_size[crop_size.size() - 1] % 16; | |||||
| int32_t remainder = crop_size[crop_size.size() - 1] % 16; | |||||
| if (crop_size.size() == 1) { | if (crop_size.size() == 1) { | ||||
| real_h = (crop_size[0] % 2 == 0) ? crop_size[0] : crop_size[0] + 1; | real_h = (crop_size[0] % 2 == 0) ? crop_size[0] : crop_size[0] + 1; | ||||
| real_w = (remainder == 0) ? crop_size[0] : crop_size[0] + 16 - remainder; | real_w = (remainder == 0) ? crop_size[0] : crop_size[0] + 16 - remainder; | ||||