forked from mindspore-Ecosystem/mindspore
!14921 fix 310 inference codex
From: @yuzhenhua666 Reviewed-by: @oacjiewen,@c_34 Signed-off-by: @c_34
This commit is contained in:
commit
99a5dacdc7
|
@ -22,6 +22,7 @@
|
|||
#include <iosfwd>
|
||||
#include <vector>
|
||||
#include <fstream>
|
||||
#include <sstream>
|
||||
|
||||
#include "include/api/model.h"
|
||||
#include "include/api/context.h"
|
||||
|
@ -136,7 +137,7 @@ int main(int argc, char **argv) {
|
|||
}
|
||||
double average = 0.0;
|
||||
int infer_cnt = 0;
|
||||
char tmpCh[256] = {0};
|
||||
|
||||
for (auto iter = costTime_map.begin(); iter != costTime_map.end(); iter++) {
|
||||
double diff = 0.0;
|
||||
diff = iter->second - iter->first;
|
||||
|
@ -145,11 +146,12 @@ int main(int argc, char **argv) {
|
|||
}
|
||||
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::string file_name = "./time_Result" + std::string("/test_perform_static.txt");
|
||||
std::ofstream file_stream(file_name.c_str(), std::ios::trunc);
|
||||
file_stream << tmpCh;
|
||||
file_stream << timeCost.str();
|
||||
file_stream.close();
|
||||
costTime_map.clear();
|
||||
return 0;
|
||||
|
|
|
@ -23,6 +23,7 @@
|
|||
#include <iosfwd>
|
||||
#include <vector>
|
||||
#include <fstream>
|
||||
#include <sstream>
|
||||
|
||||
#include "../inc/utils.h"
|
||||
#include "minddata/dataset/include/execute.h"
|
||||
|
@ -141,7 +142,7 @@ int main(int argc, char **argv) {
|
|||
}
|
||||
double average = 0.0;
|
||||
int infer_cnt = 0;
|
||||
char tmpCh[256] = {0};
|
||||
|
||||
for (auto iter = costTime_map.begin(); iter != costTime_map.end(); iter++) {
|
||||
double diff = 0.0;
|
||||
diff = iter->second - iter->first;
|
||||
|
@ -151,11 +152,12 @@ int main(int argc, char **argv) {
|
|||
|
||||
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::string file_name = "./time_Result" + std::string("/test_perform_static.txt");
|
||||
std::ofstream file_stream(file_name.c_str(), std::ios::trunc);
|
||||
file_stream << tmpCh;
|
||||
file_stream << timeCost.str();
|
||||
file_stream.close();
|
||||
costTime_map.clear();
|
||||
return 0;
|
||||
|
|
|
@ -118,7 +118,6 @@ std::string RealPath(std::string_view path) {
|
|||
char realPathMem[PATH_MAX] = {0};
|
||||
char *realPathRet = nullptr;
|
||||
realPathRet = realpath(path.data(), realPathMem);
|
||||
|
||||
if (realPathRet == nullptr) {
|
||||
std::cout << "File: " << path << " is not exist.";
|
||||
return "";
|
||||
|
|
|
@ -22,6 +22,7 @@
|
|||
#include <iosfwd>
|
||||
#include <vector>
|
||||
#include <fstream>
|
||||
#include <sstream>
|
||||
|
||||
#include "include/api/context.h"
|
||||
#include "include/api/model.h"
|
||||
|
@ -197,7 +198,7 @@ int main(int argc, char **argv) {
|
|||
}
|
||||
double average = 0.0;
|
||||
int inferCount = 0;
|
||||
char tmpCh[256] = {0};
|
||||
|
||||
for (auto iter = costTime_map.begin(); iter != costTime_map.end(); iter++) {
|
||||
double diff = 0.0;
|
||||
diff = iter->second - iter->first;
|
||||
|
@ -205,12 +206,13 @@ int main(int argc, char **argv) {
|
|||
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::string fileName = "./time_Result" + std::string("/test_perform_static.txt");
|
||||
std::ofstream fileStream(fileName.c_str(), std::ios::trunc);
|
||||
fileStream << tmpCh;
|
||||
fileStream << timeCost.str();
|
||||
fileStream.close();
|
||||
costTime_map.clear();
|
||||
return 0;
|
||||
|
|
|
@ -299,12 +299,14 @@ int AclProcess::ModelInfer(std::map<double, double> *costTime_map) {
|
|||
if (ret != ACL_ERROR_NONE) {
|
||||
std::cout << "aclrtMalloc failed, ret = " << ret << std::endl;
|
||||
aclrtFree(imInfo_dst);
|
||||
free(im_info);
|
||||
return ret;
|
||||
}
|
||||
ret = aclrtMemcpy(reinterpret_cast<uint8_t *>(imInfo_dst), 8, im_info, 8, ACL_MEMCPY_HOST_TO_DEVICE);
|
||||
if (ret != ACL_ERROR_NONE) {
|
||||
std::cout << "aclrtMemcpy failed, ret = " << ret << std::endl;
|
||||
aclrtFree(imInfo_dst);
|
||||
free(im_info);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
@ -318,6 +320,7 @@ int AclProcess::ModelInfer(std::map<double, double> *costTime_map) {
|
|||
ret = modelProcess_->ModelInference(inputBuffers, inputSizes, outputBuffers_, outputSizes_, costTime_map);
|
||||
if (ret != OK) {
|
||||
aclrtFree(imInfo_dst);
|
||||
free(im_info);
|
||||
std::cout << "Failed to execute the classification model, ret = " << ret << "." << std::endl;
|
||||
return ret;
|
||||
}
|
||||
|
@ -327,6 +330,7 @@ int AclProcess::ModelInfer(std::map<double, double> *costTime_map) {
|
|||
std::cout << "aclrtFree image info failed" << std::endl;
|
||||
return ret;
|
||||
}
|
||||
free(im_info);
|
||||
RELEASE_DVPP_DATA(resizeOutData->data);
|
||||
return OK;
|
||||
}
|
||||
|
|
|
@ -59,7 +59,7 @@ int ModelProcess::ModelInference(const std::vector<void *> &inputBufs,
|
|||
if (input == nullptr) {
|
||||
return INVALID_POINTER;
|
||||
}
|
||||
int ret = 0;
|
||||
int ret;
|
||||
|
||||
aclmdlDataset *output = nullptr;
|
||||
output = CreateAndFillDataset(ouputBufs, outputSizes);
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
#include <unistd.h>
|
||||
#include <cstring>
|
||||
#include <fstream>
|
||||
#include <sstream>
|
||||
#include "../inc/AclProcess.h"
|
||||
#include "../inc/CommonDataType.h"
|
||||
|
||||
|
@ -82,6 +83,7 @@ int main(int argc, char* argv[]) {
|
|||
ret = aclProcess.Process(FLAGS_data_path, &costTime_map);
|
||||
if (ret != OK) {
|
||||
std::cout << "model process failed, errno = " << ret << std::endl;
|
||||
aclProcess.Release();
|
||||
return ret;
|
||||
}
|
||||
} else if (is_dir(FLAGS_data_path)) {
|
||||
|
@ -89,6 +91,7 @@ int main(int argc, char* argv[]) {
|
|||
DIR *dir;
|
||||
dir = opendir(FLAGS_data_path.c_str());
|
||||
if (dir == nullptr) {
|
||||
aclProcess.Release();
|
||||
return ERROR;
|
||||
}
|
||||
|
||||
|
@ -100,6 +103,7 @@ int main(int argc, char* argv[]) {
|
|||
ret = aclProcess.Process(wholePath, &costTime_map);
|
||||
if (ret != OK) {
|
||||
std::cout << "model process failed, errno = " << ret << std::endl;
|
||||
aclProcess.Release();
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
@ -109,7 +113,6 @@ int main(int argc, char* argv[]) {
|
|||
|
||||
double average = 0.0;
|
||||
int infer_cnt = 0;
|
||||
char tmpCh[256];
|
||||
for (auto iter = costTime_map.begin(); iter != costTime_map.end(); iter++) {
|
||||
double diff = 0.0;
|
||||
diff = iter->second - iter->first;
|
||||
|
@ -117,12 +120,14 @@ int main(int argc, char* argv[]) {
|
|||
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);
|
||||
|
||||
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::string file_name = "./time_Result" + std::string("/test_perform_static.txt");
|
||||
std::ofstream file_stream(file_name.c_str(), std::ios::trunc);
|
||||
file_stream << tmpCh;
|
||||
file_stream << timeCost.str();
|
||||
file_stream.close();
|
||||
costTime_map.clear();
|
||||
|
||||
|
|
|
@ -59,7 +59,7 @@ int ModelProcess::ModelInference(const std::vector<void *> &inputBufs,
|
|||
if (input == nullptr) {
|
||||
return INVALID_POINTER;
|
||||
}
|
||||
int ret = 0;
|
||||
int ret;
|
||||
|
||||
aclmdlDataset *output = nullptr;
|
||||
output = CreateAndFillDataset(ouputBufs, outputSizes);
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
#include <unistd.h>
|
||||
#include <cstring>
|
||||
#include <fstream>
|
||||
#include <sstream>
|
||||
#include "../inc/AclProcess.h"
|
||||
#include "../inc/CommonDataType.h"
|
||||
|
||||
|
@ -109,7 +110,7 @@ int main(int argc, char* argv[]) {
|
|||
|
||||
double average = 0.0;
|
||||
int infer_cnt = 0;
|
||||
char tmpCh[256];
|
||||
|
||||
for (auto iter = costTime_map.begin(); iter != costTime_map.end(); iter++) {
|
||||
double diff = 0.0;
|
||||
diff = iter->second - iter->first;
|
||||
|
@ -117,12 +118,12 @@ int main(int argc, char* argv[]) {
|
|||
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);
|
||||
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::string file_name = "./time_Result" + std::string("/test_perform_static.txt");
|
||||
std::ofstream file_stream(file_name.c_str(), std::ios::trunc);
|
||||
file_stream << tmpCh;
|
||||
file_stream << timeCost.str();
|
||||
file_stream.close();
|
||||
costTime_map.clear();
|
||||
|
||||
|
|
|
@ -22,6 +22,7 @@
|
|||
#include <iosfwd>
|
||||
#include <vector>
|
||||
#include <fstream>
|
||||
#include <sstream>
|
||||
|
||||
#include "include/api/model.h"
|
||||
#include "include/api/context.h"
|
||||
|
@ -127,7 +128,7 @@ int main(int argc, char **argv) {
|
|||
}
|
||||
double average = 0.0;
|
||||
int inferCount = 0;
|
||||
char tmpCh[256] = {0};
|
||||
|
||||
for (auto iter = costTime_map.begin(); iter != costTime_map.end(); iter++) {
|
||||
double diff = 0.0;
|
||||
diff = iter->second - iter->first;
|
||||
|
@ -135,12 +136,12 @@ int main(int argc, char **argv) {
|
|||
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::string fileName = "./time_Result" + std::string("/test_perform_static.txt");
|
||||
std::ofstream fileStream(fileName.c_str(), std::ios::trunc);
|
||||
fileStream << tmpCh;
|
||||
fileStream << timeCost.str();
|
||||
fileStream.close();
|
||||
costTime_map.clear();
|
||||
return 0;
|
||||
|
|
|
@ -22,6 +22,7 @@
|
|||
#include <iosfwd>
|
||||
#include <vector>
|
||||
#include <fstream>
|
||||
#include <sstream>
|
||||
|
||||
#include "include/api/model.h"
|
||||
#include "include/api/context.h"
|
||||
|
@ -144,7 +145,7 @@ int main(int argc, char **argv) {
|
|||
}
|
||||
double average = 0.0;
|
||||
int inferCount = 0;
|
||||
char tmpCh[256] = {0};
|
||||
|
||||
for (auto iter = costTime_map.begin(); iter != costTime_map.end(); iter++) {
|
||||
double diff = 0.0;
|
||||
diff = iter->second - iter->first;
|
||||
|
@ -152,12 +153,12 @@ int main(int argc, char **argv) {
|
|||
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::string fileName = "./time_Result" + std::string("/test_perform_static.txt");
|
||||
std::ofstream fileStream(fileName.c_str(), std::ios::trunc);
|
||||
fileStream << tmpCh;
|
||||
fileStream << timeCost.str();
|
||||
fileStream.close();
|
||||
costTime_map.clear();
|
||||
return 0;
|
||||
|
|
|
@ -23,6 +23,7 @@
|
|||
#include <iosfwd>
|
||||
#include <vector>
|
||||
#include <fstream>
|
||||
#include <sstream>
|
||||
|
||||
#include "include/api/model.h"
|
||||
#include "include/api/serialization.h"
|
||||
|
@ -128,7 +129,7 @@ int main(int argc, char **argv) {
|
|||
}
|
||||
double average = 0.0;
|
||||
int infer_cnt = 0;
|
||||
char tmpCh[256] = {0};
|
||||
|
||||
for (auto iter = costTime_map.begin(); iter != costTime_map.end(); iter++) {
|
||||
double diff = 0.0;
|
||||
diff = iter->second - iter->first;
|
||||
|
@ -136,11 +137,12 @@ int main(int argc, char **argv) {
|
|||
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::string file_name = "./time_Result" + std::string("/test_perform_static.txt");
|
||||
std::ofstream file_stream(file_name.c_str(), std::ios::trunc);
|
||||
file_stream << tmpCh;
|
||||
file_stream << timeCost.str();
|
||||
file_stream.close();
|
||||
costTime_map.clear();
|
||||
return 0;
|
||||
|
|
|
@ -23,6 +23,7 @@
|
|||
#include <iosfwd>
|
||||
#include <vector>
|
||||
#include <fstream>
|
||||
#include <sstream>
|
||||
|
||||
#include "include/api/model.h"
|
||||
#include "include/api/serialization.h"
|
||||
|
@ -133,7 +134,7 @@ int main(int argc, char **argv) {
|
|||
}
|
||||
double average = 0.0;
|
||||
int infer_cnt = 0;
|
||||
char tmpCh[256] = {0};
|
||||
|
||||
for (auto iter = costTime_map.begin(); iter != costTime_map.end(); iter++) {
|
||||
double diff = 0.0;
|
||||
diff = iter->second - iter->first;
|
||||
|
@ -141,11 +142,12 @@ int main(int argc, char **argv) {
|
|||
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::string file_name = "./time_Result" + std::string("/test_perform_static.txt");
|
||||
std::ofstream file_stream(file_name.c_str(), std::ios::trunc);
|
||||
file_stream << tmpCh;
|
||||
file_stream << timeCost.str();
|
||||
file_stream.close();
|
||||
costTime_map.clear();
|
||||
return 0;
|
||||
|
|
|
@ -14,6 +14,8 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef MINDSPORE_MODEL_ZOO_NAML_MODEL_PROCESS_H_
|
||||
#define MINDSPORE_MODEL_ZOO_NAML_MODEL_PROCESS_H_
|
||||
#pragma once
|
||||
#include <iostream>
|
||||
#include <map>
|
||||
|
@ -45,12 +47,10 @@ class ModelProcess {
|
|||
|
||||
Result Execute(uint32_t index);
|
||||
|
||||
void DumpModelOutputResult(std::string fileName);
|
||||
|
||||
void OutputModelResult();
|
||||
Result CreateInput();
|
||||
Result CpyFileToDevice(std::string fileName, uint32_t inputNum);
|
||||
void CpyOutputFromDeviceToHost(uint32_t index, uint32_t batchSize);
|
||||
void CpyOutputFromDeviceToHost(uint32_t index);
|
||||
std::map<int, void *> GetResult();
|
||||
std::vector<uint32_t> GetOutputSize();
|
||||
std::vector<uint32_t> GetInputSize();
|
||||
|
@ -92,3 +92,4 @@ class ModelProcess {
|
|||
std::vector<std::vector<int>> ids_;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -14,6 +14,9 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef MINDSPORE_MODEL_ZOO_NAML_SAMPLE_PROCESS_H_
|
||||
#define MINDSPORE_MODEL_ZOO_NAML_SAMPLE_PROCESS_H_
|
||||
|
||||
#pragma once
|
||||
#include <map>
|
||||
#include <memory>
|
||||
|
@ -69,3 +72,4 @@ class SampleProcess {
|
|||
std::mutex mtx_;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -14,6 +14,9 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef MINDSPORE_MODEL_ZOO_NAML_UTILS_H_
|
||||
#define MINDSPORE_MODEL_ZOO_NAML_UTILS_H_
|
||||
|
||||
#pragma once
|
||||
#include <dirent.h>
|
||||
#include <iostream>
|
||||
|
@ -49,3 +52,5 @@ class Utils {
|
|||
std::vector<std::vector<int>> *newsId);
|
||||
};
|
||||
#pragma once
|
||||
|
||||
#endif
|
||||
|
|
|
@ -26,11 +26,20 @@
|
|||
extern bool g_isDevice;
|
||||
|
||||
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() {
|
||||
Unload();
|
||||
|
@ -244,62 +253,6 @@ Result ModelProcess::CreateOutput() {
|
|||
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() {
|
||||
for (size_t i = 0; i < aclmdlGetDatasetNumBuffers(output_); ++i) {
|
||||
aclDataBuffer* dataBuffer = aclmdlGetDatasetBuffer(output_, i);
|
||||
|
@ -407,7 +360,7 @@ Result ModelProcess::CpyDataToDevice(void *data, uint32_t len, uint32_t inputNum
|
|||
return SUCCESS;
|
||||
}
|
||||
|
||||
void ModelProcess::CpyOutputFromDeviceToHost(uint32_t index, uint32_t batchSize) {
|
||||
void ModelProcess::CpyOutputFromDeviceToHost(uint32_t index) {
|
||||
size_t outputNum = aclmdlGetDatasetNumBuffers(output_);
|
||||
|
||||
for (size_t i = 0; i < outputNum; ++i) {
|
||||
|
@ -430,8 +383,8 @@ void ModelProcess::CpyOutputFromDeviceToHost(uint32_t index, uint32_t batchSize)
|
|||
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));
|
||||
}
|
||||
}
|
||||
|
@ -448,7 +401,7 @@ std::vector<std::vector<void *>> ModelProcess::ReadInputFiles(std::vector<std::v
|
|||
return buff;
|
||||
}
|
||||
|
||||
void* inputHostBuff;
|
||||
void *inputHostBuff = nullptr;
|
||||
uint32_t inputHostBuffSize = 0;
|
||||
for (int i = 0; i < inputSize; ++i) {
|
||||
for (int j = 0; j < fileNum; ++j) {
|
||||
|
@ -492,7 +445,7 @@ Result ModelProcess::ExecuteWithFile(uint32_t fileNum) {
|
|||
double endTime_ms;
|
||||
gettimeofday(&start, NULL);
|
||||
void *picDevBuffer = nullptr;
|
||||
int pathIndex = 0;
|
||||
|
||||
for (auto i = 0; i < inputNum_; ++i) {
|
||||
CpyDataToDevice(fileBuff_[i][index], fileSize_[i][index], i);
|
||||
}
|
||||
|
@ -503,7 +456,7 @@ Result ModelProcess::ExecuteWithFile(uint32_t fileNum) {
|
|||
return FAILED;
|
||||
}
|
||||
|
||||
CpyOutputFromDeviceToHost(index, batchSize_);
|
||||
CpyOutputFromDeviceToHost(index);
|
||||
gettimeofday(&end, NULL);
|
||||
startTime_ms = (1.0 * start.tv_sec * 1000000 + start.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;
|
||||
}
|
||||
|
||||
CpyOutputFromDeviceToHost(index, batchSize_);
|
||||
CpyOutputFromDeviceToHost(index);
|
||||
gettimeofday(&end, NULL);
|
||||
startTime_ms = (1.0 * start.tv_sec * 1000000 + start.tv_usec) / 1000;
|
||||
endTime_ms = (1.0 * end.tv_sec * 1000000 + end.tv_usec) / 1000;
|
||||
|
@ -584,7 +537,7 @@ std::string ModelProcess::GetInputDataPath() {
|
|||
std::string ModelProcess::GetCostTimeInfo() {
|
||||
double average = 0.0;
|
||||
int infer_cnt = 0;
|
||||
char tmpCh[256] = {0};
|
||||
|
||||
for (auto iter = costTime_map_.begin(); iter != costTime_map_.end(); iter++) {
|
||||
double diff = 0.0;
|
||||
diff = iter->second - iter->first;
|
||||
|
@ -592,7 +545,9 @@ std::string ModelProcess::GetCostTimeInfo() {
|
|||
infer_cnt++;
|
||||
}
|
||||
average = average / infer_cnt;
|
||||
snprintf(tmpCh, sizeof(tmpCh), "first model latency %4.3f ms; count %d\n", average, infer_cnt);
|
||||
|
||||
return std::string(tmpCh);
|
||||
std::stringstream timeCost;
|
||||
timeCost << "first model latency "<< average << "ms; count " << infer_cnt << std::endl;
|
||||
|
||||
return timeCost.str();
|
||||
}
|
||||
|
|
|
@ -25,6 +25,7 @@
|
|||
#include <unordered_map>
|
||||
#include <iterator>
|
||||
#include <thread>
|
||||
#include <sstream>
|
||||
|
||||
#include "acl/acl.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(uint32_t deviceId, uint32_t threadNum):
|
||||
deviceId_(deviceId), threadNum_(threadNum), context_(nullptr), stream_(nullptr) {}
|
||||
deviceId_(deviceId),
|
||||
threadNum_(threadNum),
|
||||
context_(nullptr),
|
||||
stream_(nullptr) {}
|
||||
|
||||
SampleProcess::~SampleProcess() {
|
||||
DestroyResource();
|
||||
|
@ -288,7 +292,7 @@ int SampleProcess::WriteResult(const std::string& imageFile, std::vector<float>
|
|||
outputFile = nullptr;
|
||||
} catch (std::exception &e) {
|
||||
std::cout << "write result file " << outFileName << " failed, error info: " << e.what() << std::endl;
|
||||
std::exit(1);
|
||||
return FAILED;
|
||||
}
|
||||
}
|
||||
return SUCCESS;
|
||||
|
@ -333,7 +337,7 @@ std::vector<std::string> SampleProcess::GetModelExecCostTimeInfo() {
|
|||
result.emplace_back(modelProcessContainer_[0]->GetCostTimeInfo());
|
||||
double secondModelAverage = 0.0;
|
||||
int infer_cnt = 0;
|
||||
char tmpCh[256] = {0};
|
||||
|
||||
for (auto iter = secondModelCostTime_map_.begin(); iter != secondModelCostTime_map_.end(); iter++) {
|
||||
double diff = 0.0;
|
||||
diff = iter->second - iter->first;
|
||||
|
@ -341,14 +345,16 @@ std::vector<std::string> SampleProcess::GetModelExecCostTimeInfo() {
|
|||
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;
|
||||
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;
|
||||
}
|
||||
|
|
|
@ -171,7 +171,6 @@ std::string Utils::RealPath(std::string path) {
|
|||
char real_path_mem[PATH_MAX] = {0};
|
||||
char *real_path_ret = nullptr;
|
||||
real_path_ret = realpath(path.data(), real_path_mem);
|
||||
|
||||
if (real_path_ret == nullptr) {
|
||||
std::cout << "File: " << path << " is not exist.";
|
||||
return "";
|
||||
|
|
Loading…
Reference in New Issue