| @@ -22,6 +22,7 @@ | |||||
| #include <iosfwd> | #include <iosfwd> | ||||
| #include <vector> | #include <vector> | ||||
| #include <fstream> | #include <fstream> | ||||
| #include <sstream> | |||||
| #include "include/api/model.h" | #include "include/api/model.h" | ||||
| #include "include/api/context.h" | #include "include/api/context.h" | ||||
| @@ -120,7 +121,7 @@ int main(int argc, char **argv) { | |||||
| compose(ReadFileToTensor(allFiles[i]), &img); | compose(ReadFileToTensor(allFiles[i]), &img); | ||||
| inputs.emplace_back(modelInputs[0].Name(), modelInputs[0].DataType(), modelInputs[0].Shape(), | inputs.emplace_back(modelInputs[0].Name(), modelInputs[0].DataType(), modelInputs[0].Shape(), | ||||
| img.Data().get(), img.DataSize()); | |||||
| img.Data().get(), img.DataSize()); | |||||
| gettimeofday(&start, NULL); | gettimeofday(&start, NULL); | ||||
| ret = model.Predict(inputs, &outputs); | ret = model.Predict(inputs, &outputs); | ||||
| @@ -136,7 +137,7 @@ int main(int argc, char **argv) { | |||||
| } | } | ||||
| double average = 0.0; | double average = 0.0; | ||||
| int infer_cnt = 0; | int infer_cnt = 0; | ||||
| char tmpCh[256] = {0}; | |||||
| for (auto iter = costTime_map.begin(); iter != costTime_map.end(); iter++) { | for (auto iter = costTime_map.begin(); iter != costTime_map.end(); iter++) { | ||||
| double diff = 0.0; | double diff = 0.0; | ||||
| diff = iter->second - iter->first; | diff = iter->second - iter->first; | ||||
| @@ -145,11 +146,12 @@ int main(int argc, char **argv) { | |||||
| } | } | ||||
| average = average/infer_cnt; | average = average/infer_cnt; | ||||
| snprintf(tmpCh, sizeof(tmpCh), "NN inference cost average time: %4.3f ms of infer_count %d \n", average, infer_cnt); | |||||
| std::stringstream timeCost; | |||||
| timeCost << "NN inference cost average time: "<< average << " ms of infer_count " << infer_cnt << std::endl; | |||||
| std::cout << "NN inference cost average time: "<< average << "ms of infer_count " << infer_cnt << std::endl; | std::cout << "NN inference cost average time: "<< average << "ms of infer_count " << infer_cnt << std::endl; | ||||
| std::string file_name = "./time_Result" + std::string("/test_perform_static.txt"); | std::string file_name = "./time_Result" + std::string("/test_perform_static.txt"); | ||||
| std::ofstream file_stream(file_name.c_str(), std::ios::trunc); | std::ofstream file_stream(file_name.c_str(), std::ios::trunc); | ||||
| file_stream << tmpCh; | |||||
| file_stream << timeCost.str(); | |||||
| file_stream.close(); | file_stream.close(); | ||||
| costTime_map.clear(); | costTime_map.clear(); | ||||
| return 0; | return 0; | ||||
| @@ -23,6 +23,7 @@ | |||||
| #include <iosfwd> | #include <iosfwd> | ||||
| #include <vector> | #include <vector> | ||||
| #include <fstream> | #include <fstream> | ||||
| #include <sstream> | |||||
| #include "../inc/utils.h" | #include "../inc/utils.h" | ||||
| #include "minddata/dataset/include/execute.h" | #include "minddata/dataset/include/execute.h" | ||||
| @@ -141,7 +142,7 @@ int main(int argc, char **argv) { | |||||
| } | } | ||||
| double average = 0.0; | double average = 0.0; | ||||
| int infer_cnt = 0; | int infer_cnt = 0; | ||||
| char tmpCh[256] = {0}; | |||||
| for (auto iter = costTime_map.begin(); iter != costTime_map.end(); iter++) { | for (auto iter = costTime_map.begin(); iter != costTime_map.end(); iter++) { | ||||
| double diff = 0.0; | double diff = 0.0; | ||||
| diff = iter->second - iter->first; | diff = iter->second - iter->first; | ||||
| @@ -149,13 +150,14 @@ int main(int argc, char **argv) { | |||||
| infer_cnt++; | infer_cnt++; | ||||
| } | } | ||||
| average = average/infer_cnt; | |||||
| average = average / infer_cnt; | |||||
| snprintf(tmpCh, sizeof(tmpCh), "NN inference cost average time: %4.3f ms of infer_count %d\n", average, infer_cnt); | |||||
| std::stringstream timeCost; | |||||
| timeCost << "NN inference cost average time: "<< average << " ms of infer_count " << infer_cnt << std::endl; | |||||
| std::cout << "NN inference cost average time: "<< average << "ms of infer_count " << infer_cnt << std::endl; | std::cout << "NN inference cost average time: "<< average << "ms of infer_count " << infer_cnt << std::endl; | ||||
| std::string file_name = "./time_Result" + std::string("/test_perform_static.txt"); | std::string file_name = "./time_Result" + std::string("/test_perform_static.txt"); | ||||
| std::ofstream file_stream(file_name.c_str(), std::ios::trunc); | std::ofstream file_stream(file_name.c_str(), std::ios::trunc); | ||||
| file_stream << tmpCh; | |||||
| file_stream << timeCost.str(); | |||||
| file_stream.close(); | file_stream.close(); | ||||
| costTime_map.clear(); | costTime_map.clear(); | ||||
| return 0; | return 0; | ||||
| @@ -55,7 +55,7 @@ int WriteResult(const std::string& imageFile, const std::vector<MSTensor> &outpu | |||||
| std::string fileName(imageFile, pos + 1); | std::string fileName(imageFile, pos + 1); | ||||
| fileName.replace(fileName.find('.'), fileName.size() - fileName.find('.'), '_' + std::to_string(i) + ".bin"); | fileName.replace(fileName.find('.'), fileName.size() - fileName.find('.'), '_' + std::to_string(i) + ".bin"); | ||||
| std::string outFileName = homePath + "/" + fileName; | std::string outFileName = homePath + "/" + fileName; | ||||
| FILE * outputFile = fopen(outFileName.c_str(), "wb"); | |||||
| FILE *outputFile = fopen(outFileName.c_str(), "wb"); | |||||
| fwrite(netOutput.get(), outputSize, sizeof(char), outputFile); | fwrite(netOutput.get(), outputSize, sizeof(char), outputFile); | ||||
| fclose(outputFile); | fclose(outputFile); | ||||
| outputFile = nullptr; | outputFile = nullptr; | ||||
| @@ -118,7 +118,6 @@ std::string RealPath(std::string_view path) { | |||||
| char realPathMem[PATH_MAX] = {0}; | char realPathMem[PATH_MAX] = {0}; | ||||
| char *realPathRet = nullptr; | char *realPathRet = nullptr; | ||||
| realPathRet = realpath(path.data(), realPathMem); | realPathRet = realpath(path.data(), realPathMem); | ||||
| if (realPathRet == nullptr) { | if (realPathRet == nullptr) { | ||||
| std::cout << "File: " << path << " is not exist."; | std::cout << "File: " << path << " is not exist."; | ||||
| return ""; | return ""; | ||||
| @@ -22,6 +22,7 @@ | |||||
| #include <iosfwd> | #include <iosfwd> | ||||
| #include <vector> | #include <vector> | ||||
| #include <fstream> | #include <fstream> | ||||
| #include <sstream> | |||||
| #include "include/api/context.h" | #include "include/api/context.h" | ||||
| #include "include/api/model.h" | #include "include/api/model.h" | ||||
| @@ -197,7 +198,7 @@ int main(int argc, char **argv) { | |||||
| } | } | ||||
| double average = 0.0; | double average = 0.0; | ||||
| int inferCount = 0; | int inferCount = 0; | ||||
| char tmpCh[256] = {0}; | |||||
| for (auto iter = costTime_map.begin(); iter != costTime_map.end(); iter++) { | for (auto iter = costTime_map.begin(); iter != costTime_map.end(); iter++) { | ||||
| double diff = 0.0; | double diff = 0.0; | ||||
| diff = iter->second - iter->first; | diff = iter->second - iter->first; | ||||
| @@ -205,12 +206,13 @@ int main(int argc, char **argv) { | |||||
| inferCount++; | inferCount++; | ||||
| } | } | ||||
| average = average / inferCount; | average = average / inferCount; | ||||
| snprintf(tmpCh, sizeof(tmpCh), \ | |||||
| "NN inference cost average time: %4.3f ms of infer_count %d \n", average, inferCount); | |||||
| std::stringstream timeCost; | |||||
| timeCost << "NN inference cost average time: "<< average << " ms of infer_count " << inferCount << std::endl; | |||||
| std::cout << "NN inference cost average time: "<< average << "ms of infer_count " << inferCount << std::endl; | std::cout << "NN inference cost average time: "<< average << "ms of infer_count " << inferCount << std::endl; | ||||
| std::string fileName = "./time_Result" + std::string("/test_perform_static.txt"); | std::string fileName = "./time_Result" + std::string("/test_perform_static.txt"); | ||||
| std::ofstream fileStream(fileName.c_str(), std::ios::trunc); | std::ofstream fileStream(fileName.c_str(), std::ios::trunc); | ||||
| fileStream << tmpCh; | |||||
| fileStream << timeCost.str(); | |||||
| fileStream.close(); | fileStream.close(); | ||||
| costTime_map.clear(); | costTime_map.clear(); | ||||
| return 0; | return 0; | ||||
| @@ -142,7 +142,7 @@ int AclProcess::WriteResult(const std::string& imageFile) { | |||||
| void *resHostBuf = nullptr; | void *resHostBuf = nullptr; | ||||
| for (size_t i = 0; i < outputBuffers_.size(); ++i) { | for (size_t i = 0; i < outputBuffers_.size(); ++i) { | ||||
| size_t output_size; | size_t output_size; | ||||
| void * netOutput; | |||||
| void *netOutput; | |||||
| netOutput = outputBuffers_[i]; | netOutput = outputBuffers_[i]; | ||||
| output_size = outputSizes_[i]; | output_size = outputSizes_[i]; | ||||
| int ret = aclrtMallocHost(&resHostBuf, output_size); | int ret = aclrtMallocHost(&resHostBuf, output_size); | ||||
| @@ -164,7 +164,7 @@ int AclProcess::WriteResult(const std::string& imageFile) { | |||||
| std::string outFileName = homePath + "/" + fileName; | std::string outFileName = homePath + "/" + fileName; | ||||
| try { | try { | ||||
| FILE * outputFile = fopen(outFileName.c_str(), "wb"); | |||||
| FILE *outputFile = fopen(outFileName.c_str(), "wb"); | |||||
| if (outputFile == nullptr) { | if (outputFile == nullptr) { | ||||
| std::cout << "open result file " << outFileName << " failed" << std::endl; | std::cout << "open result file " << outFileName << " failed" << std::endl; | ||||
| return INVALID_POINTER; | return INVALID_POINTER; | ||||
| @@ -299,17 +299,19 @@ int AclProcess::ModelInfer(std::map<double, double> *costTime_map) { | |||||
| if (ret != ACL_ERROR_NONE) { | if (ret != ACL_ERROR_NONE) { | ||||
| std::cout << "aclrtMalloc failed, ret = " << ret << std::endl; | std::cout << "aclrtMalloc failed, ret = " << ret << std::endl; | ||||
| aclrtFree(imInfo_dst); | aclrtFree(imInfo_dst); | ||||
| free(im_info); | |||||
| return ret; | return ret; | ||||
| } | } | ||||
| ret = aclrtMemcpy(reinterpret_cast<uint8_t *>(imInfo_dst), 8, im_info, 8, ACL_MEMCPY_HOST_TO_DEVICE); | ret = aclrtMemcpy(reinterpret_cast<uint8_t *>(imInfo_dst), 8, im_info, 8, ACL_MEMCPY_HOST_TO_DEVICE); | ||||
| if (ret != ACL_ERROR_NONE) { | if (ret != ACL_ERROR_NONE) { | ||||
| std::cout << "aclrtMemcpy failed, ret = " << ret << std::endl; | std::cout << "aclrtMemcpy failed, ret = " << ret << std::endl; | ||||
| aclrtFree(imInfo_dst); | aclrtFree(imInfo_dst); | ||||
| free(im_info); | |||||
| return ret; | return ret; | ||||
| } | } | ||||
| std::vector<void *> inputBuffers({resizeOutData->data, imInfo_dst}); | std::vector<void *> inputBuffers({resizeOutData->data, imInfo_dst}); | ||||
| std::vector<size_t> inputSizes({resizeOutData->dataSize, 4*2}); | |||||
| std::vector<size_t> inputSizes({resizeOutData->dataSize, 4 * 2}); | |||||
| for (size_t i = 0; i < modelInfo_.outputNum; i++) { | for (size_t i = 0; i < modelInfo_.outputNum; i++) { | ||||
| aclrtMemset(outputBuffers_[i], outputSizes_[i], 0, outputSizes_[i]); | aclrtMemset(outputBuffers_[i], outputSizes_[i], 0, outputSizes_[i]); | ||||
| @@ -318,6 +320,7 @@ int AclProcess::ModelInfer(std::map<double, double> *costTime_map) { | |||||
| ret = modelProcess_->ModelInference(inputBuffers, inputSizes, outputBuffers_, outputSizes_, costTime_map); | ret = modelProcess_->ModelInference(inputBuffers, inputSizes, outputBuffers_, outputSizes_, costTime_map); | ||||
| if (ret != OK) { | if (ret != OK) { | ||||
| aclrtFree(imInfo_dst); | aclrtFree(imInfo_dst); | ||||
| free(im_info); | |||||
| std::cout << "Failed to execute the classification model, ret = " << ret << "." << std::endl; | std::cout << "Failed to execute the classification model, ret = " << ret << "." << std::endl; | ||||
| return ret; | return ret; | ||||
| } | } | ||||
| @@ -327,6 +330,7 @@ int AclProcess::ModelInfer(std::map<double, double> *costTime_map) { | |||||
| std::cout << "aclrtFree image info failed" << std::endl; | std::cout << "aclrtFree image info failed" << std::endl; | ||||
| return ret; | return ret; | ||||
| } | } | ||||
| free(im_info); | |||||
| RELEASE_DVPP_DATA(resizeOutData->data); | RELEASE_DVPP_DATA(resizeOutData->data); | ||||
| return OK; | return OK; | ||||
| } | } | ||||
| @@ -115,7 +115,7 @@ int DvppCommon::GetVpcDataSize(uint32_t width, uint32_t height, acldvppPixelForm | |||||
| * @return: OK if success, other values if failure | * @return: OK if success, other values if failure | ||||
| */ | */ | ||||
| int DvppCommon::GetVpcInputStrideSize(uint32_t width, uint32_t height, acldvppPixelFormat format, | int DvppCommon::GetVpcInputStrideSize(uint32_t width, uint32_t height, acldvppPixelFormat format, | ||||
| uint32_t *widthStride, uint32_t *heightStride) { | |||||
| uint32_t *widthStride, uint32_t *heightStride) { | |||||
| uint32_t inputWidthStride; | uint32_t inputWidthStride; | ||||
| if (format >= PIXEL_FORMAT_YUV_400 && format <= PIXEL_FORMAT_YVU_SEMIPLANAR_444) { | if (format >= PIXEL_FORMAT_YUV_400 && format <= PIXEL_FORMAT_YVU_SEMIPLANAR_444) { | ||||
| inputWidthStride = DVPP_ALIGN_UP(width, VPC_STRIDE_WIDTH); | inputWidthStride = DVPP_ALIGN_UP(width, VPC_STRIDE_WIDTH); | ||||
| @@ -156,7 +156,7 @@ int DvppCommon::GetVpcInputStrideSize(uint32_t width, uint32_t height, acldvppPi | |||||
| * @return: OK if success, other values if failure | * @return: OK if success, other values if failure | ||||
| */ | */ | ||||
| int DvppCommon::GetVpcOutputStrideSize(uint32_t width, uint32_t height, acldvppPixelFormat format, | int DvppCommon::GetVpcOutputStrideSize(uint32_t width, uint32_t height, acldvppPixelFormat format, | ||||
| uint32_t *widthStride, uint32_t *heightStride) { | |||||
| uint32_t *widthStride, uint32_t *heightStride) { | |||||
| if (format != PIXEL_FORMAT_YUV_SEMIPLANAR_420 && format != PIXEL_FORMAT_YVU_SEMIPLANAR_420) { | if (format != PIXEL_FORMAT_YUV_SEMIPLANAR_420 && format != PIXEL_FORMAT_YVU_SEMIPLANAR_420) { | ||||
| std::cout << "Output format[" << format << "] is not supported, just support NV12 or NV21." << std::endl; | std::cout << "Output format[" << format << "] is not supported, just support NV12 or NV21." << std::endl; | ||||
| return INVALID_PARAM; | return INVALID_PARAM; | ||||
| @@ -348,7 +348,7 @@ int DvppCommon::ResizeWithPadding(std::shared_ptr<acldvppPicDesc> inputDesc, | |||||
| pasteAreaConfig_.reset(pastRoiCfg, g_roiConfigDeleter); | pasteAreaConfig_.reset(pastRoiCfg, g_roiConfigDeleter); | ||||
| int ret = acldvppVpcCropAndPasteAsync(dvppChannelDesc_, inputDesc.get(), outputDesc.get(), cropAreaConfig_.get(), | int ret = acldvppVpcCropAndPasteAsync(dvppChannelDesc_, inputDesc.get(), outputDesc.get(), cropAreaConfig_.get(), | ||||
| pasteAreaConfig_.get(), dvppStream_); | |||||
| pasteAreaConfig_.get(), dvppStream_); | |||||
| if (ret != OK) { | if (ret != OK) { | ||||
| // release resource. | // release resource. | ||||
| std::cout << "Failed to crop and paste asynchronously, ret = " << ret << "." << std::endl; | std::cout << "Failed to crop and paste asynchronously, ret = " << ret << "." << std::endl; | ||||
| @@ -574,7 +574,7 @@ void DvppCommon::GetJpegDecodeStrideSize(uint32_t width, uint32_t height, | |||||
| * @return: OK if success, other values if failure | * @return: OK if success, other values if failure | ||||
| */ | */ | ||||
| int DvppCommon::GetJpegImageInfo(const void *data, uint32_t dataSize, uint32_t *width, uint32_t *height, | int DvppCommon::GetJpegImageInfo(const void *data, uint32_t dataSize, uint32_t *width, uint32_t *height, | ||||
| int32_t *components) { | |||||
| int32_t *components) { | |||||
| uint32_t widthTmp; | uint32_t widthTmp; | ||||
| uint32_t heightTmp; | uint32_t heightTmp; | ||||
| int32_t componentsTmp; | int32_t componentsTmp; | ||||
| @@ -608,7 +608,7 @@ int DvppCommon::GetJpegImageInfo(const void *data, uint32_t dataSize, uint32_t * | |||||
| * @return: OK if success, other values if failure | * @return: OK if success, other values if failure | ||||
| */ | */ | ||||
| int DvppCommon::GetJpegDecodeDataSize(const void *data, uint32_t dataSize, acldvppPixelFormat format, | int DvppCommon::GetJpegDecodeDataSize(const void *data, uint32_t dataSize, acldvppPixelFormat format, | ||||
| uint32_t *decSize) { | |||||
| uint32_t *decSize) { | |||||
| uint32_t outputSize; | uint32_t outputSize; | ||||
| int ret = acldvppJpegPredictDecSize(data, dataSize, format, &outputSize); | int ret = acldvppJpegPredictDecSize(data, dataSize, format, &outputSize); | ||||
| if (ret != OK) { | if (ret != OK) { | ||||
| @@ -632,7 +632,7 @@ int DvppCommon::CombineJpegdProcess(const RawData& imageInfo, acldvppPixelFormat | |||||
| inputImage_ = std::make_shared<DvppDataInfo>(); | inputImage_ = std::make_shared<DvppDataInfo>(); | ||||
| inputImage_->format = format; | inputImage_->format = format; | ||||
| int ret = GetJpegImageInfo(imageInfo.data.get(), imageInfo.lenOfByte, &(inputImage_->width), &(inputImage_->height), | int ret = GetJpegImageInfo(imageInfo.data.get(), imageInfo.lenOfByte, &(inputImage_->width), &(inputImage_->height), | ||||
| &components); | |||||
| &components); | |||||
| if (ret != OK) { | if (ret != OK) { | ||||
| std::cout << "Failed to get input image info, ret = " << ret << "." << std::endl; | std::cout << "Failed to get input image info, ret = " << ret << "." << std::endl; | ||||
| return ret; | return ret; | ||||
| @@ -59,7 +59,7 @@ int ModelProcess::ModelInference(const std::vector<void *> &inputBufs, | |||||
| if (input == nullptr) { | if (input == nullptr) { | ||||
| return INVALID_POINTER; | return INVALID_POINTER; | ||||
| } | } | ||||
| int ret = 0; | |||||
| int ret; | |||||
| aclmdlDataset *output = nullptr; | aclmdlDataset *output = nullptr; | ||||
| output = CreateAndFillDataset(ouputBufs, outputSizes); | output = CreateAndFillDataset(ouputBufs, outputSizes); | ||||
| @@ -18,6 +18,7 @@ | |||||
| #include <unistd.h> | #include <unistd.h> | ||||
| #include <cstring> | #include <cstring> | ||||
| #include <fstream> | #include <fstream> | ||||
| #include <sstream> | |||||
| #include "../inc/AclProcess.h" | #include "../inc/AclProcess.h" | ||||
| #include "../inc/CommonDataType.h" | #include "../inc/CommonDataType.h" | ||||
| @@ -82,13 +83,15 @@ int main(int argc, char* argv[]) { | |||||
| ret = aclProcess.Process(FLAGS_data_path, &costTime_map); | ret = aclProcess.Process(FLAGS_data_path, &costTime_map); | ||||
| if (ret != OK) { | if (ret != OK) { | ||||
| std::cout << "model process failed, errno = " << ret << std::endl; | std::cout << "model process failed, errno = " << ret << std::endl; | ||||
| aclProcess.Release(); | |||||
| return ret; | return ret; | ||||
| } | } | ||||
| } else if (is_dir(FLAGS_data_path)) { | } else if (is_dir(FLAGS_data_path)) { | ||||
| struct dirent * filename; | |||||
| DIR * dir; | |||||
| struct dirent *filename; | |||||
| DIR *dir; | |||||
| dir = opendir(FLAGS_data_path.c_str()); | dir = opendir(FLAGS_data_path.c_str()); | ||||
| if (dir == nullptr) { | if (dir == nullptr) { | ||||
| aclProcess.Release(); | |||||
| return ERROR; | return ERROR; | ||||
| } | } | ||||
| @@ -100,6 +103,7 @@ int main(int argc, char* argv[]) { | |||||
| ret = aclProcess.Process(wholePath, &costTime_map); | ret = aclProcess.Process(wholePath, &costTime_map); | ||||
| if (ret != OK) { | if (ret != OK) { | ||||
| std::cout << "model process failed, errno = " << ret << std::endl; | std::cout << "model process failed, errno = " << ret << std::endl; | ||||
| aclProcess.Release(); | |||||
| return ret; | return ret; | ||||
| } | } | ||||
| } | } | ||||
| @@ -109,20 +113,21 @@ int main(int argc, char* argv[]) { | |||||
| double average = 0.0; | double average = 0.0; | ||||
| int infer_cnt = 0; | int infer_cnt = 0; | ||||
| char tmpCh[256]; | |||||
| for (auto iter = costTime_map.begin(); iter != costTime_map.end(); iter++) { | for (auto iter = costTime_map.begin(); iter != costTime_map.end(); iter++) { | ||||
| double diff = 0.0; | double diff = 0.0; | ||||
| diff = iter->second - iter->first; | diff = iter->second - iter->first; | ||||
| average += diff; | average += diff; | ||||
| infer_cnt++; | infer_cnt++; | ||||
| } | } | ||||
| average = average/infer_cnt; | |||||
| memset(tmpCh, 0, sizeof(tmpCh)); | |||||
| snprintf(tmpCh, sizeof(tmpCh), "NN inference cost average time: %4.3f ms of infer_count %d \n", average, infer_cnt); | |||||
| average = average / infer_cnt; | |||||
| std::stringstream timeCost; | |||||
| timeCost << "NN inference cost average time: "<< average << "ms of infer_count " << infer_cnt << std::endl; | |||||
| std::cout << "NN inference cost average time: "<< average << "ms of infer_count " << infer_cnt << std::endl; | std::cout << "NN inference cost average time: "<< average << "ms of infer_count " << infer_cnt << std::endl; | ||||
| std::string file_name = "./time_Result" + std::string("/test_perform_static.txt"); | std::string file_name = "./time_Result" + std::string("/test_perform_static.txt"); | ||||
| std::ofstream file_stream(file_name.c_str(), std::ios::trunc); | std::ofstream file_stream(file_name.c_str(), std::ios::trunc); | ||||
| file_stream << tmpCh; | |||||
| file_stream << timeCost.str(); | |||||
| file_stream.close(); | file_stream.close(); | ||||
| costTime_map.clear(); | costTime_map.clear(); | ||||
| @@ -142,7 +142,7 @@ int AclProcess::WriteResult(const std::string& imageFile) { | |||||
| void *resHostBuf = nullptr; | void *resHostBuf = nullptr; | ||||
| for (size_t i = 0; i < outputBuffers_.size(); ++i) { | for (size_t i = 0; i < outputBuffers_.size(); ++i) { | ||||
| size_t output_size; | size_t output_size; | ||||
| void * netOutput; | |||||
| void *netOutput; | |||||
| netOutput = outputBuffers_[i]; | netOutput = outputBuffers_[i]; | ||||
| output_size = outputSizes_[i]; | output_size = outputSizes_[i]; | ||||
| int ret = aclrtMallocHost(&resHostBuf, output_size); | int ret = aclrtMallocHost(&resHostBuf, output_size); | ||||
| @@ -164,7 +164,7 @@ int AclProcess::WriteResult(const std::string& imageFile) { | |||||
| std::string outFileName = homePath + "/" + fileName; | std::string outFileName = homePath + "/" + fileName; | ||||
| try { | try { | ||||
| FILE * outputFile = fopen(outFileName.c_str(), "wb"); | |||||
| FILE *outputFile = fopen(outFileName.c_str(), "wb"); | |||||
| if (outputFile == nullptr) { | if (outputFile == nullptr) { | ||||
| std::cout << "open result file " << outFileName << " failed" << std::endl; | std::cout << "open result file " << outFileName << " failed" << std::endl; | ||||
| return INVALID_POINTER; | return INVALID_POINTER; | ||||
| @@ -308,7 +308,7 @@ int AclProcess::ModelInfer(std::map<double, double> *costTime_map) { | |||||
| } | } | ||||
| std::vector<void *> inputBuffers({resizeOutData->data, imInfo_dst}); | std::vector<void *> inputBuffers({resizeOutData->data, imInfo_dst}); | ||||
| std::vector<size_t> inputSizes({resizeOutData->dataSize, 4*2}); | |||||
| std::vector<size_t> inputSizes({resizeOutData->dataSize, 4 * 2}); | |||||
| for (size_t i = 0; i < modelInfo_.outputNum; i++) { | for (size_t i = 0; i < modelInfo_.outputNum; i++) { | ||||
| aclrtMemset(outputBuffers_[i], outputSizes_[i], 0, outputSizes_[i]); | aclrtMemset(outputBuffers_[i], outputSizes_[i], 0, outputSizes_[i]); | ||||
| @@ -115,7 +115,7 @@ int DvppCommon::GetVpcDataSize(uint32_t width, uint32_t height, acldvppPixelForm | |||||
| * @return: OK if success, other values if failure | * @return: OK if success, other values if failure | ||||
| */ | */ | ||||
| int DvppCommon::GetVpcInputStrideSize(uint32_t width, uint32_t height, acldvppPixelFormat format, | int DvppCommon::GetVpcInputStrideSize(uint32_t width, uint32_t height, acldvppPixelFormat format, | ||||
| uint32_t *widthStride, uint32_t *heightStride) { | |||||
| uint32_t *widthStride, uint32_t *heightStride) { | |||||
| uint32_t inputWidthStride; | uint32_t inputWidthStride; | ||||
| if (format >= PIXEL_FORMAT_YUV_400 && format <= PIXEL_FORMAT_YVU_SEMIPLANAR_444) { | if (format >= PIXEL_FORMAT_YUV_400 && format <= PIXEL_FORMAT_YVU_SEMIPLANAR_444) { | ||||
| inputWidthStride = DVPP_ALIGN_UP(width, VPC_STRIDE_WIDTH); | inputWidthStride = DVPP_ALIGN_UP(width, VPC_STRIDE_WIDTH); | ||||
| @@ -156,7 +156,7 @@ int DvppCommon::GetVpcInputStrideSize(uint32_t width, uint32_t height, acldvppPi | |||||
| * @return: OK if success, other values if failure | * @return: OK if success, other values if failure | ||||
| */ | */ | ||||
| int DvppCommon::GetVpcOutputStrideSize(uint32_t width, uint32_t height, acldvppPixelFormat format, | int DvppCommon::GetVpcOutputStrideSize(uint32_t width, uint32_t height, acldvppPixelFormat format, | ||||
| uint32_t *widthStride, uint32_t *heightStride) { | |||||
| uint32_t *widthStride, uint32_t *heightStride) { | |||||
| if (format != PIXEL_FORMAT_YUV_SEMIPLANAR_420 && format != PIXEL_FORMAT_YVU_SEMIPLANAR_420) { | if (format != PIXEL_FORMAT_YUV_SEMIPLANAR_420 && format != PIXEL_FORMAT_YVU_SEMIPLANAR_420) { | ||||
| std::cout << "Output format[" << format << "] is not supported, just support NV12 or NV21." << std::endl; | std::cout << "Output format[" << format << "] is not supported, just support NV12 or NV21." << std::endl; | ||||
| return INVALID_PARAM; | return INVALID_PARAM; | ||||
| @@ -348,7 +348,7 @@ int DvppCommon::ResizeWithPadding(std::shared_ptr<acldvppPicDesc> inputDesc, | |||||
| pasteAreaConfig_.reset(pastRoiCfg, g_roiConfigDeleter); | pasteAreaConfig_.reset(pastRoiCfg, g_roiConfigDeleter); | ||||
| int ret = acldvppVpcCropAndPasteAsync(dvppChannelDesc_, inputDesc.get(), outputDesc.get(), cropAreaConfig_.get(), | int ret = acldvppVpcCropAndPasteAsync(dvppChannelDesc_, inputDesc.get(), outputDesc.get(), cropAreaConfig_.get(), | ||||
| pasteAreaConfig_.get(), dvppStream_); | |||||
| pasteAreaConfig_.get(), dvppStream_); | |||||
| if (ret != OK) { | if (ret != OK) { | ||||
| // release resource. | // release resource. | ||||
| std::cout << "Failed to crop and paste asynchronously, ret = " << ret << "." << std::endl; | std::cout << "Failed to crop and paste asynchronously, ret = " << ret << "." << std::endl; | ||||
| @@ -574,7 +574,7 @@ void DvppCommon::GetJpegDecodeStrideSize(uint32_t width, uint32_t height, | |||||
| * @return: OK if success, other values if failure | * @return: OK if success, other values if failure | ||||
| */ | */ | ||||
| int DvppCommon::GetJpegImageInfo(const void *data, uint32_t dataSize, uint32_t *width, uint32_t *height, | int DvppCommon::GetJpegImageInfo(const void *data, uint32_t dataSize, uint32_t *width, uint32_t *height, | ||||
| int32_t *components) { | |||||
| int32_t *components) { | |||||
| uint32_t widthTmp; | uint32_t widthTmp; | ||||
| uint32_t heightTmp; | uint32_t heightTmp; | ||||
| int32_t componentsTmp; | int32_t componentsTmp; | ||||
| @@ -608,7 +608,7 @@ int DvppCommon::GetJpegImageInfo(const void *data, uint32_t dataSize, uint32_t * | |||||
| * @return: OK if success, other values if failure | * @return: OK if success, other values if failure | ||||
| */ | */ | ||||
| int DvppCommon::GetJpegDecodeDataSize(const void *data, uint32_t dataSize, acldvppPixelFormat format, | int DvppCommon::GetJpegDecodeDataSize(const void *data, uint32_t dataSize, acldvppPixelFormat format, | ||||
| uint32_t *decSize) { | |||||
| uint32_t *decSize) { | |||||
| uint32_t outputSize; | uint32_t outputSize; | ||||
| int ret = acldvppJpegPredictDecSize(data, dataSize, format, &outputSize); | int ret = acldvppJpegPredictDecSize(data, dataSize, format, &outputSize); | ||||
| if (ret != OK) { | if (ret != OK) { | ||||
| @@ -632,7 +632,7 @@ int DvppCommon::CombineJpegdProcess(const RawData& imageInfo, acldvppPixelFormat | |||||
| inputImage_ = std::make_shared<DvppDataInfo>(); | inputImage_ = std::make_shared<DvppDataInfo>(); | ||||
| inputImage_->format = format; | inputImage_->format = format; | ||||
| int ret = GetJpegImageInfo(imageInfo.data.get(), imageInfo.lenOfByte, &(inputImage_->width), &(inputImage_->height), | int ret = GetJpegImageInfo(imageInfo.data.get(), imageInfo.lenOfByte, &(inputImage_->width), &(inputImage_->height), | ||||
| &components); | |||||
| &components); | |||||
| if (ret != OK) { | if (ret != OK) { | ||||
| std::cout << "Failed to get input image info, ret = " << ret << "." << std::endl; | std::cout << "Failed to get input image info, ret = " << ret << "." << std::endl; | ||||
| return ret; | return ret; | ||||
| @@ -59,7 +59,7 @@ int ModelProcess::ModelInference(const std::vector<void *> &inputBufs, | |||||
| if (input == nullptr) { | if (input == nullptr) { | ||||
| return INVALID_POINTER; | return INVALID_POINTER; | ||||
| } | } | ||||
| int ret = 0; | |||||
| int ret; | |||||
| aclmdlDataset *output = nullptr; | aclmdlDataset *output = nullptr; | ||||
| output = CreateAndFillDataset(ouputBufs, outputSizes); | output = CreateAndFillDataset(ouputBufs, outputSizes); | ||||
| @@ -18,6 +18,7 @@ | |||||
| #include <unistd.h> | #include <unistd.h> | ||||
| #include <cstring> | #include <cstring> | ||||
| #include <fstream> | #include <fstream> | ||||
| #include <sstream> | |||||
| #include "../inc/AclProcess.h" | #include "../inc/AclProcess.h" | ||||
| #include "../inc/CommonDataType.h" | #include "../inc/CommonDataType.h" | ||||
| @@ -85,8 +86,8 @@ int main(int argc, char* argv[]) { | |||||
| return ret; | return ret; | ||||
| } | } | ||||
| } else if (is_dir(FLAGS_data_path)) { | } else if (is_dir(FLAGS_data_path)) { | ||||
| struct dirent * filename; | |||||
| DIR * dir; | |||||
| struct dirent *filename; | |||||
| DIR *dir; | |||||
| dir = opendir(FLAGS_data_path.c_str()); | dir = opendir(FLAGS_data_path.c_str()); | ||||
| if (dir == nullptr) { | if (dir == nullptr) { | ||||
| return ERROR; | return ERROR; | ||||
| @@ -109,20 +110,20 @@ int main(int argc, char* argv[]) { | |||||
| double average = 0.0; | double average = 0.0; | ||||
| int infer_cnt = 0; | int infer_cnt = 0; | ||||
| char tmpCh[256]; | |||||
| for (auto iter = costTime_map.begin(); iter != costTime_map.end(); iter++) { | for (auto iter = costTime_map.begin(); iter != costTime_map.end(); iter++) { | ||||
| double diff = 0.0; | double diff = 0.0; | ||||
| diff = iter->second - iter->first; | diff = iter->second - iter->first; | ||||
| average += diff; | average += diff; | ||||
| infer_cnt++; | infer_cnt++; | ||||
| } | } | ||||
| average = average/infer_cnt; | |||||
| memset(tmpCh, 0, sizeof(tmpCh)); | |||||
| snprintf(tmpCh, sizeof(tmpCh), "NN inference cost average time: %4.3f ms of infer_count %d \n", average, infer_cnt); | |||||
| average = average / infer_cnt; | |||||
| std::stringstream timeCost; | |||||
| timeCost << "NN inference cost average time: "<< average << "ms of infer_count " << infer_cnt << std::endl; | |||||
| std::cout << "NN inference cost average time: "<< average << "ms of infer_count " << infer_cnt << std::endl; | std::cout << "NN inference cost average time: "<< average << "ms of infer_count " << infer_cnt << std::endl; | ||||
| std::string file_name = "./time_Result" + std::string("/test_perform_static.txt"); | std::string file_name = "./time_Result" + std::string("/test_perform_static.txt"); | ||||
| std::ofstream file_stream(file_name.c_str(), std::ios::trunc); | std::ofstream file_stream(file_name.c_str(), std::ios::trunc); | ||||
| file_stream << tmpCh; | |||||
| file_stream << timeCost.str(); | |||||
| file_stream.close(); | file_stream.close(); | ||||
| costTime_map.clear(); | costTime_map.clear(); | ||||
| @@ -22,6 +22,7 @@ | |||||
| #include <iosfwd> | #include <iosfwd> | ||||
| #include <vector> | #include <vector> | ||||
| #include <fstream> | #include <fstream> | ||||
| #include <sstream> | |||||
| #include "include/api/model.h" | #include "include/api/model.h" | ||||
| #include "include/api/context.h" | #include "include/api/context.h" | ||||
| @@ -127,7 +128,7 @@ int main(int argc, char **argv) { | |||||
| } | } | ||||
| double average = 0.0; | double average = 0.0; | ||||
| int inferCount = 0; | int inferCount = 0; | ||||
| char tmpCh[256] = {0}; | |||||
| for (auto iter = costTime_map.begin(); iter != costTime_map.end(); iter++) { | for (auto iter = costTime_map.begin(); iter != costTime_map.end(); iter++) { | ||||
| double diff = 0.0; | double diff = 0.0; | ||||
| diff = iter->second - iter->first; | diff = iter->second - iter->first; | ||||
| @@ -135,12 +136,12 @@ int main(int argc, char **argv) { | |||||
| inferCount++; | inferCount++; | ||||
| } | } | ||||
| average = average / inferCount; | average = average / inferCount; | ||||
| snprintf(tmpCh, sizeof(tmpCh), \ | |||||
| "NN inference cost average time: %4.3f ms of infer_count %d \n", average, inferCount); | |||||
| std::stringstream timeCost; | |||||
| timeCost << "NN inference cost average time: "<< average << "ms of infer_count " << inferCount << std::endl; | |||||
| std::cout << "NN inference cost average time: "<< average << "ms of infer_count " << inferCount << std::endl; | std::cout << "NN inference cost average time: "<< average << "ms of infer_count " << inferCount << std::endl; | ||||
| std::string fileName = "./time_Result" + std::string("/test_perform_static.txt"); | std::string fileName = "./time_Result" + std::string("/test_perform_static.txt"); | ||||
| std::ofstream fileStream(fileName.c_str(), std::ios::trunc); | std::ofstream fileStream(fileName.c_str(), std::ios::trunc); | ||||
| fileStream << tmpCh; | |||||
| fileStream << timeCost.str(); | |||||
| fileStream.close(); | fileStream.close(); | ||||
| costTime_map.clear(); | costTime_map.clear(); | ||||
| return 0; | return 0; | ||||
| @@ -22,6 +22,7 @@ | |||||
| #include <iosfwd> | #include <iosfwd> | ||||
| #include <vector> | #include <vector> | ||||
| #include <fstream> | #include <fstream> | ||||
| #include <sstream> | |||||
| #include "include/api/model.h" | #include "include/api/model.h" | ||||
| #include "include/api/context.h" | #include "include/api/context.h" | ||||
| @@ -144,7 +145,7 @@ int main(int argc, char **argv) { | |||||
| } | } | ||||
| double average = 0.0; | double average = 0.0; | ||||
| int inferCount = 0; | int inferCount = 0; | ||||
| char tmpCh[256] = {0}; | |||||
| for (auto iter = costTime_map.begin(); iter != costTime_map.end(); iter++) { | for (auto iter = costTime_map.begin(); iter != costTime_map.end(); iter++) { | ||||
| double diff = 0.0; | double diff = 0.0; | ||||
| diff = iter->second - iter->first; | diff = iter->second - iter->first; | ||||
| @@ -152,12 +153,12 @@ int main(int argc, char **argv) { | |||||
| inferCount++; | inferCount++; | ||||
| } | } | ||||
| average = average / inferCount; | average = average / inferCount; | ||||
| snprintf(tmpCh, sizeof(tmpCh), \ | |||||
| "NN inference cost average time: %4.3f ms of infer_count %d \n", average, inferCount); | |||||
| std::stringstream timeCost; | |||||
| timeCost << "NN inference cost average time: "<< average << "ms of infer_count " << inferCount << std::endl; | |||||
| std::cout << "NN inference cost average time: "<< average << "ms of infer_count " << inferCount << std::endl; | std::cout << "NN inference cost average time: "<< average << "ms of infer_count " << inferCount << std::endl; | ||||
| std::string fileName = "./time_Result" + std::string("/test_perform_static.txt"); | std::string fileName = "./time_Result" + std::string("/test_perform_static.txt"); | ||||
| std::ofstream fileStream(fileName.c_str(), std::ios::trunc); | std::ofstream fileStream(fileName.c_str(), std::ios::trunc); | ||||
| fileStream << tmpCh; | |||||
| fileStream << timeCost.str(); | |||||
| fileStream.close(); | fileStream.close(); | ||||
| costTime_map.clear(); | costTime_map.clear(); | ||||
| return 0; | return 0; | ||||
| @@ -23,6 +23,7 @@ | |||||
| #include <iosfwd> | #include <iosfwd> | ||||
| #include <vector> | #include <vector> | ||||
| #include <fstream> | #include <fstream> | ||||
| #include <sstream> | |||||
| #include "include/api/model.h" | #include "include/api/model.h" | ||||
| #include "include/api/serialization.h" | #include "include/api/serialization.h" | ||||
| @@ -128,7 +129,7 @@ int main(int argc, char **argv) { | |||||
| } | } | ||||
| double average = 0.0; | double average = 0.0; | ||||
| int infer_cnt = 0; | int infer_cnt = 0; | ||||
| char tmpCh[256] = {0}; | |||||
| for (auto iter = costTime_map.begin(); iter != costTime_map.end(); iter++) { | for (auto iter = costTime_map.begin(); iter != costTime_map.end(); iter++) { | ||||
| double diff = 0.0; | double diff = 0.0; | ||||
| diff = iter->second - iter->first; | diff = iter->second - iter->first; | ||||
| @@ -136,11 +137,12 @@ int main(int argc, char **argv) { | |||||
| infer_cnt++; | infer_cnt++; | ||||
| } | } | ||||
| average = average/infer_cnt; | average = average/infer_cnt; | ||||
| snprintf(tmpCh, sizeof(tmpCh), "NN inference cost average time: %4.3f ms of infer_count %d \n", average, infer_cnt); | |||||
| std::stringstream timeCost; | |||||
| timeCost << "NN inference cost average time: "<< average << "ms of infer_count " << infer_cnt << std::endl; | |||||
| std::cout << "NN inference cost average time: "<< average << "ms of infer_count " << infer_cnt << std::endl; | std::cout << "NN inference cost average time: "<< average << "ms of infer_count " << infer_cnt << std::endl; | ||||
| std::string file_name = "./time_Result" + std::string("/test_perform_static.txt"); | std::string file_name = "./time_Result" + std::string("/test_perform_static.txt"); | ||||
| std::ofstream file_stream(file_name.c_str(), std::ios::trunc); | std::ofstream file_stream(file_name.c_str(), std::ios::trunc); | ||||
| file_stream << tmpCh; | |||||
| file_stream << timeCost.str(); | |||||
| file_stream.close(); | file_stream.close(); | ||||
| costTime_map.clear(); | costTime_map.clear(); | ||||
| return 0; | return 0; | ||||
| @@ -23,6 +23,7 @@ | |||||
| #include <iosfwd> | #include <iosfwd> | ||||
| #include <vector> | #include <vector> | ||||
| #include <fstream> | #include <fstream> | ||||
| #include <sstream> | |||||
| #include "include/api/model.h" | #include "include/api/model.h" | ||||
| #include "include/api/serialization.h" | #include "include/api/serialization.h" | ||||
| @@ -133,7 +134,7 @@ int main(int argc, char **argv) { | |||||
| } | } | ||||
| double average = 0.0; | double average = 0.0; | ||||
| int infer_cnt = 0; | int infer_cnt = 0; | ||||
| char tmpCh[256] = {0}; | |||||
| for (auto iter = costTime_map.begin(); iter != costTime_map.end(); iter++) { | for (auto iter = costTime_map.begin(); iter != costTime_map.end(); iter++) { | ||||
| double diff = 0.0; | double diff = 0.0; | ||||
| diff = iter->second - iter->first; | diff = iter->second - iter->first; | ||||
| @@ -141,11 +142,12 @@ int main(int argc, char **argv) { | |||||
| infer_cnt++; | infer_cnt++; | ||||
| } | } | ||||
| average = average/infer_cnt; | average = average/infer_cnt; | ||||
| snprintf(tmpCh, sizeof(tmpCh), "NN inference cost average time: %4.3f ms of infer_count %d \n", average, infer_cnt); | |||||
| std::stringstream timeCost; | |||||
| timeCost << "NN inference cost average time: "<< average << "ms of infer_count " << infer_cnt << std::endl; | |||||
| std::cout << "NN inference cost average time: "<< average << "ms of infer_count " << infer_cnt << std::endl; | std::cout << "NN inference cost average time: "<< average << "ms of infer_count " << infer_cnt << std::endl; | ||||
| std::string file_name = "./time_Result" + std::string("/test_perform_static.txt"); | std::string file_name = "./time_Result" + std::string("/test_perform_static.txt"); | ||||
| std::ofstream file_stream(file_name.c_str(), std::ios::trunc); | std::ofstream file_stream(file_name.c_str(), std::ios::trunc); | ||||
| file_stream << tmpCh; | |||||
| file_stream << timeCost.str(); | |||||
| file_stream.close(); | file_stream.close(); | ||||
| costTime_map.clear(); | costTime_map.clear(); | ||||
| return 0; | return 0; | ||||
| @@ -14,6 +14,8 @@ | |||||
| * limitations under the License. | * limitations under the License. | ||||
| */ | */ | ||||
| #ifndef MINDSPORE_MODEL_ZOO_NAML_MODEL_PROCESS_H_ | |||||
| #define MINDSPORE_MODEL_ZOO_NAML_MODEL_PROCESS_H_ | |||||
| #pragma once | #pragma once | ||||
| #include <iostream> | #include <iostream> | ||||
| #include <map> | #include <map> | ||||
| @@ -45,13 +47,11 @@ class ModelProcess { | |||||
| Result Execute(uint32_t index); | Result Execute(uint32_t index); | ||||
| void DumpModelOutputResult(std::string fileName); | |||||
| void OutputModelResult(); | void OutputModelResult(); | ||||
| Result CreateInput(); | Result CreateInput(); | ||||
| Result CpyFileToDevice(std::string fileName, uint32_t inputNum); | Result CpyFileToDevice(std::string fileName, uint32_t inputNum); | ||||
| void CpyOutputFromDeviceToHost(uint32_t index, uint32_t batchSize); | |||||
| std::map<int, void*> GetResult(); | |||||
| void CpyOutputFromDeviceToHost(uint32_t index); | |||||
| std::map<int, void *> GetResult(); | |||||
| std::vector<uint32_t> GetOutputSize(); | std::vector<uint32_t> GetOutputSize(); | ||||
| std::vector<uint32_t> GetInputSize(); | std::vector<uint32_t> GetInputSize(); | ||||
| Result ExecuteWithFile(uint32_t fileNum); | Result ExecuteWithFile(uint32_t fileNum); | ||||
| @@ -82,9 +82,9 @@ class ModelProcess { | |||||
| uint32_t outputNum_; | uint32_t outputNum_; | ||||
| std::vector<uint32_t> outputBuffSize_; | std::vector<uint32_t> outputBuffSize_; | ||||
| std::map<int, void*> result_; | |||||
| std::vector<void*> resultMem_; | |||||
| std::vector<void*> fileBuffMem_; | |||||
| std::map<int, void *> result_; | |||||
| std::vector<void *> resultMem_; | |||||
| std::vector<void *> fileBuffMem_; | |||||
| std::string inputDataPath_; | std::string inputDataPath_; | ||||
| std::string idFilePath_; | std::string idFilePath_; | ||||
| std::vector<std::vector<void *>> fileBuff_; | std::vector<std::vector<void *>> fileBuff_; | ||||
| @@ -92,3 +92,4 @@ class ModelProcess { | |||||
| std::vector<std::vector<int>> ids_; | std::vector<std::vector<int>> ids_; | ||||
| }; | }; | ||||
| #endif | |||||
| @@ -14,6 +14,9 @@ | |||||
| * limitations under the License. | * limitations under the License. | ||||
| */ | */ | ||||
| #ifndef MINDSPORE_MODEL_ZOO_NAML_SAMPLE_PROCESS_H_ | |||||
| #define MINDSPORE_MODEL_ZOO_NAML_SAMPLE_PROCESS_H_ | |||||
| #pragma once | #pragma once | ||||
| #include <map> | #include <map> | ||||
| #include <memory> | #include <memory> | ||||
| @@ -49,8 +52,8 @@ class SampleProcess { | |||||
| std::vector<std::vector<int>> *usersIds, std::vector<std::vector<int>> *candidateNewsIds); | std::vector<std::vector<int>> *usersIds, std::vector<std::vector<int>> *candidateNewsIds); | ||||
| uint32_t ReadBrowsedData(const std::string &browsedNewsPath); | uint32_t ReadBrowsedData(const std::string &browsedNewsPath); | ||||
| void GetResult(uint32_t startPos, uint32_t endPos, | void GetResult(uint32_t startPos, uint32_t endPos, | ||||
| std::map<int, void*> newsEncodeResult, | |||||
| std::map<int, void*> userEncodeResult); | |||||
| std::map<int, void *> newsEncodeResult, | |||||
| std::map<int, void *> userEncodeResult); | |||||
| private: | private: | ||||
| void DestroyResource(); | void DestroyResource(); | ||||
| @@ -69,3 +72,4 @@ class SampleProcess { | |||||
| std::mutex mtx_; | std::mutex mtx_; | ||||
| }; | }; | ||||
| #endif | |||||
| @@ -14,6 +14,9 @@ | |||||
| * limitations under the License. | * limitations under the License. | ||||
| */ | */ | ||||
| #ifndef MINDSPORE_MODEL_ZOO_NAML_UTILS_H_ | |||||
| #define MINDSPORE_MODEL_ZOO_NAML_UTILS_H_ | |||||
| #pragma once | #pragma once | ||||
| #include <dirent.h> | #include <dirent.h> | ||||
| #include <iostream> | #include <iostream> | ||||
| @@ -49,3 +52,5 @@ class Utils { | |||||
| std::vector<std::vector<int>> *newsId); | std::vector<std::vector<int>> *newsId); | ||||
| }; | }; | ||||
| #pragma once | #pragma once | ||||
| #endif | |||||
| @@ -26,11 +26,20 @@ | |||||
| extern bool g_isDevice; | extern bool g_isDevice; | ||||
| ModelProcess::ModelProcess(const std::string &inputDataPath, const std::string &idFilePath, uint32_t batchSize): | ModelProcess::ModelProcess(const std::string &inputDataPath, const std::string &idFilePath, uint32_t batchSize): | ||||
| modelId_(0), modelMemSize_(0), modelWeightSize_(0), modelMemPtr_(nullptr), | |||||
| modelWeightPtr_(nullptr), loadFlag_(false), modelDesc_(nullptr), output_(nullptr), | |||||
| inputDataPath_(inputDataPath), input_(nullptr), batchSize_(batchSize), | |||||
| idFilePath_(idFilePath), inputNum_(0), outputNum_(0) { | |||||
| } | |||||
| modelId_(0), | |||||
| modelMemSize_(0), | |||||
| modelWeightSize_(0), | |||||
| modelMemPtr_(nullptr), | |||||
| modelWeightPtr_(nullptr), | |||||
| loadFlag_(false), | |||||
| modelDesc_(nullptr), | |||||
| output_(nullptr), | |||||
| inputDataPath_(inputDataPath), | |||||
| input_(nullptr), | |||||
| batchSize_(batchSize), | |||||
| idFilePath_(idFilePath), | |||||
| inputNum_(0), | |||||
| outputNum_(0) {} | |||||
| ModelProcess::~ModelProcess() { | ModelProcess::~ModelProcess() { | ||||
| Unload(); | Unload(); | ||||
| @@ -244,62 +253,6 @@ Result ModelProcess::CreateOutput() { | |||||
| return SUCCESS; | return SUCCESS; | ||||
| } | } | ||||
| void ModelProcess::DumpModelOutputResult(std::string fileName) { | |||||
| std::size_t dex = fileName.find_last_of("."); | |||||
| std::string outputFile = fileName.erase(dex); | |||||
| std::string Path = "../result_Files"; | |||||
| // stringstream ss; | |||||
| size_t outputNum = aclmdlGetDatasetNumBuffers(output_); | |||||
| static int executeNum = 0; | |||||
| for (size_t i = 0; i < outputNum; ++i) { | |||||
| std::stringstream ss; | |||||
| ss << Path <<"/output" << "_" << i << "_in_" << outputFile << ".bin"; | |||||
| std::string outputFileName = ss.str(); | |||||
| FILE *file = fopen(outputFileName.c_str(), "wb"); | |||||
| if (file) { | |||||
| aclDataBuffer* dataBuffer = aclmdlGetDatasetBuffer(output_, i); | |||||
| void* data = aclGetDataBufferAddr(dataBuffer); | |||||
| uint32_t len = aclGetDataBufferSizeV2(dataBuffer); | |||||
| void* outHostData = NULL; | |||||
| aclError ret = ACL_ERROR_NONE; | |||||
| if (!g_isDevice) { | |||||
| ret = aclrtMallocHost(&outHostData, len); | |||||
| if (ret != ACL_ERROR_NONE) { | |||||
| ERROR_LOG("aclrtMallocHost failed, ret[%d]", ret); | |||||
| return; | |||||
| } | |||||
| ret = aclrtMemcpy(outHostData, len, data, len, ACL_MEMCPY_DEVICE_TO_HOST); | |||||
| if (ret != ACL_ERROR_NONE) { | |||||
| ERROR_LOG("aclrtMemcpy failed, ret[%d]", ret); | |||||
| (void)aclrtFreeHost(outHostData); | |||||
| return; | |||||
| } | |||||
| fwrite(outHostData, len, sizeof(char), file); | |||||
| ret = aclrtFreeHost(outHostData); | |||||
| if (ret != ACL_ERROR_NONE) { | |||||
| ERROR_LOG("aclrtFreeHost failed, ret[%d]", ret); | |||||
| return; | |||||
| } | |||||
| } else { | |||||
| fwrite(data, len, sizeof(char), file); | |||||
| } | |||||
| fclose(file); | |||||
| file = nullptr; | |||||
| } else { | |||||
| ERROR_LOG("create output file [%s] failed", outputFileName.c_str()); | |||||
| return; | |||||
| } | |||||
| } | |||||
| INFO_LOG("dump data success"); | |||||
| return; | |||||
| } | |||||
| void ModelProcess::OutputModelResult() { | void ModelProcess::OutputModelResult() { | ||||
| for (size_t i = 0; i < aclmdlGetDatasetNumBuffers(output_); ++i) { | for (size_t i = 0; i < aclmdlGetDatasetNumBuffers(output_); ++i) { | ||||
| aclDataBuffer* dataBuffer = aclmdlGetDatasetBuffer(output_, i); | aclDataBuffer* dataBuffer = aclmdlGetDatasetBuffer(output_, i); | ||||
| @@ -322,9 +275,9 @@ void ModelProcess::OutputModelResult() { | |||||
| return; | return; | ||||
| } | } | ||||
| outData = reinterpret_cast<float*>(outHostData); | |||||
| outData = reinterpret_cast<float *>(outHostData); | |||||
| } else { | } else { | ||||
| outData = reinterpret_cast<float*>(data); | |||||
| outData = reinterpret_cast<float *>(data); | |||||
| } | } | ||||
| std::map<float, unsigned int, std::greater<float> > resultMap; | std::map<float, unsigned int, std::greater<float> > resultMap; | ||||
| for (unsigned int j = 0; j < len / sizeof(float); ++j) { | for (unsigned int j = 0; j < len / sizeof(float); ++j) { | ||||
| @@ -372,12 +325,12 @@ void ModelProcess::DestroyOutput() { | |||||
| Result ModelProcess::CpyFileToDevice(std::string fileName, uint32_t inputNum) { | Result ModelProcess::CpyFileToDevice(std::string fileName, uint32_t inputNum) { | ||||
| uint32_t inputHostBuffSize = 0; | uint32_t inputHostBuffSize = 0; | ||||
| void* inputHostBuff = Utils::ReadBinFile(fileName, &inputHostBuffSize); | |||||
| void *inputHostBuff = Utils::ReadBinFile(fileName, &inputHostBuffSize); | |||||
| if (inputHostBuff == nullptr) { | if (inputHostBuff == nullptr) { | ||||
| return FAILED; | return FAILED; | ||||
| } | } | ||||
| aclDataBuffer *inBufferDev = aclmdlGetDatasetBuffer(input_, inputNum); | aclDataBuffer *inBufferDev = aclmdlGetDatasetBuffer(input_, inputNum); | ||||
| void*p_batchDst = aclGetDataBufferAddr(inBufferDev); | |||||
| void *p_batchDst = aclGetDataBufferAddr(inBufferDev); | |||||
| aclrtMemset(p_batchDst, inputHostBuffSize, 0, inputHostBuffSize); | aclrtMemset(p_batchDst, inputHostBuffSize, 0, inputHostBuffSize); | ||||
| aclError ret = aclrtMemcpy(p_batchDst, inputHostBuffSize, inputHostBuff, inputHostBuffSize, | aclError ret = aclrtMemcpy(p_batchDst, inputHostBuffSize, inputHostBuff, inputHostBuffSize, | ||||
| ACL_MEMCPY_HOST_TO_DEVICE); | ACL_MEMCPY_HOST_TO_DEVICE); | ||||
| @@ -396,7 +349,7 @@ Result ModelProcess::CpyDataToDevice(void *data, uint32_t len, uint32_t inputNum | |||||
| return FAILED; | return FAILED; | ||||
| } | } | ||||
| aclDataBuffer *inBufferDev = aclmdlGetDatasetBuffer(input_, inputNum); | aclDataBuffer *inBufferDev = aclmdlGetDatasetBuffer(input_, inputNum); | ||||
| void*p_batchDst = aclGetDataBufferAddr(inBufferDev); | |||||
| void *p_batchDst = aclGetDataBufferAddr(inBufferDev); | |||||
| aclrtMemset(p_batchDst, len, 0, len); | aclrtMemset(p_batchDst, len, 0, len); | ||||
| aclError ret = aclrtMemcpy(p_batchDst, len, data, len, ACL_MEMCPY_HOST_TO_DEVICE); | aclError ret = aclrtMemcpy(p_batchDst, len, data, len, ACL_MEMCPY_HOST_TO_DEVICE); | ||||
| if (ret != ACL_ERROR_NONE) { | if (ret != ACL_ERROR_NONE) { | ||||
| @@ -407,7 +360,7 @@ Result ModelProcess::CpyDataToDevice(void *data, uint32_t len, uint32_t inputNum | |||||
| return SUCCESS; | return SUCCESS; | ||||
| } | } | ||||
| void ModelProcess::CpyOutputFromDeviceToHost(uint32_t index, uint32_t batchSize) { | |||||
| void ModelProcess::CpyOutputFromDeviceToHost(uint32_t index) { | |||||
| size_t outputNum = aclmdlGetDatasetNumBuffers(output_); | size_t outputNum = aclmdlGetDatasetNumBuffers(output_); | ||||
| for (size_t i = 0; i < outputNum; ++i) { | for (size_t i = 0; i < outputNum; ++i) { | ||||
| @@ -430,8 +383,8 @@ void ModelProcess::CpyOutputFromDeviceToHost(uint32_t index, uint32_t batchSize) | |||||
| return; | return; | ||||
| } | } | ||||
| uint32_t len = (uint32_t)bufferSize/batchSize; | |||||
| for (size_t j = 0; j < batchSize; j++) { | |||||
| uint32_t len = (uint32_t)bufferSize / batchSize_; | |||||
| for (size_t j = 0; j < batchSize_; j++) { | |||||
| result_.emplace(ids_[index][j], reinterpret_cast<uint8_t *>(outHostData) + (j * len)); | result_.emplace(ids_[index][j], reinterpret_cast<uint8_t *>(outHostData) + (j * len)); | ||||
| } | } | ||||
| } | } | ||||
| @@ -448,7 +401,7 @@ std::vector<std::vector<void *>> ModelProcess::ReadInputFiles(std::vector<std::v | |||||
| return buff; | return buff; | ||||
| } | } | ||||
| void* inputHostBuff; | |||||
| void *inputHostBuff = nullptr; | |||||
| uint32_t inputHostBuffSize = 0; | uint32_t inputHostBuffSize = 0; | ||||
| for (int i = 0; i < inputSize; ++i) { | for (int i = 0; i < inputSize; ++i) { | ||||
| for (int j = 0; j < fileNum; ++j) { | for (int j = 0; j < fileNum; ++j) { | ||||
| @@ -491,8 +444,8 @@ Result ModelProcess::ExecuteWithFile(uint32_t fileNum) { | |||||
| double startTime_ms; | double startTime_ms; | ||||
| double endTime_ms; | double endTime_ms; | ||||
| gettimeofday(&start, NULL); | gettimeofday(&start, NULL); | ||||
| void* picDevBuffer = nullptr; | |||||
| int pathIndex = 0; | |||||
| void *picDevBuffer = nullptr; | |||||
| for (auto i = 0; i < inputNum_; ++i) { | for (auto i = 0; i < inputNum_; ++i) { | ||||
| CpyDataToDevice(fileBuff_[i][index], fileSize_[i][index], i); | CpyDataToDevice(fileBuff_[i][index], fileSize_[i][index], i); | ||||
| } | } | ||||
| @@ -503,7 +456,7 @@ Result ModelProcess::ExecuteWithFile(uint32_t fileNum) { | |||||
| return FAILED; | return FAILED; | ||||
| } | } | ||||
| CpyOutputFromDeviceToHost(index, batchSize_); | |||||
| CpyOutputFromDeviceToHost(index); | |||||
| gettimeofday(&end, NULL); | gettimeofday(&end, NULL); | ||||
| startTime_ms = (1.0 * start.tv_sec * 1000000 + start.tv_usec) / 1000; | startTime_ms = (1.0 * start.tv_sec * 1000000 + start.tv_usec) / 1000; | ||||
| endTime_ms = (1.0 * end.tv_sec * 1000000 + end.tv_usec) / 1000; | endTime_ms = (1.0 * end.tv_sec * 1000000 + end.tv_usec) / 1000; | ||||
| @@ -525,7 +478,7 @@ Result ModelProcess::Execute(uint32_t index) { | |||||
| return FAILED; | return FAILED; | ||||
| } | } | ||||
| CpyOutputFromDeviceToHost(index, batchSize_); | |||||
| CpyOutputFromDeviceToHost(index); | |||||
| gettimeofday(&end, NULL); | gettimeofday(&end, NULL); | ||||
| startTime_ms = (1.0 * start.tv_sec * 1000000 + start.tv_usec) / 1000; | startTime_ms = (1.0 * start.tv_sec * 1000000 + start.tv_usec) / 1000; | ||||
| endTime_ms = (1.0 * end.tv_sec * 1000000 + end.tv_usec) / 1000; | endTime_ms = (1.0 * end.tv_sec * 1000000 + end.tv_usec) / 1000; | ||||
| @@ -533,7 +486,7 @@ Result ModelProcess::Execute(uint32_t index) { | |||||
| return SUCCESS; | return SUCCESS; | ||||
| } | } | ||||
| std::map<int, void*> ModelProcess::GetResult() { | |||||
| std::map<int, void *> ModelProcess::GetResult() { | |||||
| return result_; | return result_; | ||||
| } | } | ||||
| @@ -584,15 +537,17 @@ std::string ModelProcess::GetInputDataPath() { | |||||
| std::string ModelProcess::GetCostTimeInfo() { | std::string ModelProcess::GetCostTimeInfo() { | ||||
| double average = 0.0; | double average = 0.0; | ||||
| int infer_cnt = 0; | int infer_cnt = 0; | ||||
| char tmpCh[256] = {0}; | |||||
| for (auto iter = costTime_map_.begin(); iter != costTime_map_.end(); iter++) { | for (auto iter = costTime_map_.begin(); iter != costTime_map_.end(); iter++) { | ||||
| double diff = 0.0; | double diff = 0.0; | ||||
| diff = iter->second - iter->first; | diff = iter->second - iter->first; | ||||
| average += diff; | average += diff; | ||||
| infer_cnt++; | infer_cnt++; | ||||
| } | } | ||||
| average = average/infer_cnt; | |||||
| snprintf(tmpCh, sizeof(tmpCh), "first model latency %4.3f ms; count %d\n", average, infer_cnt); | |||||
| average = average / infer_cnt; | |||||
| std::stringstream timeCost; | |||||
| timeCost << "first model latency "<< average << "ms; count " << infer_cnt << std::endl; | |||||
| return std::string(tmpCh); | |||||
| return timeCost.str(); | |||||
| } | } | ||||
| @@ -25,6 +25,7 @@ | |||||
| #include <unordered_map> | #include <unordered_map> | ||||
| #include <iterator> | #include <iterator> | ||||
| #include <thread> | #include <thread> | ||||
| #include <sstream> | |||||
| #include "acl/acl.h" | #include "acl/acl.h" | ||||
| #include "../inc/utils.h" | #include "../inc/utils.h" | ||||
| @@ -36,7 +37,10 @@ extern bool g_isDevice; | |||||
| SampleProcess::SampleProcess() :deviceId_(0), context_(nullptr), stream_(nullptr), threadNum_(0) {} | SampleProcess::SampleProcess() :deviceId_(0), context_(nullptr), stream_(nullptr), threadNum_(0) {} | ||||
| SampleProcess::SampleProcess(uint32_t deviceId, uint32_t threadNum): | SampleProcess::SampleProcess(uint32_t deviceId, uint32_t threadNum): | ||||
| deviceId_(deviceId), threadNum_(threadNum), context_(nullptr), stream_(nullptr) {} | |||||
| deviceId_(deviceId), | |||||
| threadNum_(threadNum), | |||||
| context_(nullptr), | |||||
| stream_(nullptr) {} | |||||
| SampleProcess::~SampleProcess() { | SampleProcess::~SampleProcess() { | ||||
| DestroyResource(); | DestroyResource(); | ||||
| @@ -145,7 +149,7 @@ Result SampleProcess::Process(const std::vector<std::string> &omPaths, | |||||
| gettimeofday(&totalStart, NULL); | gettimeofday(&totalStart, NULL); | ||||
| modelProcessContainer_[0]->ExecuteWithFile(fileNum); | modelProcessContainer_[0]->ExecuteWithFile(fileNum); | ||||
| std::map<int, void*> result = modelProcessContainer_[0]->GetResult(); | |||||
| std::map<int, void *> result = modelProcessContainer_[0]->GetResult(); | |||||
| std::vector<uint32_t> model1OutputBuffSize = modelProcessContainer_[0]->GetOutputSize(); | std::vector<uint32_t> model1OutputBuffSize = modelProcessContainer_[0]->GetOutputSize(); | ||||
| std::vector<uint32_t> inputBuffSize = modelProcessContainer_[1]->GetInputSize(); | std::vector<uint32_t> inputBuffSize = modelProcessContainer_[1]->GetInputSize(); | ||||
| @@ -164,7 +168,7 @@ Result SampleProcess::Process(const std::vector<std::string> &omPaths, | |||||
| for (int k = 0; k < 50; ++k) { | for (int k = 0; k < 50; ++k) { | ||||
| auto it = result.find(allHistory[i][j][k]); | auto it = result.find(allHistory[i][j][k]); | ||||
| if (it != result.end()) { | if (it != result.end()) { | ||||
| aclrtMemcpy(reinterpret_cast<uint8_t *>(browedNews) + (j*50 + k) * singleDatsSize, singleDatsSize, | |||||
| aclrtMemcpy(reinterpret_cast<uint8_t *>(browedNews) + (j * 50 + k) * singleDatsSize, singleDatsSize, | |||||
| result[allHistory[i][j][k]], singleDatsSize, ACL_MEMCPY_HOST_TO_HOST); | result[allHistory[i][j][k]], singleDatsSize, ACL_MEMCPY_HOST_TO_HOST); | ||||
| } | } | ||||
| } | } | ||||
| @@ -218,8 +222,8 @@ uint32_t SampleProcess::ReadBrowsedData(const std::string &browsedNewsPath) { | |||||
| } | } | ||||
| Result SampleProcess::GetPred(uint32_t fileNum) { | Result SampleProcess::GetPred(uint32_t fileNum) { | ||||
| std::map<int, void*> newsEncodeResult = modelProcessContainer_[0]->GetResult(); | |||||
| std::map<int, void*> userEncodeResult = modelProcessContainer_[1]->GetResult(); | |||||
| std::map<int, void *> newsEncodeResult = modelProcessContainer_[0]->GetResult(); | |||||
| std::map<int, void *> userEncodeResult = modelProcessContainer_[1]->GetResult(); | |||||
| uint32_t perThreadNum = fileNum / threadNum_; | uint32_t perThreadNum = fileNum / threadNum_; | ||||
| std::vector<std::thread> threads; | std::vector<std::thread> threads; | ||||
| @@ -227,7 +231,7 @@ Result SampleProcess::GetPred(uint32_t fileNum) { | |||||
| for (int i = 0; i < threadNum_; ++i) { | for (int i = 0; i < threadNum_; ++i) { | ||||
| if (i != threadNum_ - 1) { | if (i != threadNum_ - 1) { | ||||
| threads.emplace_back(std::thread(&SampleProcess::GetResult, this, | threads.emplace_back(std::thread(&SampleProcess::GetResult, this, | ||||
| i * perThreadNum, (i+1) * perThreadNum, | |||||
| i * perThreadNum, (i + 1) * perThreadNum, | |||||
| newsEncodeResult, | newsEncodeResult, | ||||
| userEncodeResult)); | userEncodeResult)); | ||||
| } else { | } else { | ||||
| @@ -245,8 +249,8 @@ Result SampleProcess::GetPred(uint32_t fileNum) { | |||||
| return SUCCESS; | return SUCCESS; | ||||
| } | } | ||||
| void SampleProcess::GetResult(uint32_t startPos, uint32_t endPos, | void SampleProcess::GetResult(uint32_t startPos, uint32_t endPos, | ||||
| std::map<int, void*> newsEncodeResult, | |||||
| std::map<int, void*> userEncodeResult) { | |||||
| std::map<int, void *> newsEncodeResult, | |||||
| std::map<int, void *> userEncodeResult) { | |||||
| for (int i = startPos; i < endPos; ++i) { | for (int i = startPos; i < endPos; ++i) { | ||||
| std::vector<std::vector<float>> newsCandidate; | std::vector<std::vector<float>> newsCandidate; | ||||
| std::vector<float> userEncodeIds(400); | std::vector<float> userEncodeIds(400); | ||||
| @@ -282,13 +286,13 @@ int SampleProcess::WriteResult(const std::string& imageFile, std::vector<float> | |||||
| for (size_t i = 0; i < 1; ++i) { | for (size_t i = 0; i < 1; ++i) { | ||||
| std::string outFileName = homePath + "/" + name; | std::string outFileName = homePath + "/" + name; | ||||
| try { | try { | ||||
| FILE * outputFile = fopen(outFileName.c_str(), "wb"); | |||||
| fwrite(static_cast<void*>(&result[0]), size, sizeof(char), outputFile); | |||||
| FILE *outputFile = fopen(outFileName.c_str(), "wb"); | |||||
| fwrite(static_cast<void *>(&result[0]), size, sizeof(char), outputFile); | |||||
| fclose(outputFile); | fclose(outputFile); | ||||
| outputFile = nullptr; | outputFile = nullptr; | ||||
| } catch (std::exception &e) { | } catch (std::exception &e) { | ||||
| std::cout << "write result file " << outFileName << " failed, error info: " << e.what() << std::endl; | std::cout << "write result file " << outFileName << " failed, error info: " << e.what() << std::endl; | ||||
| std::exit(1); | |||||
| return FAILED; | |||||
| } | } | ||||
| } | } | ||||
| return SUCCESS; | return SUCCESS; | ||||
| @@ -333,7 +337,7 @@ std::vector<std::string> SampleProcess::GetModelExecCostTimeInfo() { | |||||
| result.emplace_back(modelProcessContainer_[0]->GetCostTimeInfo()); | result.emplace_back(modelProcessContainer_[0]->GetCostTimeInfo()); | ||||
| double secondModelAverage = 0.0; | double secondModelAverage = 0.0; | ||||
| int infer_cnt = 0; | int infer_cnt = 0; | ||||
| char tmpCh[256] = {0}; | |||||
| for (auto iter = secondModelCostTime_map_.begin(); iter != secondModelCostTime_map_.end(); iter++) { | for (auto iter = secondModelCostTime_map_.begin(); iter != secondModelCostTime_map_.end(); iter++) { | ||||
| double diff = 0.0; | double diff = 0.0; | ||||
| diff = iter->second - iter->first; | diff = iter->second - iter->first; | ||||
| @@ -341,14 +345,16 @@ std::vector<std::string> SampleProcess::GetModelExecCostTimeInfo() { | |||||
| infer_cnt++; | infer_cnt++; | ||||
| } | } | ||||
| secondModelAverage = secondModelAverage / infer_cnt; | secondModelAverage = secondModelAverage / infer_cnt; | ||||
| snprintf(tmpCh, sizeof(tmpCh), "second model inference cost average time: %4.3f ms of infer_count %d\n", | |||||
| secondModelAverage, infer_cnt); | |||||
| result.emplace_back(tmpCh); | |||||
| std::stringstream timeCost; | |||||
| timeCost << "second model inference cost average time: "<< secondModelAverage << | |||||
| "ms of infer_count " << infer_cnt << std::endl; | |||||
| result.emplace_back(timeCost.str()); | |||||
| double totalCostTime; | double totalCostTime; | ||||
| totalCostTime = totalCostTime_map_.begin()->second - totalCostTime_map_.begin()->first; | totalCostTime = totalCostTime_map_.begin()->second - totalCostTime_map_.begin()->first; | ||||
| snprintf(tmpCh, sizeof(tmpCh), "total inference cost time: %4.3f ms; count %d\n", totalCostTime, infer_cnt); | |||||
| result.emplace_back(tmpCh); | |||||
| std::stringstream totalTimeCost; | |||||
| totalTimeCost << "total inference cost time: "<< totalCostTime << " ms; count " << infer_cnt << std::endl; | |||||
| result.emplace_back(totalTimeCost.str()); | |||||
| return result; | return result; | ||||
| } | } | ||||
| @@ -171,7 +171,6 @@ std::string Utils::RealPath(std::string path) { | |||||
| char real_path_mem[PATH_MAX] = {0}; | char real_path_mem[PATH_MAX] = {0}; | ||||
| char *real_path_ret = nullptr; | char *real_path_ret = nullptr; | ||||
| real_path_ret = realpath(path.data(), real_path_mem); | real_path_ret = realpath(path.data(), real_path_mem); | ||||
| if (real_path_ret == nullptr) { | if (real_path_ret == nullptr) { | ||||
| std::cout << "File: " << path << " is not exist."; | std::cout << "File: " << path << " is not exist."; | ||||
| return ""; | return ""; | ||||