add profiler
This commit is contained in:
@@ -47,6 +47,11 @@ public:
|
|||||||
*/
|
*/
|
||||||
Result CreateDesc();
|
Result CreateDesc();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief PrintDesc
|
||||||
|
*/
|
||||||
|
Result PrintDesc();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief destroy desc
|
* @brief destroy desc
|
||||||
*/
|
*/
|
||||||
@@ -60,6 +65,12 @@ public:
|
|||||||
*/
|
*/
|
||||||
Result CreateInput(void *inputDataBuffer, size_t bufferSize);
|
Result CreateInput(void *inputDataBuffer, size_t bufferSize);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief create model input
|
||||||
|
* @return result
|
||||||
|
*/
|
||||||
|
Result CreateZeroInput();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief destroy input resource
|
* @brief destroy input resource
|
||||||
*/
|
*/
|
||||||
@@ -103,4 +114,6 @@ private:
|
|||||||
aclmdlDesc *modelDesc_;
|
aclmdlDesc *modelDesc_;
|
||||||
aclmdlDataset *input_;
|
aclmdlDataset *input_;
|
||||||
aclmdlDataset *output_;
|
aclmdlDataset *output_;
|
||||||
|
size_t numInputs_;
|
||||||
|
size_t numOutputs_;
|
||||||
};
|
};
|
||||||
@@ -12,6 +12,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
#include "acl/acl.h"
|
#include "acl/acl.h"
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -21,8 +21,13 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
#include <sys/time.h>
|
#include <sys/time.h>
|
||||||
|
#include <dirent.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
|
#include <cstddef>
|
||||||
|
|
||||||
#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 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)
|
||||||
|
|
||||||
@@ -72,6 +77,10 @@ public:
|
|||||||
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 DumpJson(bool isdump, map<char,string>& params);
|
||||||
};
|
};
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|||||||
Binary file not shown.
+39
-4
@@ -17,6 +17,10 @@ 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;
|
||||||
|
int32_t device = 0;
|
||||||
|
bool is_profi = false;
|
||||||
|
bool is_dump = false;
|
||||||
|
bool is_debug = false;
|
||||||
string input_Ftype = ".bin";
|
string input_Ftype = ".bin";
|
||||||
string model_Ftype = ".om";
|
string model_Ftype = ".om";
|
||||||
string check = "";
|
string check = "";
|
||||||
@@ -24,17 +28,19 @@ 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)
|
//void InitAndCheckParams(int argc, char* argv[], vector<string>& params, vector<string>& inputs)
|
||||||
{
|
{
|
||||||
const char *optstring="m::i::o::f::hd::p::l::y::";
|
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},
|
||||||
{"dumpConf",required_argument,NULL,'d'},
|
{"dump",required_argument,NULL,'d'},
|
||||||
{"profConf",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'},
|
||||||
|
{"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)
|
||||||
{
|
{
|
||||||
@@ -95,6 +101,18 @@ void InitAndCheckParams(int argc, char* argv[], map<char,string>& params, vector
|
|||||||
// params.push_back(optarg);
|
// params.push_back(optarg);
|
||||||
params['y'] = optarg;
|
params['y'] = optarg;
|
||||||
break;
|
break;
|
||||||
|
case 'e':
|
||||||
|
device = Utils::str2num(optarg);
|
||||||
|
cout << "device:" << device << endl;
|
||||||
|
if (device > 255 || device < 0)
|
||||||
|
{
|
||||||
|
printf("device id must in 0 to 255\n");
|
||||||
|
exit(0);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 'g':
|
||||||
|
params['g'] = optarg;
|
||||||
|
break;
|
||||||
case 1:
|
case 1:
|
||||||
Utils::printHelpLetter();
|
Utils::printHelpLetter();
|
||||||
exit(0);
|
exit(0);
|
||||||
@@ -117,13 +135,30 @@ int main(int argc, char* argv[])
|
|||||||
printf("Test Start!\n");
|
printf("Test Start!\n");
|
||||||
|
|
||||||
|
|
||||||
if (params.empty() || inputs.empty()) {
|
if (params.empty()) {
|
||||||
printf("Invalid params.\n");
|
printf("Invalid params.\n");
|
||||||
printf("Execute sample failed.\n");
|
printf("Execute sample failed.\n");
|
||||||
Utils::printHelpLetter();
|
Utils::printHelpLetter();
|
||||||
return FAILED;
|
return FAILED;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (params['d'].compare("true") == 0) {
|
||||||
|
is_dump = true;
|
||||||
|
}
|
||||||
|
if (params['p'].compare("true") == 0) {
|
||||||
|
is_profi = true;
|
||||||
|
}
|
||||||
|
if (params['g'].compare("true") == 0) {
|
||||||
|
is_debug = true;
|
||||||
|
}
|
||||||
|
if (is_profi && is_dump){
|
||||||
|
ERROR_LOG("dump and profiler can not both be true");
|
||||||
|
return FAILED;
|
||||||
|
}
|
||||||
|
|
||||||
|
Utils::ProfilerJson(is_profi, params);
|
||||||
|
Utils::DumpJson(is_dump, params);
|
||||||
|
|
||||||
SampleProcess processSample;
|
SampleProcess processSample;
|
||||||
|
|
||||||
Result ret = processSample.InitResource();
|
Result ret = processSample.InitResource();
|
||||||
|
|||||||
@@ -21,7 +21,8 @@ extern bool g_isDevice;
|
|||||||
extern bool f_isTXT;
|
extern bool f_isTXT;
|
||||||
|
|
||||||
ModelProcess::ModelProcess() :modelId_(0), modelMemSize_(0), modelWeightSize_(0), modelMemPtr_(nullptr),
|
ModelProcess::ModelProcess() :modelId_(0), modelMemSize_(0), modelWeightSize_(0), modelMemPtr_(nullptr),
|
||||||
modelWeightPtr_(nullptr), loadFlag_(false), modelDesc_(nullptr), input_(nullptr), output_(nullptr)
|
modelWeightPtr_(nullptr), loadFlag_(false), modelDesc_(nullptr), input_(nullptr), output_(nullptr), numInputs_(0),
|
||||||
|
numOutputs_(0)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -89,6 +90,83 @@ Result ModelProcess::CreateDesc()
|
|||||||
return SUCCESS;
|
return SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Result ModelProcess::PrintDesc()
|
||||||
|
{ aclError ret;
|
||||||
|
DEBUG_LOG("start print model description");
|
||||||
|
size_t numInputs = aclmdlGetNumInputs(modelDesc_);
|
||||||
|
size_t numOutputs = aclmdlGetNumOutputs(modelDesc_);
|
||||||
|
DEBUG_LOG("NumInputs: %zu", numInputs);
|
||||||
|
DEBUG_LOG("NumOutputs: %zu", numOutputs);
|
||||||
|
|
||||||
|
aclmdlIODims dimsInput;
|
||||||
|
aclmdlIODims dimsOutput;
|
||||||
|
aclmdlIODims dimsCurrentOutput;
|
||||||
|
for (size_t i = 0; i < numInputs; i++){
|
||||||
|
DEBUG_LOG("the size of %zu input: %zu", i, aclmdlGetInputSizeByIndex(modelDesc_, i));
|
||||||
|
ret = aclmdlGetInputDims(modelDesc_, i, &dimsInput);
|
||||||
|
DEBUG_LOG("the dims of %zu input:", i);
|
||||||
|
for (size_t j = 0; j < dimsInput.dimCount; j++){
|
||||||
|
cout << dimsInput.dims[j] << " ";
|
||||||
|
}
|
||||||
|
cout << endl;
|
||||||
|
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 DataType of %zu input: %u", i, aclmdlGetInputFormat(modelDesc_, i));
|
||||||
|
}
|
||||||
|
for (size_t i = 0; i < numOutputs; i++){
|
||||||
|
DEBUG_LOG("the size of %zu output: %zu", i, aclmdlGetOutputSizeByIndex(modelDesc_, i));
|
||||||
|
ret = aclmdlGetOutputDims(modelDesc_, i, &dimsOutput);
|
||||||
|
DEBUG_LOG("the dims of %zu output:", i);
|
||||||
|
for (size_t j = 0; j < dimsOutput.dimCount; j++){
|
||||||
|
cout <<dimsOutput.dims[j] << " ";
|
||||||
|
}
|
||||||
|
cout << endl;
|
||||||
|
ret = aclmdlGetCurOutputDims(modelDesc_, i, &dimsCurrentOutput);
|
||||||
|
DEBUG_LOG("the dims of %zu current output:", i);
|
||||||
|
for (size_t j = 0; j < dimsCurrentOutput.dimCount; j++){
|
||||||
|
cout <<dimsCurrentOutput.dims[j] << " ";
|
||||||
|
}
|
||||||
|
cout << endl;
|
||||||
|
DEBUG_LOG("the name of %zu output: %s", i, aclmdlGetOutputNameByIndex(modelDesc_, i));
|
||||||
|
DEBUG_LOG("the Format of %zu output: %u", i, aclmdlGetOutputFormat(modelDesc_, i));
|
||||||
|
DEBUG_LOG("the DataType of %zu output: %u", i, aclmdlGetOutputFormat(modelDesc_, i));
|
||||||
|
}
|
||||||
|
aclmdlBatch batch_info;
|
||||||
|
ret = aclmdlGetDynamicBatch(modelDesc_, &batch_info);
|
||||||
|
if (ret != ACL_ERROR_NONE) {
|
||||||
|
ERROR_LOG("get DynamicBatch failed");
|
||||||
|
(void)aclmdlDestroyDesc(modelDesc_);
|
||||||
|
modelDesc_ = nullptr;
|
||||||
|
return FAILED;
|
||||||
|
}
|
||||||
|
if (batch_info.batchCount != 0) {
|
||||||
|
DEBUG_LOG("DynamicBatch:");
|
||||||
|
for (size_t i = 0; i < batch_info.batchCount; i++){
|
||||||
|
cout << batch_info.batch[i] << " ";
|
||||||
|
}
|
||||||
|
cout << endl;
|
||||||
|
}
|
||||||
|
aclmdlHW dynamicHW;
|
||||||
|
ret = aclmdlGetDynamicHW(modelDesc_, -1, &dynamicHW);
|
||||||
|
if (ret != ACL_ERROR_NONE) {
|
||||||
|
ERROR_LOG("get DynamicHW failed");
|
||||||
|
(void)aclmdlDestroyDesc(modelDesc_);
|
||||||
|
modelDesc_ = nullptr;
|
||||||
|
return FAILED;
|
||||||
|
}
|
||||||
|
if (dynamicHW.hwCount != 0) {
|
||||||
|
DEBUG_LOG("DynamicHW:");
|
||||||
|
for (size_t i = 0; i < dynamicHW.hwCount; i++) {
|
||||||
|
cout << dynamicHW.hw[i][0] << dynamicHW.hw[i][1] << " ";
|
||||||
|
}
|
||||||
|
cout << endl;
|
||||||
|
}
|
||||||
|
DEBUG_LOG("end print model description");
|
||||||
|
return SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void ModelProcess::DestroyDesc()
|
void ModelProcess::DestroyDesc()
|
||||||
{
|
{
|
||||||
if (modelDesc_ != nullptr) {
|
if (modelDesc_ != nullptr) {
|
||||||
@@ -120,12 +198,73 @@ Result ModelProcess::CreateInput(void *inputDataBuffer, size_t bufferSize)
|
|||||||
inputData = nullptr;
|
inputData = nullptr;
|
||||||
return FAILED;
|
return FAILED;
|
||||||
}
|
}
|
||||||
size_t aa = aclmdlGetDatasetNumBuffers(input_);
|
|
||||||
|
|
||||||
|
|
||||||
return SUCCESS;
|
return SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Result ModelProcess::CreateZeroInput(){
|
||||||
|
if (input_ == nullptr) {
|
||||||
|
input_ = aclmdlCreateDataset();
|
||||||
|
if (input_ == nullptr) {
|
||||||
|
ERROR_LOG("can't create dataset, create input failed");
|
||||||
|
return FAILED;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
numInputs_ = aclmdlGetNumInputs(modelDesc_);
|
||||||
|
for (size_t i = 0; i < numInputs_; i++){
|
||||||
|
size_t buffer_size_zero = aclmdlGetInputSizeByIndex(modelDesc_, i);
|
||||||
|
void *inBufferDev = nullptr;
|
||||||
|
if (!g_isDevice) {
|
||||||
|
void* binFileBufferData = nullptr;
|
||||||
|
aclError ret = aclrtMallocHost(&binFileBufferData, buffer_size_zero);
|
||||||
|
if (ret != ACL_ERROR_NONE) {
|
||||||
|
ERROR_LOG("malloc host buffer failed. size is %zu", buffer_size_zero);
|
||||||
|
return FAILED;
|
||||||
|
}
|
||||||
|
memset(binFileBufferData,0,buffer_size_zero);
|
||||||
|
ret = aclrtMalloc(&inBufferDev, buffer_size_zero, ACL_MEM_MALLOC_NORMAL_ONLY);
|
||||||
|
if (ret != ACL_ERROR_NONE) {
|
||||||
|
ERROR_LOG("malloc device buffer failed. size is %zu", buffer_size_zero);
|
||||||
|
return FAILED;
|
||||||
|
}
|
||||||
|
ret = aclrtMemcpy(inBufferDev, buffer_size_zero, binFileBufferData, buffer_size_zero, ACL_MEMCPY_HOST_TO_DEVICE);
|
||||||
|
if (ret != ACL_ERROR_NONE) {
|
||||||
|
ERROR_LOG("memcpy failed. device buffer size is %zu, input host buffer size is %zu", buffer_size_zero, buffer_size_zero);
|
||||||
|
aclrtFree(inBufferDev);
|
||||||
|
aclrtFreeHost(binFileBufferData);
|
||||||
|
return FAILED;
|
||||||
|
}
|
||||||
|
}else{
|
||||||
|
aclError ret = aclrtMalloc(&inBufferDev, buffer_size_zero, ACL_MEM_MALLOC_NORMAL_ONLY);
|
||||||
|
if (ret != ACL_ERROR_NONE) {
|
||||||
|
ERROR_LOG("malloc device buffer failed. size is %zu", buffer_size_zero);
|
||||||
|
return FAILED;
|
||||||
|
}
|
||||||
|
memset(inBufferDev,0,buffer_size_zero);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
aclDataBuffer* inputData = aclCreateDataBuffer(inBufferDev, buffer_size_zero);
|
||||||
|
if (inputData == nullptr) {
|
||||||
|
ERROR_LOG("can't create data buffer, create input failed");
|
||||||
|
aclrtFree(inBufferDev);
|
||||||
|
inBufferDev = nullptr;
|
||||||
|
return FAILED;
|
||||||
|
}
|
||||||
|
aclError ret = aclmdlAddDatasetBuffer(input_, inputData);
|
||||||
|
if (ret != ACL_ERROR_NONE) {
|
||||||
|
ERROR_LOG("add input dataset buffer failed");
|
||||||
|
aclrtFree(inBufferDev);
|
||||||
|
inBufferDev = nullptr;
|
||||||
|
aclDestroyDataBuffer(inputData);
|
||||||
|
inputData = nullptr;
|
||||||
|
return FAILED;
|
||||||
|
}
|
||||||
|
aclrtFree(inBufferDev);
|
||||||
|
inBufferDev = nullptr;
|
||||||
|
return SUCCESS;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void ModelProcess::DestroyInput()
|
void ModelProcess::DestroyInput()
|
||||||
{
|
{
|
||||||
if (input_ == nullptr) {
|
if (input_ == nullptr) {
|
||||||
|
|||||||
@@ -17,6 +17,11 @@ using namespace std;
|
|||||||
extern bool g_isDevice;
|
extern bool g_isDevice;
|
||||||
extern bool f_isTXT;
|
extern bool f_isTXT;
|
||||||
extern int loop;
|
extern int loop;
|
||||||
|
extern int32_t device;
|
||||||
|
extern bool is_debug;
|
||||||
|
extern bool is_profi;
|
||||||
|
extern bool is_dump;
|
||||||
|
|
||||||
|
|
||||||
SampleProcess::SampleProcess() :deviceId_(0), context_(nullptr), stream_(nullptr)
|
SampleProcess::SampleProcess() :deviceId_(0), context_(nullptr), stream_(nullptr)
|
||||||
{
|
{
|
||||||
@@ -30,15 +35,31 @@ SampleProcess::~SampleProcess()
|
|||||||
Result SampleProcess::InitResource()
|
Result SampleProcess::InitResource()
|
||||||
{
|
{
|
||||||
// ACL init
|
// ACL init
|
||||||
const char *aclConfigPath = "";
|
aclError ret;
|
||||||
aclError ret = aclInit(nullptr);
|
const char *aclConfigPath = "acl.json";
|
||||||
|
if (is_profi == true){
|
||||||
|
ret = aclInit(aclConfigPath);
|
||||||
|
} else
|
||||||
|
{
|
||||||
|
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
|
||||||
|
deviceId_ = device;
|
||||||
ret = aclrtSetDevice(deviceId_);
|
ret = aclrtSetDevice(deviceId_);
|
||||||
if (ret != ACL_ERROR_NONE) {
|
if (ret != ACL_ERROR_NONE) {
|
||||||
ERROR_LOG("acl open device %d failed", deviceId_);
|
ERROR_LOG("acl open device %d failed", deviceId_);
|
||||||
@@ -71,6 +92,17 @@ 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;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -83,9 +115,6 @@ Result SampleProcess::Process(map<char,string>& params, vector<string>& input_fi
|
|||||||
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);
|
||||||
const char* dumpConf = params['d'].c_str();
|
|
||||||
const char* profConf = params['p'].c_str();
|
|
||||||
const char* dymBatch = params['y'].c_str();
|
|
||||||
|
|
||||||
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);
|
||||||
@@ -104,13 +133,38 @@ 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){
|
||||||
|
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();
|
||||||
|
if (ret != SUCCESS) {
|
||||||
|
ERROR_LOG("print model descrtption failed");
|
||||||
|
return FAILED;
|
||||||
|
}
|
||||||
|
}
|
||||||
ret = processModel.CreateOutput();
|
ret = processModel.CreateOutput();
|
||||||
if (ret != SUCCESS) {
|
if (ret != SUCCESS) {
|
||||||
ERROR_LOG("create model output failed");
|
ERROR_LOG("create model output failed");
|
||||||
return FAILED;
|
return FAILED;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (input_files.empty() == 1) {
|
||||||
|
ret = processModel.CreateZeroInput();
|
||||||
|
if (ret != SUCCESS) {
|
||||||
|
ERROR_LOG("model create input failed");
|
||||||
|
return FAILED;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
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());
|
||||||
@@ -123,14 +177,16 @@ Result SampleProcess::Process(map<char,string>& params, vector<string>& input_fi
|
|||||||
}
|
}
|
||||||
|
|
||||||
ret = processModel.CreateInput(picDevBuffer[index], devBufferSize);
|
ret = processModel.CreateInput(picDevBuffer[index], devBufferSize);
|
||||||
if (ret != SUCCESS) {
|
|
||||||
ERROR_LOG("model create input failed");
|
|
||||||
for (size_t i = 0; i < index; i++) {
|
for (size_t i = 0; i < index; i++) {
|
||||||
aclrtFree (picDevBuffer[i]);
|
aclrtFree (picDevBuffer[i]);
|
||||||
}
|
}
|
||||||
|
if (ret != SUCCESS) {
|
||||||
|
ERROR_LOG("model create input failed");
|
||||||
return FAILED;
|
return FAILED;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// loop end
|
// loop end
|
||||||
for (size_t t = 0; t < loop; ++t) {
|
for (size_t t = 0; t < loop; ++t) {
|
||||||
gettimeofday(&begin, NULL);
|
gettimeofday(&begin, NULL);
|
||||||
@@ -140,9 +196,9 @@ 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++) {
|
// for (size_t i = 0; i < input_files.size(); i++) {
|
||||||
aclrtFree(picDevBuffer[i]);
|
// aclrtFree(picDevBuffer[i]);
|
||||||
}
|
// }
|
||||||
return FAILED;
|
return FAILED;
|
||||||
}
|
}
|
||||||
processModel.OutputModelResult(output_path, modelName, t);
|
processModel.OutputModelResult(output_path, modelName, t);
|
||||||
@@ -155,10 +211,19 @@ Result SampleProcess::Process(map<char,string>& params, vector<string>& input_fi
|
|||||||
}
|
}
|
||||||
processModel.DestroyInput();
|
processModel.DestroyInput();
|
||||||
|
|
||||||
// release model input buffer
|
if (is_dump || is_profi){
|
||||||
for (size_t i = 0; i < input_files.size(); i++) {
|
if (remove("acl.json")==0){
|
||||||
aclrtFree(picDevBuffer[i]);
|
INFO_LOG("delete acl.json success");
|
||||||
}
|
}
|
||||||
|
else{
|
||||||
|
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;
|
||||||
}
|
}
|
||||||
@@ -190,6 +255,14 @@ 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");
|
||||||
|
|||||||
+99
-4
@@ -15,6 +15,9 @@
|
|||||||
using namespace std;
|
using namespace std;
|
||||||
extern bool g_isDevice;
|
extern bool g_isDevice;
|
||||||
extern bool f_isTXT;
|
extern bool f_isTXT;
|
||||||
|
extern int32_t device;
|
||||||
|
extern bool is_profi;
|
||||||
|
extern bool is_dump;
|
||||||
|
|
||||||
void* Utils::ReadBinFile(std::string fileName, uint32_t &fileSize)
|
void* Utils::ReadBinFile(std::string fileName, uint32_t &fileSize)
|
||||||
{
|
{
|
||||||
@@ -99,12 +102,32 @@ void Utils::SplitString(std::string& s, std::vector<std::string>& v, char c)
|
|||||||
pos1 = 0;
|
pos1 = 0;
|
||||||
while(std::string::npos != pos2)
|
while(std::string::npos != pos2)
|
||||||
{
|
{
|
||||||
v.push_back(s.substr(pos1, pos2-pos1));
|
std::string s1 = s.substr(pos1, pos2-pos1);
|
||||||
|
size_t n = s1.find_last_not_of(" \r\n\t");
|
||||||
|
if (n != string::npos) {
|
||||||
|
s1.erase(n + 1, s.size() - n);
|
||||||
|
}
|
||||||
|
n = s1.find_first_not_of(" \r\n\t");
|
||||||
|
if (n != string::npos) {
|
||||||
|
s1.erase(0, n);
|
||||||
|
}
|
||||||
|
v.push_back(s1);
|
||||||
pos1 = pos2 + 1;
|
pos1 = pos2 + 1;
|
||||||
pos2 = s.find(c, pos1);
|
pos2 = s.find(c, pos1);
|
||||||
}
|
}
|
||||||
if(pos1 != s.length())
|
if(pos1 != s.length())
|
||||||
v.push_back(s.substr(pos1));
|
{
|
||||||
|
std::string s1 = s.substr(pos1);
|
||||||
|
size_t n = s1.find_last_not_of(" \r\n\t");
|
||||||
|
if (n != string::npos) {
|
||||||
|
s1.erase(n + 1, s.size() - n);
|
||||||
|
}
|
||||||
|
n = s1.find_first_not_of(" \r\n\t");
|
||||||
|
if (n != string::npos) {
|
||||||
|
s1.erase(0, n);
|
||||||
|
}
|
||||||
|
v.push_back(s1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int Utils::str2num(char *str)
|
int Utils::str2num(char *str)
|
||||||
@@ -170,8 +193,10 @@ void Utils::printHelpLetter()
|
|||||||
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<< " --dumpConf dump configure file path (Do not support now)" << endl;
|
cout<< " --dump Enable dump (true or false)" << endl;
|
||||||
cout<< " --profConf profiling configure file path (Do not support now)" << endl;
|
cout<< " --profiler Enable profiler (true or false)" << 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<< " --dymBatch dynamic batch (Do not support now)" << endl << endl << endl;
|
cout<< " --dymBatch dynamic batch (Do not support now)" << endl << endl << endl;
|
||||||
|
|
||||||
|
|
||||||
@@ -205,3 +230,73 @@ double Utils::InferenceTimeAverageWithoutFirst(double *x, int len)
|
|||||||
|
|
||||||
return sum / (len - 1);
|
return sum / (len - 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Utils::ProfilerJson(bool isprof, map<char,string>& params)
|
||||||
|
{
|
||||||
|
if (isprof){
|
||||||
|
std::string out_path = params['o'].c_str();
|
||||||
|
std::string out_profiler_path = out_path + "/profiler";
|
||||||
|
ofstream outstr("acl.json", ios::out);
|
||||||
|
outstr << "{\n\"profiler\": {\n \"switch\": \"on\",\n \"device_id\": \"";
|
||||||
|
outstr << device << "\",\n \"result_path\": \"" << out_profiler_path << "\",\n ";
|
||||||
|
outstr << "\"ai_core_metrics\": \"\"}\n}";
|
||||||
|
//outstr << "\"ai_core_metrics\": \"aicorePipelineStall\"}\n}";
|
||||||
|
//outstr <<"}]n}";
|
||||||
|
outstr.close();
|
||||||
|
|
||||||
|
//mkdir profiler output dir
|
||||||
|
const char* temp_s = out_path.c_str();
|
||||||
|
if (NULL == opendir(temp_s)){
|
||||||
|
mkdir(temp_s,0775);
|
||||||
|
}
|
||||||
|
const char* temp_s1 = out_profiler_path.c_str();
|
||||||
|
if (NULL == opendir(temp_s1)){
|
||||||
|
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)
|
||||||
|
{
|
||||||
|
if (is_dump){
|
||||||
|
std::string modelPath = params['m'].c_str();
|
||||||
|
std::string modelName = Utils::modelName(modelPath);
|
||||||
|
std::string out_path = params['o'].c_str();
|
||||||
|
std::string out_dump_path = out_path + "/dump";
|
||||||
|
ofstream outstr("acl.json", ios::out);
|
||||||
|
outstr << "{\n\"dump\": {\n \"dump_path\": \"";
|
||||||
|
outstr << out_dump_path << "\",\n ";
|
||||||
|
outstr << "\"dump_mode\": \"output\",\n \"dump_list\": [{\n ";
|
||||||
|
outstr << " \"model_name\": \"" << modelName << "\",\n }]\n";
|
||||||
|
outstr << " }\n}";
|
||||||
|
outstr.close();
|
||||||
|
|
||||||
|
//mkdir dump output dir
|
||||||
|
const char* temp_s = out_path.c_str();
|
||||||
|
if (NULL == opendir(temp_s)){
|
||||||
|
mkdir(temp_s,0775);
|
||||||
|
}
|
||||||
|
const char* temp_s1 = out_dump_path.c_str();
|
||||||
|
if (NULL == opendir(temp_s1)){
|
||||||
|
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