Executable → Regular
+24
-25
@@ -1,22 +1,21 @@
|
|||||||
//Model_process.h
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @file model_process.h
|
* @file model_process.h
|
||||||
*
|
*
|
||||||
* Copyright (C) 2020. Huawei Technologies Co., Ltd. All rights reserved.
|
* Copyright (C) 2020. Huawei Technologies Co., Ltd. All rights reserved.
|
||||||
*
|
*
|
||||||
* This program is distributed in the hope that it will be useful,
|
* This program is distributed in the hope that it will be useful,
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
*/
|
*/
|
||||||
#pragma once
|
#ifndef _MODEL_PROCESS_H_
|
||||||
#include "utils.h"
|
#define _MODEL_PROCESS_H_
|
||||||
#include "acl/acl.h"
|
#include "acl/acl.h"
|
||||||
|
#include "utils.h"
|
||||||
|
#include <string>
|
||||||
|
|
||||||
using namespace std;
|
|
||||||
/**
|
/**
|
||||||
* ModelProcess
|
* ModelProcess
|
||||||
*/
|
*/
|
||||||
class ModelProcess {
|
class ModelProcess {
|
||||||
public:
|
public:
|
||||||
/**
|
/**
|
||||||
@@ -34,7 +33,7 @@ public:
|
|||||||
* @param [in] modelPath: model path
|
* @param [in] modelPath: model path
|
||||||
* @return result
|
* @return result
|
||||||
*/
|
*/
|
||||||
Result LoadModelFromFileWithMem(const char *modelPath);
|
Result LoadModelFromFileWithMem(const std::string& modelPath);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief unload model
|
* @brief unload model
|
||||||
@@ -63,9 +62,9 @@ public:
|
|||||||
* @param [in] bufferSize: input buffer size
|
* @param [in] bufferSize: input buffer size
|
||||||
* @return result
|
* @return result
|
||||||
*/
|
*/
|
||||||
Result CreateInput(void *inputDataBuffer, size_t bufferSize);
|
Result CreateInput(void* inputDataBuffer, size_t bufferSize);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief create model input
|
* @brief create model input
|
||||||
* @return result
|
* @return result
|
||||||
*/
|
*/
|
||||||
@@ -101,19 +100,19 @@ public:
|
|||||||
/**
|
/**
|
||||||
* @brief get model output result
|
* @brief get model output result
|
||||||
*/
|
*/
|
||||||
void OutputModelResult(std::string& s,std::string& modelName,size_t index);
|
void OutputModelResult(std::string& s, std::string& modelName, size_t index);
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
uint32_t modelId_;
|
uint32_t modelId_;
|
||||||
size_t modelMemSize_;
|
size_t modelMemSize_;
|
||||||
size_t modelWeightSize_;
|
size_t modelWeightSize_;
|
||||||
void *modelMemPtr_;
|
void* modelMemPtr_;
|
||||||
void *modelWeightPtr_;
|
void* modelWeightPtr_;
|
||||||
bool loadFlag_; // model load flag
|
bool loadFlag_; // model load flag
|
||||||
aclmdlDesc *modelDesc_;
|
aclmdlDesc* modelDesc_;
|
||||||
aclmdlDataset *input_;
|
aclmdlDataset* input_;
|
||||||
aclmdlDataset *output_;
|
aclmdlDataset* output_;
|
||||||
size_t numInputs_;
|
size_t numInputs_;
|
||||||
size_t numOutputs_;
|
size_t numOutputs_;
|
||||||
};
|
};
|
||||||
|
#endif
|
||||||
Executable → Regular
+5
-6
@@ -1,5 +1,3 @@
|
|||||||
//Sample_process.h
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @file sample_process.h
|
* @file sample_process.h
|
||||||
*
|
*
|
||||||
@@ -9,12 +7,12 @@
|
|||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
*/
|
*/
|
||||||
#pragma once
|
#ifndef _SAMPLE_PROCESS_H_
|
||||||
#include "utils.h"
|
#define _SAMPLE_PROCESS_H_
|
||||||
#include "acl/acl.h"
|
#include "acl/acl.h"
|
||||||
|
#include "utils.h"
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
using namespace std;
|
|
||||||
/**
|
/**
|
||||||
* SampleProcess
|
* SampleProcess
|
||||||
*/
|
*/
|
||||||
@@ -40,7 +38,7 @@ public:
|
|||||||
* @brief sample process
|
* @brief sample process
|
||||||
* @return result
|
* @return result
|
||||||
*/
|
*/
|
||||||
Result Process(map<char,string>& params, vector<string>& inputs);
|
Result Process(std::map<char, std::string>& params, std::vector<std::string>& inputs);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void DestroyResource();
|
void DestroyResource();
|
||||||
@@ -49,3 +47,4 @@ private:
|
|||||||
aclrtContext context_;
|
aclrtContext context_;
|
||||||
aclrtStream stream_;
|
aclrtStream stream_;
|
||||||
};
|
};
|
||||||
|
#endif
|
||||||
|
|||||||
Executable → Regular
+26
-29
@@ -1,5 +1,3 @@
|
|||||||
//Util.h
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @file utils.h
|
* @file utils.h
|
||||||
*
|
*
|
||||||
@@ -9,36 +7,35 @@
|
|||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
*/
|
*/
|
||||||
#pragma once
|
#ifndef _UTILS_H_
|
||||||
#include <iostream>
|
#define _UTILS_H_
|
||||||
#include <sstream>
|
|
||||||
#include <fstream>
|
|
||||||
#include <cstring>
|
|
||||||
#include <string>
|
|
||||||
#include <map>
|
|
||||||
#include <vector>
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <stdio.h>
|
|
||||||
#include <time.h>
|
|
||||||
#include <sys/time.h>
|
|
||||||
#include <dirent.h>
|
|
||||||
#include <sys/types.h>
|
|
||||||
#include <sys/stat.h>
|
|
||||||
#include <cstddef>
|
#include <cstddef>
|
||||||
|
#include <cstring>
|
||||||
|
#include <dirent.h>
|
||||||
|
#include <fstream>
|
||||||
|
#include <iostream>
|
||||||
|
#include <map>
|
||||||
|
#include <sstream>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <string>
|
||||||
|
#include <sys/stat.h>
|
||||||
|
#include <sys/time.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <time.h>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
#define INFO_LOG(fmt, args...) fprintf(stdout, "[INFO] " fmt "\n", ##args)
|
#define INFO_LOG(fmt, args...) fprintf(stdout, "[INFO] " fmt "\n", ##args)
|
||||||
#define DEBUG_LOG(fmt, args...) fprintf(stdout, "[DEBUG] " fmt "\n", ##args)
|
#define DEBUG_LOG(fmt, args...) fprintf(stdout, "[DEBUG] " fmt "\n", ##args)
|
||||||
#define WARN_LOG(fmt, args...) fprintf(stdout, "[WARN] " fmt "\n", ##args)
|
#define WARN_LOG(fmt, args...) fprintf(stdout, "[WARN] " fmt "\n", ##args)
|
||||||
#define ERROR_LOG(fmt, args...) fprintf(stdout, "[ERROR] " fmt "\n", ##args)
|
#define ERROR_LOG(fmt, args...) fprintf(stdout, "[ERROR] " fmt "\n", ##args)
|
||||||
|
|
||||||
using namespace std;
|
|
||||||
//static size_t loop = 1;
|
//static size_t loop = 1;
|
||||||
typedef enum Result {
|
typedef enum Result {
|
||||||
SUCCESS = 0,
|
SUCCESS = 0,
|
||||||
FAILED = 1
|
FAILED = 1
|
||||||
} Result;
|
} Result;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Utils
|
* Utils
|
||||||
*/
|
*/
|
||||||
@@ -50,7 +47,7 @@ public:
|
|||||||
* @param [out] fileSize: size of file
|
* @param [out] fileSize: size of file
|
||||||
* @return device buffer of file
|
* @return device buffer of file
|
||||||
*/
|
*/
|
||||||
static void *GetDeviceBufferOfFile(std::string fileName, uint32_t &fileSize);
|
static void* GetDeviceBufferOfFile(std::string fileName, uint32_t& fileSize);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief create buffer of file
|
* @brief create buffer of file
|
||||||
@@ -62,25 +59,25 @@ public:
|
|||||||
|
|
||||||
static void SplitString(std::string& s, std::vector<std::string>& v, char c);
|
static void SplitString(std::string& s, std::vector<std::string>& v, char c);
|
||||||
|
|
||||||
static int str2num(char *str);
|
static int str2num(char* str);
|
||||||
|
|
||||||
static std::string modelName(string& s);
|
static std::string modelName(std::string& s);
|
||||||
|
|
||||||
static std::string TimeLine();
|
static std::string TimeLine();
|
||||||
|
|
||||||
static void printCurrentTime();
|
static void printCurrentTime();
|
||||||
|
|
||||||
static void printHelpLetter();
|
static void printHelpLetter();
|
||||||
|
|
||||||
static double printDiffTime(time_t begin, time_t end);
|
static double printDiffTime(time_t begin, time_t end);
|
||||||
|
|
||||||
static double InferenceTimeAverage(double *x, int len);
|
static double InferenceTimeAverage(double* x, int len);
|
||||||
|
|
||||||
static double InferenceTimeAverageWithoutFirst(double *x, int len);
|
static double InferenceTimeAverageWithoutFirst(double* x, int len);
|
||||||
|
|
||||||
static void ProfilerJson(bool isprof, map<char,string>& params);
|
static void ProfilerJson(bool isprof, std::map<char, std::string>& params);
|
||||||
|
|
||||||
static void DumpJson(bool isdump, map<char,string>& params);
|
static void DumpJson(bool isdump, std::map<char, std::string>& params);
|
||||||
};
|
};
|
||||||
|
|
||||||
#pragma once
|
#endif
|
||||||
|
|||||||
Executable → Regular
+41
-57
@@ -10,10 +10,9 @@
|
|||||||
*/
|
*/
|
||||||
#include "sample_process.h"
|
#include "sample_process.h"
|
||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
#include<getopt.h>
|
#include <getopt.h>
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
|
|
||||||
bool f_isTXT = false;
|
bool f_isTXT = false;
|
||||||
bool g_isDevice = false;
|
bool g_isDevice = false;
|
||||||
int loop = 1;
|
int loop = 1;
|
||||||
@@ -25,54 +24,46 @@ string input_Ftype = ".bin";
|
|||||||
string model_Ftype = ".om";
|
string model_Ftype = ".om";
|
||||||
string check = "";
|
string check = "";
|
||||||
|
|
||||||
void InitAndCheckParams(int argc, char* argv[], map<char,string>& params, vector<string>& inputs)
|
void InitAndCheckParams(int argc, char* argv[], map<char, string>& params, vector<string>& inputs)
|
||||||
//void InitAndCheckParams(int argc, char* argv[], vector<string>& params, vector<string>& inputs)
|
|
||||||
{
|
{
|
||||||
const char *optstring="m::i::o::f::hd::p::l::y::e::g::";
|
const char* optstring = "m::i::o::f::hd::p::l::y::e::g::";
|
||||||
int c,deb,index;
|
int c, deb, index;
|
||||||
struct option opts[]={{"model",required_argument,NULL,'m'},
|
struct option opts[] = { { "model", required_argument, NULL, 'm' },
|
||||||
{"input",required_argument,NULL,'i'},
|
{ "input", required_argument, NULL, 'i' },
|
||||||
{"output",required_argument,NULL,'o'},
|
{ "output", required_argument, NULL, 'o' },
|
||||||
{"outfmt",required_argument,NULL,'f'},
|
{ "outfmt", required_argument, NULL, 'f' },
|
||||||
{"help",no_argument,NULL,1},
|
{ "help", no_argument, NULL, 1 },
|
||||||
{"dump",required_argument,NULL,'d'},
|
{ "dump", required_argument, NULL, 'd' },
|
||||||
{"profiler",required_argument,NULL,'p'},
|
{ "profiler", required_argument, NULL, 'p' },
|
||||||
{"loop",required_argument,NULL,'l'},
|
{ "loop", required_argument, NULL, 'l' },
|
||||||
{"dymBatch",required_argument,NULL,'y'},
|
{ "dymBatch", required_argument, NULL, 'y' },
|
||||||
{"device",required_argument,NULL,'e'},
|
{ "device", required_argument, NULL, 'e' },
|
||||||
{"debug",required_argument,NULL,'g'},
|
{ "debug", required_argument, NULL, 'g' },
|
||||||
{0,0,0,0}};
|
{ 0, 0, 0, 0 } };
|
||||||
while((c=getopt_long(argc,argv,optstring,opts,&index))!=-1)
|
while ((c = getopt_long(argc, argv, optstring, opts, &index)) != -1) {
|
||||||
{
|
switch (c) {
|
||||||
switch(c)
|
|
||||||
{
|
|
||||||
case 'm':
|
case 'm':
|
||||||
check = optarg;
|
check = optarg;
|
||||||
if (check.find(model_Ftype) != string::npos){
|
if (check.find(model_Ftype) != string::npos) {
|
||||||
// params.push_back(optarg);
|
|
||||||
params['m'] = optarg;
|
params['m'] = optarg;
|
||||||
break;
|
break;
|
||||||
}
|
} else {
|
||||||
else {
|
printf("input model file type is not .om , please check your model type!\n");
|
||||||
printf("input model file type is not .om , please check your model type!\n");
|
exit(0);
|
||||||
exit(0);
|
}
|
||||||
}
|
|
||||||
case 'i':
|
case 'i':
|
||||||
check = optarg;
|
check = optarg;
|
||||||
if (check.find(input_Ftype) == string::npos){
|
if (check.find(input_Ftype) == string::npos) {
|
||||||
printf("input data file type is not .bin , please check your input file type!\n");
|
printf("input data file type is not .bin , please check your input file type!\n");
|
||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
// params.push_back(optarg);
|
|
||||||
params['i'] = optarg;
|
params['i'] = optarg;
|
||||||
Utils::SplitString(params['i'], inputs, ',');
|
Utils::SplitString(params['i'], inputs, ',');
|
||||||
break;
|
break;
|
||||||
case 'o':
|
case 'o':
|
||||||
// params.push_back(optarg);
|
|
||||||
params['o'] = optarg;
|
params['o'] = optarg;
|
||||||
break;
|
break;
|
||||||
case 'f':
|
case 'f':
|
||||||
// params.push_back(optarg);
|
|
||||||
params['f'] = optarg;
|
params['f'] = optarg;
|
||||||
break;
|
break;
|
||||||
case '?':
|
case '?':
|
||||||
@@ -81,34 +72,29 @@ void InitAndCheckParams(int argc, char* argv[], map<char,string>& params, vector
|
|||||||
Utils::printHelpLetter();
|
Utils::printHelpLetter();
|
||||||
exit(0);
|
exit(0);
|
||||||
case 'd':
|
case 'd':
|
||||||
// params.push_back(optarg);
|
|
||||||
params['d'] = optarg;
|
params['d'] = optarg;
|
||||||
break;
|
break;
|
||||||
case 'p':
|
case 'p':
|
||||||
// params.push_back(optarg);
|
|
||||||
params['p'] = optarg;
|
params['p'] = optarg;
|
||||||
break;
|
break;
|
||||||
case 'l':
|
case 'l':
|
||||||
loop = Utils::str2num(optarg);
|
loop = Utils::str2num(optarg);
|
||||||
cout << "loop:" << loop << endl;
|
cout << "loop:" << loop << endl;
|
||||||
if (loop > 100 || loop < 1)
|
if (loop > 100 || loop < 1) {
|
||||||
{
|
printf("loop must in 1 to 100\n");
|
||||||
printf("loop must in 1 to 100\n");
|
exit(0);
|
||||||
exit(0);
|
}
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
case 'y':
|
case 'y':
|
||||||
// params.push_back(optarg);
|
|
||||||
params['y'] = optarg;
|
params['y'] = optarg;
|
||||||
break;
|
break;
|
||||||
case 'e':
|
case 'e':
|
||||||
device = Utils::str2num(optarg);
|
device = Utils::str2num(optarg);
|
||||||
cout << "device:" << device << endl;
|
cout << "device:" << device << endl;
|
||||||
if (device > 255 || device < 0)
|
if (device > 255 || device < 0) {
|
||||||
{
|
printf("device id must in 0 to 255\n");
|
||||||
printf("device id must in 0 to 255\n");
|
exit(0);
|
||||||
exit(0);
|
}
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
case 'g':
|
case 'g':
|
||||||
params['g'] = optarg;
|
params['g'] = optarg;
|
||||||
@@ -127,14 +113,12 @@ void InitAndCheckParams(int argc, char* argv[], map<char,string>& params, vector
|
|||||||
|
|
||||||
int main(int argc, char* argv[])
|
int main(int argc, char* argv[])
|
||||||
{
|
{
|
||||||
map<char,string>params;
|
map<char, string> params;
|
||||||
// vector<string> params;
|
|
||||||
vector<string> inputs;
|
vector<string> inputs;
|
||||||
InitAndCheckParams(argc, argv, params, inputs);
|
InitAndCheckParams(argc, argv, params, inputs);
|
||||||
printf("******************************\n");
|
printf("******************************\n");
|
||||||
printf("Test Start!\n");
|
printf("Test Start!\n");
|
||||||
|
|
||||||
|
|
||||||
if (params.empty()) {
|
if (params.empty()) {
|
||||||
printf("Invalid params.\n");
|
printf("Invalid params.\n");
|
||||||
printf("Execute sample failed.\n");
|
printf("Execute sample failed.\n");
|
||||||
@@ -151,7 +135,7 @@ int main(int argc, char* argv[])
|
|||||||
if (params['g'].compare("true") == 0) {
|
if (params['g'].compare("true") == 0) {
|
||||||
is_debug = true;
|
is_debug = true;
|
||||||
}
|
}
|
||||||
if (is_profi && is_dump){
|
if (is_profi && is_dump) {
|
||||||
ERROR_LOG("dump and profiler can not both be true");
|
ERROR_LOG("dump and profiler can not both be true");
|
||||||
return FAILED;
|
return FAILED;
|
||||||
}
|
}
|
||||||
|
|||||||
Executable → Regular
+251
-317
@@ -1,4 +1,4 @@
|
|||||||
//Model_procccess.cpp
|
// Model_procccess.cpp
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @file model_process.cpp
|
* @file model_process.cpp
|
||||||
@@ -11,18 +11,27 @@
|
|||||||
*/
|
*/
|
||||||
#include "model_process.h"
|
#include "model_process.h"
|
||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
#include <sys/types.h>
|
|
||||||
#include <sys/stat.h>
|
|
||||||
#include <dirent.h>
|
|
||||||
#include <cstddef>
|
#include <cstddef>
|
||||||
|
#include <dirent.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
extern bool g_isDevice;
|
extern bool g_isDevice;
|
||||||
extern bool f_isTXT;
|
extern bool f_isTXT;
|
||||||
|
|
||||||
ModelProcess::ModelProcess() :modelId_(0), modelMemSize_(0), modelWeightSize_(0), modelMemPtr_(nullptr),
|
ModelProcess::ModelProcess()
|
||||||
modelWeightPtr_(nullptr), loadFlag_(false), modelDesc_(nullptr), input_(nullptr), output_(nullptr), numInputs_(0),
|
: modelId_(0)
|
||||||
numOutputs_(0)
|
, modelMemSize_(0)
|
||||||
|
, modelWeightSize_(0)
|
||||||
|
, modelMemPtr_(nullptr)
|
||||||
|
, modelWeightPtr_(nullptr)
|
||||||
|
, loadFlag_(false)
|
||||||
|
, modelDesc_(nullptr)
|
||||||
|
, input_(nullptr)
|
||||||
|
, output_(nullptr)
|
||||||
|
, numInputs_(0)
|
||||||
|
, numOutputs_(0)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -34,16 +43,16 @@ ModelProcess::~ModelProcess()
|
|||||||
DestroyOutput();
|
DestroyOutput();
|
||||||
}
|
}
|
||||||
|
|
||||||
Result ModelProcess::LoadModelFromFileWithMem(const char *modelPath)
|
Result ModelProcess::LoadModelFromFileWithMem(const string& modelPath)
|
||||||
{
|
{
|
||||||
if (loadFlag_) {
|
if (loadFlag_) {
|
||||||
ERROR_LOG("has already loaded a model");
|
ERROR_LOG("has already loaded a model");
|
||||||
return FAILED;
|
return FAILED;
|
||||||
}
|
}
|
||||||
|
|
||||||
aclError ret = aclmdlQuerySize(modelPath, &modelMemSize_, &modelWeightSize_);
|
aclError ret = aclmdlQuerySize(modelPath.c_str(), &modelMemSize_, &modelWeightSize_);
|
||||||
if (ret != ACL_ERROR_NONE) {
|
if (ret != ACL_ERROR_NONE) {
|
||||||
ERROR_LOG("query model failed, model file is %s", modelPath);
|
ERROR_LOG("query model failed, model file is %s", modelPath.c_str());
|
||||||
return FAILED;
|
return FAILED;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -59,15 +68,15 @@ Result ModelProcess::LoadModelFromFileWithMem(const char *modelPath)
|
|||||||
return FAILED;
|
return FAILED;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = aclmdlLoadFromFileWithMem(modelPath, &modelId_, modelMemPtr_,
|
ret = aclmdlLoadFromFileWithMem(modelPath.c_str(), &modelId_, modelMemPtr_,
|
||||||
modelMemSize_, modelWeightPtr_, modelWeightSize_);
|
modelMemSize_, modelWeightPtr_, modelWeightSize_);
|
||||||
if (ret != ACL_ERROR_NONE) {
|
if (ret != ACL_ERROR_NONE) {
|
||||||
ERROR_LOG("load model from file failed, model file is %s", modelPath);
|
ERROR_LOG("load model from file failed, model file is %s", modelPath.c_str());
|
||||||
return FAILED;
|
return FAILED;
|
||||||
}
|
}
|
||||||
|
|
||||||
loadFlag_ = true;
|
loadFlag_ = true;
|
||||||
INFO_LOG("load model %s success", modelPath);
|
INFO_LOG("load model %s success", modelPath.c_str());
|
||||||
return SUCCESS;
|
return SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -91,7 +100,8 @@ Result ModelProcess::CreateDesc()
|
|||||||
}
|
}
|
||||||
|
|
||||||
Result ModelProcess::PrintDesc()
|
Result ModelProcess::PrintDesc()
|
||||||
{ aclError ret;
|
{
|
||||||
|
aclError ret;
|
||||||
DEBUG_LOG("start print model description");
|
DEBUG_LOG("start print model description");
|
||||||
size_t numInputs = aclmdlGetNumInputs(modelDesc_);
|
size_t numInputs = aclmdlGetNumInputs(modelDesc_);
|
||||||
size_t numOutputs = aclmdlGetNumOutputs(modelDesc_);
|
size_t numOutputs = aclmdlGetNumOutputs(modelDesc_);
|
||||||
@@ -101,30 +111,30 @@ Result ModelProcess::PrintDesc()
|
|||||||
aclmdlIODims dimsInput;
|
aclmdlIODims dimsInput;
|
||||||
aclmdlIODims dimsOutput;
|
aclmdlIODims dimsOutput;
|
||||||
aclmdlIODims dimsCurrentOutput;
|
aclmdlIODims dimsCurrentOutput;
|
||||||
for (size_t i = 0; i < numInputs; i++){
|
for (size_t i = 0; i < numInputs; i++) {
|
||||||
DEBUG_LOG("the size of %zu input: %zu", i, aclmdlGetInputSizeByIndex(modelDesc_, i));
|
DEBUG_LOG("the size of %zu input: %zu", i, aclmdlGetInputSizeByIndex(modelDesc_, i));
|
||||||
ret = aclmdlGetInputDims(modelDesc_, i, &dimsInput);
|
ret = aclmdlGetInputDims(modelDesc_, i, &dimsInput);
|
||||||
DEBUG_LOG("the dims of %zu input:", i);
|
DEBUG_LOG("the dims of %zu input:", i);
|
||||||
for (size_t j = 0; j < dimsInput.dimCount; j++){
|
for (size_t j = 0; j < dimsInput.dimCount; j++) {
|
||||||
cout << dimsInput.dims[j] << " ";
|
cout << dimsInput.dims[j] << " ";
|
||||||
}
|
}
|
||||||
cout << endl;
|
cout << endl;
|
||||||
DEBUG_LOG("the name of %zu input: %s", i, aclmdlGetInputNameByIndex(modelDesc_, i));
|
DEBUG_LOG("the name of %zu input: %s", i, aclmdlGetInputNameByIndex(modelDesc_, i));
|
||||||
DEBUG_LOG("the Format of %zu input: %u", i, aclmdlGetInputFormat(modelDesc_, i));
|
DEBUG_LOG("the Format of %zu input: %u", i, aclmdlGetInputFormat(modelDesc_, i));
|
||||||
DEBUG_LOG("the DataType of %zu input: %u", i, aclmdlGetInputFormat(modelDesc_, i));
|
DEBUG_LOG("the DataType of %zu input: %u", i, aclmdlGetInputFormat(modelDesc_, i));
|
||||||
}
|
}
|
||||||
for (size_t i = 0; i < numOutputs; i++){
|
for (size_t i = 0; i < numOutputs; i++) {
|
||||||
DEBUG_LOG("the size of %zu output: %zu", i, aclmdlGetOutputSizeByIndex(modelDesc_, i));
|
DEBUG_LOG("the size of %zu output: %zu", i, aclmdlGetOutputSizeByIndex(modelDesc_, i));
|
||||||
ret = aclmdlGetOutputDims(modelDesc_, i, &dimsOutput);
|
ret = aclmdlGetOutputDims(modelDesc_, i, &dimsOutput);
|
||||||
DEBUG_LOG("the dims of %zu output:", i);
|
DEBUG_LOG("the dims of %zu output:", i);
|
||||||
for (size_t j = 0; j < dimsOutput.dimCount; j++){
|
for (size_t j = 0; j < dimsOutput.dimCount; j++) {
|
||||||
cout <<dimsOutput.dims[j] << " ";
|
cout << dimsOutput.dims[j] << " ";
|
||||||
}
|
}
|
||||||
cout << endl;
|
cout << endl;
|
||||||
ret = aclmdlGetCurOutputDims(modelDesc_, i, &dimsCurrentOutput);
|
ret = aclmdlGetCurOutputDims(modelDesc_, i, &dimsCurrentOutput);
|
||||||
DEBUG_LOG("the dims of %zu current output:", i);
|
DEBUG_LOG("the dims of %zu current output:", i);
|
||||||
for (size_t j = 0; j < dimsCurrentOutput.dimCount; j++){
|
for (size_t j = 0; j < dimsCurrentOutput.dimCount; j++) {
|
||||||
cout <<dimsCurrentOutput.dims[j] << " ";
|
cout << dimsCurrentOutput.dims[j] << " ";
|
||||||
}
|
}
|
||||||
cout << endl;
|
cout << endl;
|
||||||
DEBUG_LOG("the name of %zu output: %s", i, aclmdlGetOutputNameByIndex(modelDesc_, i));
|
DEBUG_LOG("the name of %zu output: %s", i, aclmdlGetOutputNameByIndex(modelDesc_, i));
|
||||||
@@ -141,7 +151,7 @@ Result ModelProcess::PrintDesc()
|
|||||||
}
|
}
|
||||||
if (batch_info.batchCount != 0) {
|
if (batch_info.batchCount != 0) {
|
||||||
DEBUG_LOG("DynamicBatch:");
|
DEBUG_LOG("DynamicBatch:");
|
||||||
for (size_t i = 0; i < batch_info.batchCount; i++){
|
for (size_t i = 0; i < batch_info.batchCount; i++) {
|
||||||
cout << batch_info.batch[i] << " ";
|
cout << batch_info.batch[i] << " ";
|
||||||
}
|
}
|
||||||
cout << endl;
|
cout << endl;
|
||||||
@@ -165,8 +175,6 @@ Result ModelProcess::PrintDesc()
|
|||||||
return SUCCESS;
|
return SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void ModelProcess::DestroyDesc()
|
void ModelProcess::DestroyDesc()
|
||||||
{
|
{
|
||||||
if (modelDesc_ != nullptr) {
|
if (modelDesc_ != nullptr) {
|
||||||
@@ -175,7 +183,7 @@ void ModelProcess::DestroyDesc()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Result ModelProcess::CreateInput(void *inputDataBuffer, size_t bufferSize)
|
Result ModelProcess::CreateInput(void* inputDataBuffer, size_t bufferSize)
|
||||||
{
|
{
|
||||||
if (input_ == nullptr) {
|
if (input_ == nullptr) {
|
||||||
input_ = aclmdlCreateDataset();
|
input_ = aclmdlCreateDataset();
|
||||||
@@ -201,7 +209,8 @@ Result ModelProcess::CreateInput(void *inputDataBuffer, size_t bufferSize)
|
|||||||
return SUCCESS;
|
return SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
Result ModelProcess::CreateZeroInput(){
|
Result ModelProcess::CreateZeroInput()
|
||||||
|
{
|
||||||
if (input_ == nullptr) {
|
if (input_ == nullptr) {
|
||||||
input_ = aclmdlCreateDataset();
|
input_ = aclmdlCreateDataset();
|
||||||
if (input_ == nullptr) {
|
if (input_ == nullptr) {
|
||||||
@@ -210,9 +219,9 @@ Result ModelProcess::CreateInput(void *inputDataBuffer, size_t bufferSize)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
numInputs_ = aclmdlGetNumInputs(modelDesc_);
|
numInputs_ = aclmdlGetNumInputs(modelDesc_);
|
||||||
for (size_t i = 0; i < numInputs_; i++){
|
for (size_t i = 0; i < numInputs_; i++) {
|
||||||
size_t buffer_size_zero = aclmdlGetInputSizeByIndex(modelDesc_, i);
|
size_t buffer_size_zero = aclmdlGetInputSizeByIndex(modelDesc_, i);
|
||||||
void *inBufferDev = nullptr;
|
void* inBufferDev = nullptr;
|
||||||
if (!g_isDevice) {
|
if (!g_isDevice) {
|
||||||
void* binFileBufferData = nullptr;
|
void* binFileBufferData = nullptr;
|
||||||
aclError ret = aclrtMallocHost(&binFileBufferData, buffer_size_zero);
|
aclError ret = aclrtMallocHost(&binFileBufferData, buffer_size_zero);
|
||||||
@@ -220,7 +229,7 @@ Result ModelProcess::CreateInput(void *inputDataBuffer, size_t bufferSize)
|
|||||||
ERROR_LOG("malloc host buffer failed. size is %zu", buffer_size_zero);
|
ERROR_LOG("malloc host buffer failed. size is %zu", buffer_size_zero);
|
||||||
return FAILED;
|
return FAILED;
|
||||||
}
|
}
|
||||||
memset(binFileBufferData,0,buffer_size_zero);
|
memset(binFileBufferData, 0, buffer_size_zero);
|
||||||
ret = aclrtMalloc(&inBufferDev, buffer_size_zero, ACL_MEM_MALLOC_NORMAL_ONLY);
|
ret = aclrtMalloc(&inBufferDev, buffer_size_zero, ACL_MEM_MALLOC_NORMAL_ONLY);
|
||||||
if (ret != ACL_ERROR_NONE) {
|
if (ret != ACL_ERROR_NONE) {
|
||||||
ERROR_LOG("malloc device buffer failed. size is %zu", buffer_size_zero);
|
ERROR_LOG("malloc device buffer failed. size is %zu", buffer_size_zero);
|
||||||
@@ -233,16 +242,15 @@ Result ModelProcess::CreateInput(void *inputDataBuffer, size_t bufferSize)
|
|||||||
aclrtFreeHost(binFileBufferData);
|
aclrtFreeHost(binFileBufferData);
|
||||||
return FAILED;
|
return FAILED;
|
||||||
}
|
}
|
||||||
}else{
|
} else {
|
||||||
aclError ret = aclrtMalloc(&inBufferDev, buffer_size_zero, ACL_MEM_MALLOC_NORMAL_ONLY);
|
aclError ret = aclrtMalloc(&inBufferDev, buffer_size_zero, ACL_MEM_MALLOC_NORMAL_ONLY);
|
||||||
if (ret != ACL_ERROR_NONE) {
|
if (ret != ACL_ERROR_NONE) {
|
||||||
ERROR_LOG("malloc device buffer failed. size is %zu", buffer_size_zero);
|
ERROR_LOG("malloc device buffer failed. size is %zu", buffer_size_zero);
|
||||||
return FAILED;
|
return FAILED;
|
||||||
}
|
}
|
||||||
memset(inBufferDev,0,buffer_size_zero);
|
memset(inBufferDev, 0, buffer_size_zero);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
aclDataBuffer* inputData = aclCreateDataBuffer(inBufferDev, buffer_size_zero);
|
aclDataBuffer* inputData = aclCreateDataBuffer(inBufferDev, buffer_size_zero);
|
||||||
if (inputData == nullptr) {
|
if (inputData == nullptr) {
|
||||||
ERROR_LOG("can't create data buffer, create input failed");
|
ERROR_LOG("can't create data buffer, create input failed");
|
||||||
@@ -260,7 +268,7 @@ Result ModelProcess::CreateInput(void *inputDataBuffer, size_t bufferSize)
|
|||||||
return FAILED;
|
return FAILED;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return SUCCESS;
|
return SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ModelProcess::DestroyInput()
|
void ModelProcess::DestroyInput()
|
||||||
@@ -294,7 +302,7 @@ Result ModelProcess::CreateOutput()
|
|||||||
for (size_t i = 0; i < outputSize; ++i) {
|
for (size_t i = 0; i < outputSize; ++i) {
|
||||||
size_t buffer_size = aclmdlGetOutputSizeByIndex(modelDesc_, i);
|
size_t buffer_size = aclmdlGetOutputSizeByIndex(modelDesc_, i);
|
||||||
|
|
||||||
void *outputBuffer = nullptr;
|
void* outputBuffer = nullptr;
|
||||||
aclError ret = aclrtMalloc(&outputBuffer, buffer_size, ACL_MEM_MALLOC_NORMAL_ONLY);
|
aclError ret = aclrtMalloc(&outputBuffer, buffer_size, ACL_MEM_MALLOC_NORMAL_ONLY);
|
||||||
if (ret != ACL_ERROR_NONE) {
|
if (ret != ACL_ERROR_NONE) {
|
||||||
ERROR_LOG("can't malloc buffer, size is %zu, create output failed", buffer_size);
|
ERROR_LOG("can't malloc buffer, size is %zu, create output failed", buffer_size);
|
||||||
@@ -320,74 +328,19 @@ Result ModelProcess::CreateOutput()
|
|||||||
INFO_LOG("create model output success");
|
INFO_LOG("create model output success");
|
||||||
return SUCCESS;
|
return SUCCESS;
|
||||||
}
|
}
|
||||||
/*
|
|
||||||
void ModelProcess::DumpModelOutputResult()
|
|
||||||
{
|
|
||||||
stringstream ss;
|
|
||||||
size_t outputNum = aclmdlGetDatasetNumBuffers(output_);
|
|
||||||
static int executeNum = 0;
|
|
||||||
for (size_t i = 0; i < outputNum; ++i) {
|
|
||||||
ss << "output" << ++executeNum << "_" << i << ".bin";
|
|
||||||
string outputFileName = ss.str();
|
|
||||||
FILE *outputFile = fopen(outputFileName.c_str(), "wb");
|
|
||||||
if (outputFile) {
|
|
||||||
aclDataBuffer* dataBuffer = aclmdlGetDatasetBuffer(output_, i);
|
|
||||||
void* data = aclGetDataBufferAddr(dataBuffer);
|
|
||||||
uint32_t len = aclGetDataBufferSize(dataBuffer);
|
|
||||||
|
|
||||||
void* outHostData = NULL;
|
void ModelProcess::OutputModelResult(std::string& s, std::string& modelName, size_t index)
|
||||||
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), outputFile);
|
|
||||||
|
|
||||||
ret = aclrtFreeHost(outHostData);
|
|
||||||
if (ret != ACL_ERROR_NONE) {
|
|
||||||
ERROR_LOG("aclrtFreeHost failed, ret[%d]", ret);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
fwrite(data, len, sizeof(char), outputFile);
|
|
||||||
}
|
|
||||||
fclose(outputFile);
|
|
||||||
outputFile = nullptr;
|
|
||||||
} else {
|
|
||||||
ERROR_LOG("create output file [%s] failed", outputFileName.c_str());
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
INFO_LOG("dump data success");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
void ModelProcess::OutputModelResult(std::string& s,std::string& modelName,size_t index)
|
|
||||||
{
|
{
|
||||||
const char* temp_s = s.c_str();
|
const char* temp_s = s.c_str();
|
||||||
if (NULL == opendir(temp_s)){
|
if (NULL == opendir(temp_s)) {
|
||||||
mkdir(temp_s,0775);
|
mkdir(temp_s, 0775);
|
||||||
}
|
}
|
||||||
std::string T = Utils::TimeLine();
|
std::string T = Utils::TimeLine();
|
||||||
//std::string t = s.c_str()+"/"+T.c_str();
|
string times = s + "/" + T + "_" + to_string(index);
|
||||||
//const char* time = t.c_str();
|
const char* time = times.c_str();
|
||||||
string times = s+"/"+T+"_"+to_string(index);
|
cout << time << endl;
|
||||||
const char* time = times.c_str();
|
mkdir(time, 0775);
|
||||||
cout << time <<endl;
|
if (NULL == opendir(time)) {
|
||||||
mkdir(time,0775);
|
|
||||||
if (NULL == opendir(time))
|
|
||||||
{
|
|
||||||
ERROR_LOG("current user does not have permission");
|
ERROR_LOG("current user does not have permission");
|
||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
@@ -397,8 +350,8 @@ void ModelProcess::OutputModelResult(std::string& s,std::string& modelName,size_
|
|||||||
void* data = aclGetDataBufferAddr(dataBuffer);
|
void* data = aclGetDataBufferAddr(dataBuffer);
|
||||||
uint32_t len = aclGetDataBufferSize(dataBuffer);
|
uint32_t len = aclGetDataBufferSize(dataBuffer);
|
||||||
aclDataType datatype = aclmdlGetOutputDataType(modelDesc_, i);
|
aclDataType datatype = aclmdlGetOutputDataType(modelDesc_, i);
|
||||||
void *dims = nullptr;
|
void* dims = nullptr;
|
||||||
aclmdlIODims *dim = nullptr;
|
aclmdlIODims* dim = nullptr;
|
||||||
aclError ret = ACL_ERROR_NONE;
|
aclError ret = ACL_ERROR_NONE;
|
||||||
if (!g_isDevice) {
|
if (!g_isDevice) {
|
||||||
ret = aclrtMallocHost(&dims, sizeof(aclmdlIODims));
|
ret = aclrtMallocHost(&dims, sizeof(aclmdlIODims));
|
||||||
@@ -406,14 +359,13 @@ void ModelProcess::OutputModelResult(std::string& s,std::string& modelName,size_
|
|||||||
ERROR_LOG("aclrtMallocHost failed, ret[%d]", ret);
|
ERROR_LOG("aclrtMallocHost failed, ret[%d]", ret);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else {
|
ret = aclrtMalloc(&dims, sizeof(aclmdlIODims), ACL_MEM_MALLOC_NORMAL_ONLY);
|
||||||
ret = aclrtMalloc(&dims, sizeof(aclmdlIODims), ACL_MEM_MALLOC_NORMAL_ONLY);
|
if (ret != ACL_ERROR_NONE) {
|
||||||
if (ret != ACL_ERROR_NONE) {
|
|
||||||
ERROR_LOG("malloc device buffer failed, ret[%d]", ret);
|
ERROR_LOG("malloc device buffer failed, ret[%d]", ret);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
dim = reinterpret_cast<aclmdlIODims*>(dims);
|
dim = reinterpret_cast<aclmdlIODims*>(dims);
|
||||||
ret = aclmdlGetOutputDims(modelDesc_, i, dim);
|
ret = aclmdlGetOutputDims(modelDesc_, i, dim);
|
||||||
if (ret != ACL_ERROR_NONE) {
|
if (ret != ACL_ERROR_NONE) {
|
||||||
@@ -421,9 +373,9 @@ void ModelProcess::OutputModelResult(std::string& s,std::string& modelName,size_
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
void *outHostData = NULL;
|
void* outHostData = NULL;
|
||||||
ret = ACL_ERROR_NONE;
|
ret = ACL_ERROR_NONE;
|
||||||
void *outData = NULL;
|
void* outData = NULL;
|
||||||
if (!g_isDevice) {
|
if (!g_isDevice) {
|
||||||
ret = aclrtMallocHost(&outHostData, len);
|
ret = aclrtMallocHost(&outHostData, len);
|
||||||
if (ret != ACL_ERROR_NONE) {
|
if (ret != ACL_ERROR_NONE) {
|
||||||
@@ -436,216 +388,198 @@ void ModelProcess::OutputModelResult(std::string& s,std::string& modelName,size_
|
|||||||
ERROR_LOG("aclrtMemcpy failed, ret[%d]", ret);
|
ERROR_LOG("aclrtMemcpy failed, ret[%d]", ret);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
switch (datatype)
|
switch (datatype) {
|
||||||
{
|
case 0:
|
||||||
case 0:
|
outData = reinterpret_cast<float*>(outHostData);
|
||||||
outData = reinterpret_cast<float*>(outHostData);
|
break;
|
||||||
break;
|
case 1:
|
||||||
case 1:
|
outData = reinterpret_cast<aclFloat16*>(outHostData);
|
||||||
outData = reinterpret_cast<aclFloat16*>(outHostData);
|
break;
|
||||||
break;
|
case 2:
|
||||||
case 2:
|
outData = reinterpret_cast<int8_t*>(outHostData);
|
||||||
outData = reinterpret_cast<int8_t*>(outHostData);
|
break;
|
||||||
break;
|
case 3:
|
||||||
case 3:
|
outData = reinterpret_cast<int*>(outHostData);
|
||||||
outData = reinterpret_cast<int*>(outHostData);
|
break;
|
||||||
break;
|
case 4:
|
||||||
case 4:
|
outData = reinterpret_cast<uint8_t*>(outHostData);
|
||||||
outData = reinterpret_cast<uint8_t*>(outHostData);
|
break;
|
||||||
break;
|
case 6:
|
||||||
case 6:
|
outData = reinterpret_cast<int16_t*>(outHostData);
|
||||||
outData = reinterpret_cast<int16_t*>(outHostData);
|
break;
|
||||||
break;
|
case 7:
|
||||||
case 7:
|
outData = reinterpret_cast<uint16_t*>(outHostData);
|
||||||
outData = reinterpret_cast<uint16_t*>(outHostData);
|
break;
|
||||||
break;
|
case 8:
|
||||||
case 8:
|
outData = reinterpret_cast<uint32_t*>(outHostData);
|
||||||
outData = reinterpret_cast<uint32_t*>(outHostData);
|
break;
|
||||||
break;
|
case 9:
|
||||||
case 9:
|
outData = reinterpret_cast<int64_t*>(outHostData);
|
||||||
outData = reinterpret_cast<int64_t*>(outHostData);
|
break;
|
||||||
break;
|
case 10:
|
||||||
case 10:
|
outData = reinterpret_cast<uint64_t*>(outHostData);
|
||||||
outData = reinterpret_cast<uint64_t*>(outHostData);
|
break;
|
||||||
break;
|
case 11:
|
||||||
case 11:
|
outData = reinterpret_cast<double*>(outHostData);
|
||||||
outData = reinterpret_cast<double*>(outHostData);
|
break;
|
||||||
break;
|
case 12:
|
||||||
case 12:
|
outData = reinterpret_cast<bool*>(outHostData);
|
||||||
outData = reinterpret_cast<bool*>(outHostData);
|
break;
|
||||||
break;
|
default:
|
||||||
default :
|
printf("undefined data type!\n");
|
||||||
printf("undefined data type!\n");
|
break;
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
outData = reinterpret_cast<float*>(data);
|
outData = reinterpret_cast<float*>(data);
|
||||||
}
|
}
|
||||||
if (f_isTXT)
|
if (f_isTXT) {
|
||||||
{
|
ofstream outstr(times + "/" + modelName + "_output_" + to_string(i) + ".txt", ios::out);
|
||||||
ofstream outstr(times+"/"+modelName+"_output_"+to_string(i)+".txt", ios::out);
|
switch (datatype) {
|
||||||
switch (datatype)
|
case 0:
|
||||||
{
|
for (int i = 0; i < len / sizeof(float); i++) {
|
||||||
case 0:
|
float out = *((float*)outData + i);
|
||||||
for (int i = 0; i < len/sizeof(float); i++)
|
outstr << out << " ";
|
||||||
{
|
for (int j = 0; j < dim->dimCount; j++) {
|
||||||
float out = *((float*)outData+i);
|
if (i != 0 && i % dim->dims[j] == 0 && dim->dims[j] > 10) {
|
||||||
outstr << out << " ";
|
outstr << "\n";
|
||||||
for (int j = 0; j < dim->dimCount; j++)
|
}
|
||||||
{
|
}
|
||||||
if (i !=0 && i%dim->dims[j] == 0 && dim->dims[j] > 10)
|
}
|
||||||
{outstr << "\n" ;}
|
break;
|
||||||
}
|
case 1:
|
||||||
}
|
for (int i = 0; i < len / sizeof(aclFloat16); i++) {
|
||||||
break;
|
aclFloat16 out = *((aclFloat16*)outData + i);
|
||||||
case 1:
|
outstr << out << " ";
|
||||||
for (int i = 0; i < len/sizeof(aclFloat16); i++)
|
for (int j = 0; j < dim->dimCount; j++) {
|
||||||
{
|
if (i != 0 && i % dim->dims[j] == 0 && dim->dims[j] > 10) {
|
||||||
aclFloat16 out = *((aclFloat16*)outData+i);
|
outstr << "\n";
|
||||||
outstr << out << " ";
|
}
|
||||||
for (int j = 0; j < dim->dimCount; j++)
|
}
|
||||||
{
|
}
|
||||||
if (i !=0 && i%dim->dims[j] == 0 && dim->dims[j] > 10)
|
break;
|
||||||
{outstr << "\n" ;}
|
case 2:
|
||||||
}
|
for (int i = 0; i < len / sizeof(int8_t); i++) {
|
||||||
}
|
int8_t out = *((int8_t*)outData + i);
|
||||||
break;
|
outstr << out << " ";
|
||||||
case 2:
|
for (int j = 0; j < dim->dimCount; j++) {
|
||||||
for (int i = 0; i < len/sizeof(int8_t); i++)
|
if (i != 0 && i % dim->dims[j] == 0 && dim->dims[j] > 10) {
|
||||||
{
|
outstr << "\n";
|
||||||
int8_t out = *((int8_t*)outData+i);
|
}
|
||||||
outstr << out << " ";
|
}
|
||||||
for (int j = 0; j < dim->dimCount; j++)
|
}
|
||||||
{
|
break;
|
||||||
if (i !=0 && i%dim->dims[j] == 0 && dim->dims[j] > 10)
|
case 3:
|
||||||
{outstr << "\n" ;}
|
for (int i = 0; i < len / sizeof(int); i++) {
|
||||||
}
|
int out = *((int*)outData + i);
|
||||||
}
|
outstr << out << " ";
|
||||||
break;
|
for (int j = 0; j < dim->dimCount; j++) {
|
||||||
case 3:
|
if (i != 0 && i % dim->dims[j] == 0 && dim->dims[j] > 10) {
|
||||||
for (int i = 0; i < len/sizeof(int); i++)
|
outstr << "\n";
|
||||||
{
|
}
|
||||||
int out = *((int*)outData+i);
|
}
|
||||||
outstr << out << " ";
|
}
|
||||||
for (int j = 0; j < dim->dimCount; j++)
|
break;
|
||||||
{
|
case 4:
|
||||||
if (i !=0 && i%dim->dims[j] == 0 && dim->dims[j] > 10)
|
for (int i = 0; i < len / sizeof(uint8_t); i++) {
|
||||||
{outstr << "\n" ;}
|
uint8_t out = *((uint8_t*)outData + i);
|
||||||
}
|
outstr << out << " ";
|
||||||
}
|
for (int j = 0; j < dim->dimCount; j++) {
|
||||||
break;
|
if (i != 0 && i % dim->dims[j] == 0 && dim->dims[j] > 10) {
|
||||||
case 4:
|
outstr << "\n";
|
||||||
for (int i = 0; i < len/sizeof(uint8_t); i++)
|
}
|
||||||
{
|
}
|
||||||
uint8_t out = *((uint8_t*)outData+i);
|
}
|
||||||
outstr << out << " ";
|
break;
|
||||||
for (int j = 0; j < dim->dimCount; j++)
|
case 6:
|
||||||
{
|
for (int i = 0; i < len / sizeof(int16_t); i++) {
|
||||||
if (i !=0 && i%dim->dims[j] == 0 && dim->dims[j] > 10)
|
int16_t out = *((int16_t*)outData + i);
|
||||||
{outstr << "\n" ;}
|
outstr << out << " ";
|
||||||
}
|
for (int j = 0; j < dim->dimCount; j++) {
|
||||||
}
|
if (i != 0 && i % dim->dims[j] == 0 && dim->dims[j] > 10) {
|
||||||
break;
|
outstr << "\n";
|
||||||
case 6:
|
}
|
||||||
for (int i = 0; i < len/sizeof(int16_t); i++)
|
}
|
||||||
{
|
}
|
||||||
int16_t out = *((int16_t*)outData+i);
|
break;
|
||||||
outstr << out << " ";
|
case 7:
|
||||||
for (int j = 0; j < dim->dimCount; j++)
|
for (int i = 0; i < len / sizeof(uint16_t); i++) {
|
||||||
{
|
uint16_t out = *((uint16_t*)outData + i);
|
||||||
if (i !=0 && i%dim->dims[j] == 0 && dim->dims[j] > 10)
|
outstr << out << " ";
|
||||||
{outstr << "\n" ;}
|
for (int j = 0; j < dim->dimCount; j++) {
|
||||||
}
|
if (i != 0 && i % dim->dims[j] == 0 && dim->dims[j] > 10) {
|
||||||
}
|
outstr << "\n";
|
||||||
break;
|
}
|
||||||
case 7:
|
}
|
||||||
for (int i = 0; i < len/sizeof(uint16_t); i++)
|
}
|
||||||
{
|
break;
|
||||||
uint16_t out = *((uint16_t*)outData+i);
|
case 8:
|
||||||
outstr << out << " ";
|
for (int i = 0; i < len / sizeof(uint32_t); i++) {
|
||||||
for (int j = 0; j < dim->dimCount; j++)
|
uint32_t out = *((uint32_t*)outData + i);
|
||||||
{
|
outstr << out << " ";
|
||||||
if (i !=0 && i%dim->dims[j] == 0 && dim->dims[j] > 10)
|
for (int j = 0; j < dim->dimCount; j++) {
|
||||||
{outstr << "\n" ;}
|
if (i != 0 && i % dim->dims[j] == 0 && dim->dims[j] > 10) {
|
||||||
}
|
outstr << "\n";
|
||||||
}
|
}
|
||||||
break;
|
}
|
||||||
case 8:
|
}
|
||||||
for (int i = 0; i < len/sizeof(uint32_t); i++)
|
break;
|
||||||
{
|
case 9:
|
||||||
uint32_t out = *((uint32_t*)outData+i);
|
for (int i = 0; i < len / sizeof(int64_t); i++) {
|
||||||
outstr << out << " ";
|
int64_t out = *((int64_t*)outData + i);
|
||||||
for (int j = 0; j < dim->dimCount; j++)
|
outstr << out << " ";
|
||||||
{
|
for (int j = 0; j < dim->dimCount; j++) {
|
||||||
if (i !=0 && i%dim->dims[j] == 0 && dim->dims[j] > 10)
|
if (i != 0 && i % dim->dims[j] == 0 && dim->dims[j] > 10) {
|
||||||
{outstr << "\n" ;}
|
outstr << "\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
}
|
||||||
case 9:
|
break;
|
||||||
for (int i = 0; i < len/sizeof(int64_t); i++)
|
case 10:
|
||||||
{
|
for (int i = 0; i < len / sizeof(uint64_t); i++) {
|
||||||
int64_t out = *((int64_t*)outData+i);
|
uint64_t out = *((uint64_t*)outData + i);
|
||||||
outstr << out << " ";
|
outstr << out << " ";
|
||||||
for (int j = 0; j < dim->dimCount; j++)
|
for (int j = 0; j < dim->dimCount; j++) {
|
||||||
{
|
if (i != 0 && i % dim->dims[j] == 0 && dim->dims[j] > 10) {
|
||||||
if (i !=0 && i%dim->dims[j] == 0 && dim->dims[j] > 10)
|
outstr << "\n";
|
||||||
{outstr << "\n" ;}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 10:
|
case 11:
|
||||||
for (int i = 0; i < len/sizeof(uint64_t); i++)
|
for (int i = 0; i < len / sizeof(double); i++) {
|
||||||
{
|
double out = *((double*)outData + i);
|
||||||
uint64_t out = *((uint64_t*)outData+i);
|
outstr << out << " ";
|
||||||
outstr << out << " ";
|
for (int j = 0; j < dim->dimCount; j++) {
|
||||||
for (int j = 0; j < dim->dimCount; j++)
|
if (i != 0 && i % dim->dims[j] == 0 && dim->dims[j] > 10) {
|
||||||
{
|
outstr << "\n";
|
||||||
if (i !=0 && i%dim->dims[j] == 0 && dim->dims[j] > 10)
|
}
|
||||||
{outstr << "\n" ;}
|
}
|
||||||
}
|
}
|
||||||
}
|
break;
|
||||||
break;
|
case 12:
|
||||||
case 11:
|
for (int i = 0; i < len / sizeof(bool); i++) {
|
||||||
for (int i = 0; i < len/sizeof(double); i++)
|
int out = *((bool*)outData + i);
|
||||||
{
|
outstr << out << " ";
|
||||||
double out = *((double*)outData+i);
|
for (int j = 0; j < dim->dimCount; j++) {
|
||||||
outstr << out << " ";
|
if (i != 0 && i % dim->dims[j] == 0 && dim->dims[j] > 10) {
|
||||||
for (int j = 0; j < dim->dimCount; j++)
|
outstr << "\n";
|
||||||
{
|
}
|
||||||
if (i !=0 && i%dim->dims[j] == 0 && dim->dims[j] > 10)
|
}
|
||||||
{outstr << "\n" ;}
|
}
|
||||||
}
|
break;
|
||||||
}
|
default:
|
||||||
break;
|
printf("undefined data type!\n");
|
||||||
case 12:
|
break;
|
||||||
for (int i = 0; i < len/sizeof(bool); i++)
|
|
||||||
{
|
|
||||||
int out = *((bool*)outData+i);
|
|
||||||
outstr << out << " ";
|
|
||||||
for (int j = 0; j < dim->dimCount; j++)
|
|
||||||
{
|
|
||||||
if (i !=0 && i%dim->dims[j] == 0 && dim->dims[j] > 10)
|
|
||||||
{outstr << "\n" ;}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
default :
|
|
||||||
printf("undefined data type!\n");
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
outstr.close();
|
outstr.close();
|
||||||
}
|
} else {
|
||||||
else
|
ofstream outstr(times + "/" + modelName + "_output_" + to_string(i) + ".bin", ios::out | ios::binary);
|
||||||
{
|
|
||||||
ofstream outstr(times+"/"+modelName+"_output_"+to_string(i)+".bin", ios::out|ios::binary);
|
|
||||||
|
|
||||||
outstr.write((char*)outData, len);
|
outstr.write((char*)outData, len);
|
||||||
outstr.close();
|
outstr.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (!g_isDevice) {
|
if (!g_isDevice) {
|
||||||
ret = aclrtFreeHost(outHostData);
|
ret = aclrtFreeHost(outHostData);
|
||||||
if (ret != ACL_ERROR_NONE) {
|
if (ret != ACL_ERROR_NONE) {
|
||||||
@@ -663,7 +597,7 @@ void ModelProcess::DestroyOutput()
|
|||||||
{
|
{
|
||||||
if (output_ == nullptr) {
|
if (output_ == nullptr) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
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);
|
||||||
@@ -708,13 +642,13 @@ void ModelProcess::Unload()
|
|||||||
aclrtFree(modelMemPtr_);
|
aclrtFree(modelMemPtr_);
|
||||||
modelMemPtr_ = nullptr;
|
modelMemPtr_ = nullptr;
|
||||||
modelMemSize_ = 0;
|
modelMemSize_ = 0;
|
||||||
}
|
}
|
||||||
if (modelWeightPtr_ != nullptr) {
|
if (modelWeightPtr_ != nullptr) {
|
||||||
aclrtFree(modelWeightPtr_);
|
aclrtFree(modelWeightPtr_);
|
||||||
modelWeightPtr_ = nullptr;
|
modelWeightPtr_ = nullptr;
|
||||||
modelWeightSize_ = 0;
|
modelWeightSize_ = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
loadFlag_ = false;
|
loadFlag_ = false;
|
||||||
INFO_LOG("unload model success, model Id is %u", modelId_);
|
INFO_LOG("unload model success, model Id is %u", modelId_);
|
||||||
}
|
}
|
||||||
|
|||||||
Executable → Regular
+19
-66
@@ -10,8 +10,8 @@
|
|||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
*/
|
*/
|
||||||
#include "sample_process.h"
|
#include "sample_process.h"
|
||||||
#include "model_process.h"
|
|
||||||
#include "acl/acl.h"
|
#include "acl/acl.h"
|
||||||
|
#include "model_process.h"
|
||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
using namespace std;
|
using namespace std;
|
||||||
extern bool g_isDevice;
|
extern bool g_isDevice;
|
||||||
@@ -22,8 +22,10 @@ extern bool is_debug;
|
|||||||
extern bool is_profi;
|
extern bool is_profi;
|
||||||
extern bool is_dump;
|
extern bool is_dump;
|
||||||
|
|
||||||
|
SampleProcess::SampleProcess()
|
||||||
SampleProcess::SampleProcess() :deviceId_(0), context_(nullptr), stream_(nullptr)
|
: deviceId_(0)
|
||||||
|
, context_(nullptr)
|
||||||
|
, stream_(nullptr)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -36,26 +38,16 @@ Result SampleProcess::InitResource()
|
|||||||
{
|
{
|
||||||
// ACL init
|
// ACL init
|
||||||
aclError ret;
|
aclError ret;
|
||||||
const char *aclConfigPath = "acl.json";
|
const char* aclConfigPath = "acl.json";
|
||||||
if (is_profi == true){
|
if (is_profi == true) {
|
||||||
ret = aclInit(aclConfigPath);
|
ret = aclInit(aclConfigPath);
|
||||||
} else
|
} else {
|
||||||
{
|
|
||||||
ret = aclInit(nullptr);
|
ret = aclInit(nullptr);
|
||||||
}
|
}
|
||||||
if (ret != ACL_ERROR_NONE) {
|
if (ret != ACL_ERROR_NONE) {
|
||||||
/* if (is_debug || is_profi){
|
|
||||||
if (remove("acl.json")==0){
|
|
||||||
INFO_LOG("delete acl.json success");
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
ERROR_LOG("delete acl.json failed");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
ERROR_LOG("acl init failed");
|
ERROR_LOG("acl init failed");
|
||||||
return FAILED;
|
return FAILED;
|
||||||
}
|
}
|
||||||
INFO_LOG("acl init success");
|
INFO_LOG("acl init success");
|
||||||
|
|
||||||
// open device
|
// open device
|
||||||
@@ -93,28 +85,18 @@ Result SampleProcess::InitResource()
|
|||||||
g_isDevice = (runMode == ACL_DEVICE);
|
g_isDevice = (runMode == ACL_DEVICE);
|
||||||
INFO_LOG("get run mode success");
|
INFO_LOG("get run mode success");
|
||||||
|
|
||||||
/* // dump init
|
|
||||||
if (is_dump == true){
|
|
||||||
ret = aclmdlInitDump();
|
|
||||||
if (ret != ACL_ERROR_NONE) {
|
|
||||||
ERROR_LOG("dump init failed");
|
|
||||||
return FAILED;
|
|
||||||
}
|
|
||||||
INFO_LOG("dump init success");
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
return SUCCESS;
|
return SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
Result SampleProcess::Process(map<char,string>& params, vector<string>& input_files)
|
Result SampleProcess::Process(map<char, string>& params, vector<string>& input_files)
|
||||||
{
|
{
|
||||||
// model init
|
// model init
|
||||||
ModelProcess processModel;
|
ModelProcess processModel;
|
||||||
const char* omModelPath = params['m'].c_str();
|
const std::string& omModelPath = params['m'];
|
||||||
std::string output_path = params['o'].c_str();
|
std::string output_path = params['o'].c_str();
|
||||||
const char* outfmt = params['f'].c_str();
|
const char* outfmt = params['f'].c_str();
|
||||||
const char* fmt_TXT = "TXT";
|
const char* fmt_TXT = "TXT";
|
||||||
f_isTXT = (strcmp(outfmt,fmt_TXT)==0);
|
f_isTXT = (strcmp(outfmt, fmt_TXT) == 0);
|
||||||
|
|
||||||
std::string modelPath = params['m'].c_str();
|
std::string modelPath = params['m'].c_str();
|
||||||
std::string modelName = Utils::modelName(modelPath);
|
std::string modelName = Utils::modelName(modelPath);
|
||||||
@@ -133,18 +115,8 @@ Result SampleProcess::Process(map<char,string>& params, vector<string>& input_fi
|
|||||||
ERROR_LOG("create model description failed");
|
ERROR_LOG("create model description failed");
|
||||||
return FAILED;
|
return FAILED;
|
||||||
}
|
}
|
||||||
/* // dump init
|
|
||||||
if (is_dump){
|
if (is_debug) {
|
||||||
const char *aclConfigPath = "acl.json";
|
|
||||||
ret = aclmdlSetDump(aclConfigPath);
|
|
||||||
if (ret != SUCCESS) {
|
|
||||||
ERROR_LOG("dump init failed");
|
|
||||||
return FAILED;
|
|
||||||
}
|
|
||||||
INFO_LOG("dump init success");
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
if (is_debug){
|
|
||||||
ret = processModel.PrintDesc();
|
ret = processModel.PrintDesc();
|
||||||
if (ret != SUCCESS) {
|
if (ret != SUCCESS) {
|
||||||
ERROR_LOG("print model descrtption failed");
|
ERROR_LOG("print model descrtption failed");
|
||||||
@@ -163,9 +135,8 @@ Result SampleProcess::Process(map<char,string>& params, vector<string>& input_fi
|
|||||||
ERROR_LOG("model create input failed");
|
ERROR_LOG("model create input failed");
|
||||||
return FAILED;
|
return FAILED;
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else {
|
vector<void*> picDevBuffer(input_files.size(), nullptr);
|
||||||
vector < void* > picDevBuffer(input_files.size(), nullptr);
|
|
||||||
for (size_t index = 0; index < input_files.size(); ++index) {
|
for (size_t index = 0; index < input_files.size(); ++index) {
|
||||||
INFO_LOG("start to process file:%s", input_files[index].c_str());
|
INFO_LOG("start to process file:%s", input_files[index].c_str());
|
||||||
// model process
|
// model process
|
||||||
@@ -193,9 +164,6 @@ Result SampleProcess::Process(map<char,string>& params, vector<string>& input_fi
|
|||||||
std::cout << "Inference time: " << inference_time[t] << "ms" << endl;
|
std::cout << "Inference time: " << inference_time[t] << "ms" << endl;
|
||||||
if (ret != SUCCESS) {
|
if (ret != SUCCESS) {
|
||||||
ERROR_LOG("model execute failed");
|
ERROR_LOG("model execute failed");
|
||||||
// for (size_t i = 0; i < input_files.size(); i++) {
|
|
||||||
// aclrtFree(picDevBuffer[i]);
|
|
||||||
// }
|
|
||||||
return FAILED;
|
return FAILED;
|
||||||
}
|
}
|
||||||
processModel.OutputModelResult(output_path, modelName, t);
|
processModel.OutputModelResult(output_path, modelName, t);
|
||||||
@@ -208,20 +176,14 @@ Result SampleProcess::Process(map<char,string>& params, vector<string>& input_fi
|
|||||||
}
|
}
|
||||||
processModel.DestroyInput();
|
processModel.DestroyInput();
|
||||||
|
|
||||||
if (is_dump || is_profi){
|
if (is_dump || is_profi) {
|
||||||
if (remove("acl.json")==0){
|
if (remove("acl.json") == 0) {
|
||||||
INFO_LOG("delete acl.json success");
|
INFO_LOG("delete acl.json success");
|
||||||
}
|
} else {
|
||||||
else{
|
|
||||||
ERROR_LOG("delete acl.json failed");
|
ERROR_LOG("delete acl.json failed");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// release model input buffer
|
|
||||||
// for (size_t i = 0; i < input_files.size(); i++) {
|
|
||||||
// aclrtFree(picDevBuffer[i]);
|
|
||||||
// }
|
|
||||||
|
|
||||||
return SUCCESS;
|
return SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -252,18 +214,9 @@ void SampleProcess::DestroyResource()
|
|||||||
}
|
}
|
||||||
INFO_LOG("end to reset device is %d", deviceId_);
|
INFO_LOG("end to reset device is %d", deviceId_);
|
||||||
|
|
||||||
/* if (is_dump){
|
|
||||||
ret = aclmdlFinalizeDump();
|
|
||||||
if (ret != ACL_ERROR_NONE) {
|
|
||||||
ERROR_LOG("finalize dump failed");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
INFO_LOG("end to finalize dump");
|
|
||||||
*/
|
|
||||||
ret = aclFinalize();
|
ret = aclFinalize();
|
||||||
if (ret != ACL_ERROR_NONE) {
|
if (ret != ACL_ERROR_NONE) {
|
||||||
ERROR_LOG("finalize acl failed");
|
ERROR_LOG("finalize acl failed");
|
||||||
}
|
}
|
||||||
INFO_LOG("end to finalize acl");
|
INFO_LOG("end to finalize acl");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Executable → Regular
+66
-94
@@ -10,8 +10,8 @@
|
|||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
*/
|
*/
|
||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
#include <sys/time.h>
|
|
||||||
#include "acl/acl.h"
|
#include "acl/acl.h"
|
||||||
|
#include <sys/time.h>
|
||||||
using namespace std;
|
using namespace std;
|
||||||
extern bool g_isDevice;
|
extern bool g_isDevice;
|
||||||
extern bool f_isTXT;
|
extern bool f_isTXT;
|
||||||
@@ -19,7 +19,7 @@ extern int32_t device;
|
|||||||
extern bool is_profi;
|
extern bool is_profi;
|
||||||
extern bool is_dump;
|
extern bool is_dump;
|
||||||
|
|
||||||
void* Utils::ReadBinFile(std::string fileName, uint32_t &fileSize)
|
void* Utils::ReadBinFile(std::string fileName, uint32_t& fileSize)
|
||||||
{
|
{
|
||||||
std::ifstream binFile(fileName, std::ifstream::binary);
|
std::ifstream binFile(fileName, std::ifstream::binary);
|
||||||
if (binFile.is_open() == false) {
|
if (binFile.is_open() == false) {
|
||||||
@@ -55,13 +55,13 @@ void* Utils::ReadBinFile(std::string fileName, uint32_t &fileSize)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
binFile.read(static_cast<char *>(binFileBufferData), binFileBufferLen);
|
binFile.read(static_cast<char*>(binFileBufferData), binFileBufferLen);
|
||||||
binFile.close();
|
binFile.close();
|
||||||
fileSize = binFileBufferLen;
|
fileSize = binFileBufferLen;
|
||||||
return binFileBufferData;
|
return binFileBufferData;
|
||||||
}
|
}
|
||||||
|
|
||||||
void* Utils::GetDeviceBufferOfFile(std::string fileName, uint32_t &fileSize)
|
void* Utils::GetDeviceBufferOfFile(std::string fileName, uint32_t& fileSize)
|
||||||
{
|
{
|
||||||
uint32_t inputHostBuffSize = 0;
|
uint32_t inputHostBuffSize = 0;
|
||||||
void* inputHostBuff = Utils::ReadBinFile(fileName, inputHostBuffSize);
|
void* inputHostBuff = Utils::ReadBinFile(fileName, inputHostBuffSize);
|
||||||
@@ -69,7 +69,7 @@ void* Utils::GetDeviceBufferOfFile(std::string fileName, uint32_t &fileSize)
|
|||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
if (!g_isDevice) {
|
if (!g_isDevice) {
|
||||||
void *inBufferDev = nullptr;
|
void* inBufferDev = nullptr;
|
||||||
uint32_t inBufferSize = inputHostBuffSize;
|
uint32_t inBufferSize = inputHostBuffSize;
|
||||||
aclError ret = aclrtMalloc(&inBufferDev, inBufferSize, ACL_MEM_MALLOC_NORMAL_ONLY);
|
aclError ret = aclrtMalloc(&inBufferDev, inBufferSize, ACL_MEM_MALLOC_NORMAL_ONLY);
|
||||||
if (ret != ACL_ERROR_NONE) {
|
if (ret != ACL_ERROR_NONE) {
|
||||||
@@ -100,9 +100,8 @@ void Utils::SplitString(std::string& s, std::vector<std::string>& v, char c)
|
|||||||
std::string::size_type pos1, pos2;
|
std::string::size_type pos1, pos2;
|
||||||
pos2 = s.find(c);
|
pos2 = s.find(c);
|
||||||
pos1 = 0;
|
pos1 = 0;
|
||||||
while(std::string::npos != pos2)
|
while (std::string::npos != pos2) {
|
||||||
{
|
std::string s1 = s.substr(pos1, pos2 - pos1);
|
||||||
std::string s1 = s.substr(pos1, pos2-pos1);
|
|
||||||
size_t n = s1.find_last_not_of(" \r\n\t");
|
size_t n = s1.find_last_not_of(" \r\n\t");
|
||||||
if (n != string::npos) {
|
if (n != string::npos) {
|
||||||
s1.erase(n + 1, s.size() - n);
|
s1.erase(n + 1, s.size() - n);
|
||||||
@@ -115,8 +114,7 @@ void Utils::SplitString(std::string& s, std::vector<std::string>& v, char c)
|
|||||||
pos1 = pos2 + 1;
|
pos1 = pos2 + 1;
|
||||||
pos2 = s.find(c, pos1);
|
pos2 = s.find(c, pos1);
|
||||||
}
|
}
|
||||||
if(pos1 != s.length())
|
if (pos1 != s.length()) {
|
||||||
{
|
|
||||||
std::string s1 = s.substr(pos1);
|
std::string s1 = s.substr(pos1);
|
||||||
size_t n = s1.find_last_not_of(" \r\n\t");
|
size_t n = s1.find_last_not_of(" \r\n\t");
|
||||||
if (n != string::npos) {
|
if (n != string::npos) {
|
||||||
@@ -130,17 +128,15 @@ void Utils::SplitString(std::string& s, std::vector<std::string>& v, char c)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int Utils::str2num(char *str)
|
int Utils::str2num(char* str)
|
||||||
{
|
{
|
||||||
int n = 0;
|
int n = 0;
|
||||||
int flag = 0;
|
int flag = 0;
|
||||||
while(*str >= '0' && *str <= '9')
|
while (*str >= '0' && *str <= '9') {
|
||||||
{
|
n = n * 10 + (*str - '0');
|
||||||
n = n*10 + (*str - '0');
|
|
||||||
str++;
|
str++;
|
||||||
}
|
}
|
||||||
if(flag == 1)
|
if (flag == 1) {
|
||||||
{
|
|
||||||
n = -n;
|
n = -n;
|
||||||
}
|
}
|
||||||
return n;
|
return n;
|
||||||
@@ -148,71 +144,67 @@ int Utils::str2num(char *str)
|
|||||||
|
|
||||||
std::string Utils::modelName(string& s)
|
std::string Utils::modelName(string& s)
|
||||||
{
|
{
|
||||||
string::size_type position1,position2;
|
string::size_type position1, position2;
|
||||||
position1 = s.find_last_of("/");
|
position1 = s.find_last_of("/");
|
||||||
if (position1 == s.npos)
|
if (position1 == s.npos) {
|
||||||
{
|
position1 = 0;
|
||||||
position1 = 0;
|
}
|
||||||
}
|
position2 = s.find_last_of(".");
|
||||||
position2 = s.find_last_of(".");
|
std::string modelName = s.substr(position1, position2 - position1);
|
||||||
std::string modelName = s.substr(position1,position2-position1);
|
return modelName;
|
||||||
return modelName;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string Utils::TimeLine()
|
std::string Utils::TimeLine()
|
||||||
{
|
{
|
||||||
time_t currentTime = time(NULL);
|
time_t currentTime = time(NULL);
|
||||||
char chCurrentTime[64];
|
char chCurrentTime[64];
|
||||||
strftime(chCurrentTime, sizeof(chCurrentTime), "%Y%m%d_%H%M%S", localtime(¤tTime));
|
strftime(chCurrentTime, sizeof(chCurrentTime), "%Y%m%d_%H%M%S", localtime(¤tTime));
|
||||||
std::string stCurrentTime = chCurrentTime;
|
std::string stCurrentTime = chCurrentTime;
|
||||||
return stCurrentTime;
|
return stCurrentTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Utils::printCurrentTime()
|
void Utils::printCurrentTime()
|
||||||
{
|
{
|
||||||
char szBuf[256] = {0};
|
char szBuf[256] = { 0 };
|
||||||
struct timeval tv;
|
struct timeval tv;
|
||||||
struct timezone tz;
|
struct timezone tz;
|
||||||
struct tm *p;
|
struct tm* p = nullptr;
|
||||||
|
|
||||||
gettimeofday(&tv, &tz);
|
gettimeofday(&tv, &tz);
|
||||||
p = localtime(&tv.tv_sec);
|
p = localtime(&tv.tv_sec);
|
||||||
printf("%02d-%02d-%02d %02d:%02d:%02d.%06ld\n", p->tm_year + 1900, p->tm_mon + 1, p->tm_mday, p->tm_hour, p->tm_min, p->tm_sec, tv.tv_usec);
|
printf("%02d-%02d-%02d %02d:%02d:%02d.%06ld\n", p->tm_year + 1900, p->tm_mon + 1, p->tm_mday, p->tm_hour, p->tm_min, p->tm_sec, tv.tv_usec);
|
||||||
|
|
||||||
}
|
}
|
||||||
void Utils::printHelpLetter()
|
void Utils::printHelpLetter()
|
||||||
{
|
{
|
||||||
cout<< endl;
|
cout << endl;
|
||||||
cout<< "Usage:" << endl;
|
cout << "Usage:" << endl;
|
||||||
cout<< "generate offline model inference output file example:" << endl;
|
cout << "generate offline model inference output file example:" << endl;
|
||||||
cout<< "./msame --model /home/HwHiAiUser/ljj/colorization.om --input /home/HwHiAiUser/ljj/colorization_input.bin --output /home/HwHiAiUser/ljj/AMEXEC/out/output1 --outfmt TXT --loop 2" << endl << endl;
|
cout << "./msame --model /home/HwHiAiUser/ljj/colorization.om --input /home/HwHiAiUser/ljj/colorization_input.bin --output /home/HwHiAiUser/ljj/AMEXEC/out/output1 --outfmt TXT --loop 2" << endl
|
||||||
|
<< endl;
|
||||||
|
|
||||||
cout<< "arguments explain:" << endl;
|
cout << "arguments explain:" << endl;
|
||||||
cout<< " --model Model file path" << endl;
|
cout << " --model Model file path" << endl;
|
||||||
cout<< " --input Input data path(only accept binary data file) If there are several file, please seprate by ','" << endl;
|
cout << " --input Input data path(only accept binary data file) If there are several file, please seprate by ','" << endl;
|
||||||
cout<< " --output Output path(User needs to have permission to create directories)" << endl;
|
cout << " --output Output path(User needs to have permission to create directories)" << endl;
|
||||||
cout<< " --outfmt Output file format (TXT or BIN)" << endl;
|
cout << " --outfmt Output file format (TXT or BIN)" << endl;
|
||||||
cout<< " --loop loop time(must in 1 to 100)" << endl;
|
cout << " --loop loop time(must in 1 to 100)" << endl;
|
||||||
cout<< " --dump Enable dump (true or false)(Do not support now)" << endl;
|
cout << " --dump Enable dump (true or false)(Do not support now)" << endl;
|
||||||
cout<< " --profiler Enable profiler (true or false)" << endl;
|
cout << " --profiler Enable profiler (true or false)" << endl;
|
||||||
cout<< " --device Designated the device ID(must in 0 to 255)" << endl;
|
cout << " --device Designated the device ID(must in 0 to 255)" << endl;
|
||||||
cout<< " --debug Debug switch,print model information (true or false)" << endl;
|
cout << " --debug Debug switch,print model information (true or false)" << endl;
|
||||||
cout<< " --dymBatch dynamic batch (Do not support now)" << endl << endl << endl;
|
cout << " --dymBatch dynamic batch (Do not support now)" << endl
|
||||||
|
<< endl
|
||||||
|
<< endl;
|
||||||
// cout<< "NOTECE: " << endl;
|
|
||||||
// cout<< " The order of parameter must follow in --model --input --output --outfmt --loop " << endl;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
double Utils::printDiffTime(time_t begin, time_t end)
|
double Utils::printDiffTime(time_t begin, time_t end)
|
||||||
{
|
{
|
||||||
double diffT = difftime(begin, end);
|
double diffT = difftime(begin, end);
|
||||||
printf("The inference time is: %f millisecond\n", 1000*diffT);
|
printf("The inference time is: %f millisecond\n", 1000 * diffT);
|
||||||
return diffT * 1000;
|
return diffT * 1000;
|
||||||
}
|
}
|
||||||
|
|
||||||
double Utils::InferenceTimeAverage(double *x, int len)
|
double Utils::InferenceTimeAverage(double* x, int len)
|
||||||
{
|
{
|
||||||
double sum = 0;
|
double sum = 0;
|
||||||
for (int i = 0; i < len; i++)
|
for (int i = 0; i < len; i++)
|
||||||
@@ -220,54 +212,43 @@ double Utils::InferenceTimeAverage(double *x, int len)
|
|||||||
return sum / len;
|
return sum / len;
|
||||||
}
|
}
|
||||||
|
|
||||||
double Utils::InferenceTimeAverageWithoutFirst(double *x, int len)
|
double Utils::InferenceTimeAverageWithoutFirst(double* x, int len)
|
||||||
{
|
{
|
||||||
double sum = 0;
|
double sum = 0;
|
||||||
for (int i = 0; i < len; i++)
|
for (int i = 0; i < len; i++)
|
||||||
if (i !=0){
|
if (i != 0) {
|
||||||
sum += x[i];
|
sum += x[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
return sum / (len - 1);
|
return sum / (len - 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Utils::ProfilerJson(bool isprof, map<char,string>& params)
|
void Utils::ProfilerJson(bool isprof, map<char, string>& params)
|
||||||
{
|
{
|
||||||
if (isprof){
|
if (isprof) {
|
||||||
std::string out_path = params['o'].c_str();
|
std::string out_path = params['o'].c_str();
|
||||||
std::string out_profiler_path = out_path + "/profiler";
|
std::string out_profiler_path = out_path + "/profiler";
|
||||||
ofstream outstr("acl.json", ios::out);
|
ofstream outstr("acl.json", ios::out);
|
||||||
outstr << "{\n\"profiler\": {\n \"switch\": \"on\",\n \"device_id\": \"";
|
outstr << "{\n\"profiler\": {\n \"switch\": \"on\",\n \"device_id\": \"";
|
||||||
outstr << device << "\",\n \"result_path\": \"" << out_profiler_path << "\",\n ";
|
outstr << device << "\",\n \"result_path\": \"" << out_profiler_path << "\",\n ";
|
||||||
outstr << "\"ai_core_metrics\": \"\"}\n}";
|
outstr << "\"ai_core_metrics\": \"\"}\n}";
|
||||||
//outstr << "\"ai_core_metrics\": \"aicorePipelineStall\"}\n}";
|
|
||||||
//outstr <<"}]n}";
|
|
||||||
outstr.close();
|
outstr.close();
|
||||||
|
|
||||||
//mkdir profiler output dir
|
//mkdir profiler output dir
|
||||||
const char* temp_s = out_path.c_str();
|
const char* temp_s = out_path.c_str();
|
||||||
if (NULL == opendir(temp_s)){
|
if (NULL == opendir(temp_s)) {
|
||||||
mkdir(temp_s,0775);
|
mkdir(temp_s, 0775);
|
||||||
}
|
}
|
||||||
const char* temp_s1 = out_profiler_path.c_str();
|
const char* temp_s1 = out_profiler_path.c_str();
|
||||||
if (NULL == opendir(temp_s1)){
|
if (NULL == opendir(temp_s1)) {
|
||||||
mkdir(temp_s1,0775);
|
mkdir(temp_s1, 0775);
|
||||||
}
|
}
|
||||||
/*{
|
|
||||||
"profiler": {
|
|
||||||
"switch": "on",
|
|
||||||
"device_id": "all",
|
|
||||||
"result_path": "/home/HwHiAiUser",
|
|
||||||
"ai_core_metrics": "aicorePipelineStall"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Utils::DumpJson(bool isdump, map<char,string>& params)
|
void Utils::DumpJson(bool isdump, map<char, string>& params)
|
||||||
{
|
{
|
||||||
if (is_dump){
|
if (is_dump) {
|
||||||
std::string modelPath = params['m'].c_str();
|
std::string modelPath = params['m'].c_str();
|
||||||
std::string modelName = Utils::modelName(modelPath);
|
std::string modelName = Utils::modelName(modelPath);
|
||||||
std::string out_path = params['o'].c_str();
|
std::string out_path = params['o'].c_str();
|
||||||
@@ -282,21 +263,12 @@ void Utils::DumpJson(bool isdump, map<char,string>& params)
|
|||||||
|
|
||||||
//mkdir dump output dir
|
//mkdir dump output dir
|
||||||
const char* temp_s = out_path.c_str();
|
const char* temp_s = out_path.c_str();
|
||||||
if (NULL == opendir(temp_s)){
|
if (NULL == opendir(temp_s)) {
|
||||||
mkdir(temp_s,0775);
|
mkdir(temp_s, 0775);
|
||||||
}
|
}
|
||||||
const char* temp_s1 = out_dump_path.c_str();
|
const char* temp_s1 = out_dump_path.c_str();
|
||||||
if (NULL == opendir(temp_s1)){
|
if (NULL == opendir(temp_s1)) {
|
||||||
mkdir(temp_s1,0775);
|
mkdir(temp_s1, 0775);
|
||||||
}
|
}
|
||||||
// {
|
|
||||||
// "dump": {
|
|
||||||
// "dump_path": "output_path",
|
|
||||||
// "dump_mode": "output",
|
|
||||||
// "dump_list": [{
|
|
||||||
// "model_name": "model_name",
|
|
||||||
// }]
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user