diff --git a/msame/inc/model_process.h b/msame/inc/model_process.h old mode 100755 new mode 100644 index c0fa939851ba495bc2c6c80cd62f2612096c15fe..36fb0fc376e24d034047ee854d022d693fe08ad4 --- a/msame/inc/model_process.h +++ b/msame/inc/model_process.h @@ -1,46 +1,45 @@ -//Model_process.h - /** -* @file model_process.h -* -* Copyright (C) 2020. Huawei Technologies Co., Ltd. All rights reserved. -* -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. -*/ -#pragma once -#include "utils.h" + * @file model_process.h + * + * Copyright (C) 2020. Huawei Technologies Co., Ltd. All rights reserved. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + */ +#ifndef _MODEL_PROCESS_H_ +#define _MODEL_PROCESS_H_ #include "acl/acl.h" - -using namespace std; +#include "utils.h" +#include + /** -* ModelProcess -*/ + * ModelProcess + */ class ModelProcess { public: /** * @brief Constructor */ ModelProcess(); - + /** * @brief Destructor */ ~ModelProcess(); - + /** * @brief load model from file with mem * @param [in] modelPath: model path * @return result */ - Result LoadModelFromFileWithMem(const char *modelPath); - + Result LoadModelFromFileWithMem(const std::string& modelPath); + /** * @brief unload model */ void Unload(); - + /** * @brief create model desc * @return result @@ -51,69 +50,69 @@ public: * @brief PrintDesc */ Result PrintDesc(); - + /** * @brief destroy desc */ void DestroyDesc(); - + /** * @brief create model input * @param [in] inputDataBuffer: input buffer * @param [in] bufferSize: input buffer size * @return result */ - 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 */ void DestroyInput(); - + /** * @brief create output buffer * @return result */ Result CreateOutput(); - + /** * @brief destroy output resource */ void DestroyOutput(); - + /** * @brief model execute * @return result */ Result Execute(); - + /** * @brief dump model output result to file */ void DumpModelOutputResult(); - + /** * @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: uint32_t modelId_; size_t modelMemSize_; size_t modelWeightSize_; - void *modelMemPtr_; - void *modelWeightPtr_; + void* modelMemPtr_; + void* modelWeightPtr_; bool loadFlag_; // model load flag - aclmdlDesc *modelDesc_; - aclmdlDataset *input_; - aclmdlDataset *output_; + aclmdlDesc* modelDesc_; + aclmdlDataset* input_; + aclmdlDataset* output_; size_t numInputs_; size_t numOutputs_; -}; \ No newline at end of file +}; +#endif \ No newline at end of file diff --git a/msame/inc/sample_process.h b/msame/inc/sample_process.h old mode 100755 new mode 100644 index 95b1d215fcb607061797c3e073f6b201b91ba4f0..574231c66e62075b154bff44a727a6bb9f70dd26 --- a/msame/inc/sample_process.h +++ b/msame/inc/sample_process.h @@ -1,5 +1,3 @@ -//Sample_process.h - /** * @file sample_process.h * @@ -9,12 +7,12 @@ * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. */ -#pragma once -#include "utils.h" +#ifndef _SAMPLE_PROCESS_H_ +#define _SAMPLE_PROCESS_H_ #include "acl/acl.h" +#include "utils.h" #include - -using namespace std; + /** * SampleProcess */ @@ -24,28 +22,29 @@ public: * @brief Constructor */ SampleProcess(); - + /** * @brief Destructor */ ~SampleProcess(); - + /** * @brief init reousce * @return result */ Result InitResource(); - + /** * @brief sample process * @return result */ - Result Process(map& params, vector& inputs); - + Result Process(std::map& params, std::vector& inputs); + private: void DestroyResource(); - + int32_t deviceId_; aclrtContext context_; aclrtStream stream_; }; +#endif diff --git a/msame/inc/utils.h b/msame/inc/utils.h old mode 100755 new mode 100644 index d14cef9d5ba63f26aebb524a73b6930c59e3c0a0..9394bd439e2ad4645a2594a110eb001997992b47 --- a/msame/inc/utils.h +++ b/msame/inc/utils.h @@ -1,5 +1,3 @@ -//Util.h - /** * @file utils.h * @@ -9,36 +7,35 @@ * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. */ -#pragma once -#include -#include -#include +#ifndef _UTILS_H_ +#define _UTILS_H_ +#include +#include #include -#include +#include +#include +#include #include -#include -#include +#include #include -#include +#include +#include #include -#include #include -#include -#include - +#include +#include + #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 ERROR_LOG(fmt, args...) fprintf(stdout, "[ERROR] " fmt "\n", ##args) - -using namespace std; + //static size_t loop = 1; typedef enum Result { SUCCESS = 0, FAILED = 1 } Result; - /** * Utils */ @@ -50,8 +47,8 @@ public: * @param [out] fileSize: size 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 * @param [in] fileName: file name @@ -59,28 +56,28 @@ public: * @return buffer of pic */ static void* ReadBinFile(std::string fileName, uint32_t& fileSize); - + static void SplitString(std::string& s, std::vector& v, char c); - - static int str2num(char *str); - - static std::string modelName(string& s); - - static std::string TimeLine(); - - static void printCurrentTime(); - - static void printHelpLetter(); + + static int str2num(char* str); + + static std::string modelName(std::string& s); + + static std::string TimeLine(); + + static void printCurrentTime(); + + static void printHelpLetter(); static double printDiffTime(time_t begin, time_t end); - - static double InferenceTimeAverage(double *x, int len); - - static double InferenceTimeAverageWithoutFirst(double *x, int len); - static void ProfilerJson(bool isprof, map& params); + static double InferenceTimeAverage(double* x, int len); + + static double InferenceTimeAverageWithoutFirst(double* x, int len); - static void DumpJson(bool isdump, map& params); + static void ProfilerJson(bool isprof, std::map& params); + + static void DumpJson(bool isdump, std::map& params); }; - -#pragma once + +#endif diff --git a/msame/src/main.cpp b/msame/src/main.cpp old mode 100755 new mode 100644 index 8cef44af9a6d9df8d1d4333e40fdb8bf9c78f231..65b22ecc1b8c9d5a67c69e9294fe9b18b2310c2a --- a/msame/src/main.cpp +++ b/msame/src/main.cpp @@ -10,9 +10,8 @@ */ #include "sample_process.h" #include "utils.h" -#include +#include using namespace std; - bool f_isTXT = false; bool g_isDevice = false; @@ -25,54 +24,46 @@ string input_Ftype = ".bin"; string model_Ftype = ".om"; string check = ""; -void InitAndCheckParams(int argc, char* argv[], map& params, vector& inputs) -//void InitAndCheckParams(int argc, char* argv[], vector& params, vector& inputs) +void InitAndCheckParams(int argc, char* argv[], map& params, vector& inputs) { - const char *optstring="m::i::o::f::hd::p::l::y::e::g::"; - int c,deb,index; - struct option opts[]={{"model",required_argument,NULL,'m'}, - {"input",required_argument,NULL,'i'}, - {"output",required_argument,NULL,'o'}, - {"outfmt",required_argument,NULL,'f'}, - {"help",no_argument,NULL,1}, - {"dump",required_argument,NULL,'d'}, - {"profiler",required_argument,NULL,'p'}, - {"loop",required_argument,NULL,'l'}, - {"dymBatch",required_argument,NULL,'y'}, - {"device",required_argument,NULL,'e'}, - {"debug",required_argument,NULL,'g'}, - {0,0,0,0}}; - while((c=getopt_long(argc,argv,optstring,opts,&index))!=-1) - { - switch(c) - { + const char* optstring = "m::i::o::f::hd::p::l::y::e::g::"; + int c, deb, index; + struct option opts[] = { { "model", required_argument, NULL, 'm' }, + { "input", required_argument, NULL, 'i' }, + { "output", required_argument, NULL, 'o' }, + { "outfmt", required_argument, NULL, 'f' }, + { "help", no_argument, NULL, 1 }, + { "dump", required_argument, NULL, 'd' }, + { "profiler", required_argument, NULL, 'p' }, + { "loop", required_argument, NULL, 'l' }, + { "dymBatch", required_argument, NULL, 'y' }, + { "device", required_argument, NULL, 'e' }, + { "debug", required_argument, NULL, 'g' }, + { 0, 0, 0, 0 } }; + while ((c = getopt_long(argc, argv, optstring, opts, &index)) != -1) { + switch (c) { case 'm': - check = optarg; - if (check.find(model_Ftype) != string::npos){ -// params.push_back(optarg); + check = optarg; + if (check.find(model_Ftype) != string::npos) { params['m'] = optarg; - break; - } - else { - printf("input model file type is not .om , please check your model type!\n"); - exit(0); - } + break; + } else { + printf("input model file type is not .om , please check your model type!\n"); + exit(0); + } case 'i': - check = optarg; - if (check.find(input_Ftype) == string::npos){ - printf("input data file type is not .bin , please check your input file type!\n"); - exit(0); - } -// params.push_back(optarg); + check = optarg; + if (check.find(input_Ftype) == string::npos) { + printf("input data file type is not .bin , please check your input file type!\n"); + exit(0); + } params['i'] = optarg; Utils::SplitString(params['i'], inputs, ','); break; case 'o': -// params.push_back(optarg); params['o'] = optarg; break; case 'f': -// params.push_back(optarg); params['f'] = optarg; break; case '?': @@ -81,34 +72,29 @@ void InitAndCheckParams(int argc, char* argv[], map& params, vector Utils::printHelpLetter(); exit(0); case 'd': -// params.push_back(optarg); params['d'] = optarg; break; case 'p': -// params.push_back(optarg); params['p'] = optarg; break; case 'l': loop = Utils::str2num(optarg); - cout << "loop:" << loop << endl; - if (loop > 100 || loop < 1) - { - printf("loop must in 1 to 100\n"); - exit(0); - } + cout << "loop:" << loop << endl; + if (loop > 100 || loop < 1) { + printf("loop must in 1 to 100\n"); + exit(0); + } break; case 'y': -// params.push_back(optarg); params['y'] = optarg; 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); - } + if (device > 255 || device < 0) { + printf("device id must in 0 to 255\n"); + exit(0); + } break; case 'g': params['g'] = optarg; @@ -127,13 +113,11 @@ void InitAndCheckParams(int argc, char* argv[], map& params, vector int main(int argc, char* argv[]) { - mapparams; -// vector params; + map params; vector inputs; InitAndCheckParams(argc, argv, params, inputs); printf("******************************\n"); printf("Test Start!\n"); - if (params.empty()) { printf("Invalid params.\n"); @@ -147,20 +131,20 @@ int main(int argc, char* argv[]) } if (params['p'].compare("true") == 0) { is_profi = true; - } + } if (params['g'].compare("true") == 0) { is_debug = true; } - if (is_profi && is_dump){ + 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; - + Result ret = processSample.InitResource(); if (ret != SUCCESS) { ERROR_LOG("Sample init resource failed."); @@ -176,6 +160,6 @@ int main(int argc, char* argv[]) INFO_LOG("Execute sample success."); printf("Test Finish!\n"); printf("******************************\n"); - + return SUCCESS; } diff --git a/msame/src/model_process.cpp b/msame/src/model_process.cpp old mode 100755 new mode 100644 index cd045135071ee9a29537fad33357536e8a87b389..3661b2fc0746782681871cc669342e75201aed99 --- a/msame/src/model_process.cpp +++ b/msame/src/model_process.cpp @@ -1,5 +1,5 @@ -//Model_procccess.cpp - +// Model_procccess.cpp + /** * @file model_process.cpp * @@ -11,21 +11,30 @@ */ #include "model_process.h" #include "utils.h" -#include -#include -#include #include - +#include +#include +#include + using namespace std; extern bool g_isDevice; extern bool f_isTXT; - -ModelProcess::ModelProcess() :modelId_(0), modelMemSize_(0), modelWeightSize_(0), modelMemPtr_(nullptr), -modelWeightPtr_(nullptr), loadFlag_(false), modelDesc_(nullptr), input_(nullptr), output_(nullptr), numInputs_(0), -numOutputs_(0) + +ModelProcess::ModelProcess() + : modelId_(0) + , modelMemSize_(0) + , modelWeightSize_(0) + , modelMemPtr_(nullptr) + , modelWeightPtr_(nullptr) + , loadFlag_(false) + , modelDesc_(nullptr) + , input_(nullptr) + , output_(nullptr) + , numInputs_(0) + , numOutputs_(0) { } - + ModelProcess::~ModelProcess() { Unload(); @@ -33,44 +42,44 @@ ModelProcess::~ModelProcess() DestroyInput(); DestroyOutput(); } - -Result ModelProcess::LoadModelFromFileWithMem(const char *modelPath) + +Result ModelProcess::LoadModelFromFileWithMem(const string& modelPath) { if (loadFlag_) { ERROR_LOG("has already loaded a model"); return FAILED; } - - aclError ret = aclmdlQuerySize(modelPath, &modelMemSize_, &modelWeightSize_); + + aclError ret = aclmdlQuerySize(modelPath.c_str(), &modelMemSize_, &modelWeightSize_); 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; } - + ret = aclrtMalloc(&modelMemPtr_, modelMemSize_, ACL_MEM_MALLOC_NORMAL_ONLY); if (ret != ACL_ERROR_NONE) { ERROR_LOG("malloc buffer for mem failed, require size is %zu", modelMemSize_); return FAILED; } - + ret = aclrtMalloc(&modelWeightPtr_, modelWeightSize_, ACL_MEM_MALLOC_NORMAL_ONLY); if (ret != ACL_ERROR_NONE) { ERROR_LOG("malloc buffer for weight failed, require size is %zu", modelWeightSize_); return FAILED; } - - ret = aclmdlLoadFromFileWithMem(modelPath, &modelId_, modelMemPtr_, + + ret = aclmdlLoadFromFileWithMem(modelPath.c_str(), &modelId_, modelMemPtr_, modelMemSize_, modelWeightPtr_, modelWeightSize_); 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; - } - + } + loadFlag_ = true; - INFO_LOG("load model %s success", modelPath); + INFO_LOG("load model %s success", modelPath.c_str()); return SUCCESS; } - + Result ModelProcess::CreateDesc() { modelDesc_ = aclmdlCreateDesc(); @@ -78,20 +87,21 @@ Result ModelProcess::CreateDesc() ERROR_LOG("create model description failed"); return FAILED; } - + aclError ret = aclmdlGetDesc(modelDesc_, modelId_); if (ret != ACL_ERROR_NONE) { ERROR_LOG("get model description failed"); return FAILED; } - + INFO_LOG("create model description success"); - + return SUCCESS; } Result ModelProcess::PrintDesc() -{ aclError ret; +{ + aclError ret; DEBUG_LOG("start print model description"); size_t numInputs = aclmdlGetNumInputs(modelDesc_); size_t numOutputs = aclmdlGetNumOutputs(modelDesc_); @@ -101,30 +111,30 @@ Result ModelProcess::PrintDesc() aclmdlIODims dimsInput; aclmdlIODims dimsOutput; 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)); 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] << " "; + 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++){ + 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 <(dims); ret = aclmdlGetOutputDims(modelDesc_, i, dim); if (ret != ACL_ERROR_NONE) { ERROR_LOG("aclmdlGetOutputDims failed, ret[%d]", ret); return; } - - void *outHostData = NULL; + + void* outHostData = NULL; ret = ACL_ERROR_NONE; - void *outData = NULL; + void* outData = NULL; 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); return; } - switch (datatype) - { - case 0: - outData = reinterpret_cast(outHostData); - break; - case 1: - outData = reinterpret_cast(outHostData); - break; - case 2: - outData = reinterpret_cast(outHostData); - break; - case 3: - outData = reinterpret_cast(outHostData); - break; - case 4: - outData = reinterpret_cast(outHostData); - break; - case 6: - outData = reinterpret_cast(outHostData); - break; - case 7: - outData = reinterpret_cast(outHostData); - break; - case 8: - outData = reinterpret_cast(outHostData); - break; - case 9: - outData = reinterpret_cast(outHostData); - break; - case 10: - outData = reinterpret_cast(outHostData); - break; - case 11: - outData = reinterpret_cast(outHostData); - break; - case 12: - outData = reinterpret_cast(outHostData); - break; - default : - printf("undefined data type!\n"); - break; + switch (datatype) { + case 0: + outData = reinterpret_cast(outHostData); + break; + case 1: + outData = reinterpret_cast(outHostData); + break; + case 2: + outData = reinterpret_cast(outHostData); + break; + case 3: + outData = reinterpret_cast(outHostData); + break; + case 4: + outData = reinterpret_cast(outHostData); + break; + case 6: + outData = reinterpret_cast(outHostData); + break; + case 7: + outData = reinterpret_cast(outHostData); + break; + case 8: + outData = reinterpret_cast(outHostData); + break; + case 9: + outData = reinterpret_cast(outHostData); + break; + case 10: + outData = reinterpret_cast(outHostData); + break; + case 11: + outData = reinterpret_cast(outHostData); + break; + case 12: + outData = reinterpret_cast(outHostData); + break; + default: + printf("undefined data type!\n"); + break; } - + } else { outData = reinterpret_cast(data); } - if (f_isTXT) - { - ofstream outstr(times+"/"+modelName+"_output_"+to_string(i)+".txt", ios::out); - switch (datatype) - { - case 0: - for (int i = 0; i < len/sizeof(float); i++) - { - float out = *((float*)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; - case 1: - for (int i = 0; i < len/sizeof(aclFloat16); i++) - { - aclFloat16 out = *((aclFloat16*)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; - case 2: - for (int i = 0; i < len/sizeof(int8_t); i++) - { - int8_t out = *((int8_t*)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; - case 3: - for (int i = 0; i < len/sizeof(int); i++) - { - int out = *((int*)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; - case 4: - for (int i = 0; i < len/sizeof(uint8_t); i++) - { - uint8_t out = *((uint8_t*)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; - case 6: - for (int i = 0; i < len/sizeof(int16_t); i++) - { - int16_t out = *((int16_t*)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; - case 7: - for (int i = 0; i < len/sizeof(uint16_t); i++) - { - uint16_t out = *((uint16_t*)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; - case 8: - for (int i = 0; i < len/sizeof(uint32_t); i++) - { - uint32_t out = *((uint32_t*)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; - case 9: - for (int i = 0; i < len/sizeof(int64_t); i++) - { - int64_t out = *((int64_t*)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; - case 10: - for (int i = 0; i < len/sizeof(uint64_t); i++) - { - uint64_t out = *((uint64_t*)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; - case 11: - for (int i = 0; i < len/sizeof(double); i++) - { - double out = *((double*)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; - case 12: - 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; + if (f_isTXT) { + ofstream outstr(times + "/" + modelName + "_output_" + to_string(i) + ".txt", ios::out); + switch (datatype) { + case 0: + for (int i = 0; i < len / sizeof(float); i++) { + float out = *((float*)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; + case 1: + for (int i = 0; i < len / sizeof(aclFloat16); i++) { + aclFloat16 out = *((aclFloat16*)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; + case 2: + for (int i = 0; i < len / sizeof(int8_t); i++) { + int8_t out = *((int8_t*)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; + case 3: + for (int i = 0; i < len / sizeof(int); i++) { + int out = *((int*)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; + case 4: + for (int i = 0; i < len / sizeof(uint8_t); i++) { + uint8_t out = *((uint8_t*)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; + case 6: + for (int i = 0; i < len / sizeof(int16_t); i++) { + int16_t out = *((int16_t*)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; + case 7: + for (int i = 0; i < len / sizeof(uint16_t); i++) { + uint16_t out = *((uint16_t*)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; + case 8: + for (int i = 0; i < len / sizeof(uint32_t); i++) { + uint32_t out = *((uint32_t*)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; + case 9: + for (int i = 0; i < len / sizeof(int64_t); i++) { + int64_t out = *((int64_t*)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; + case 10: + for (int i = 0; i < len / sizeof(uint64_t); i++) { + uint64_t out = *((uint64_t*)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; + case 11: + for (int i = 0; i < len / sizeof(double); i++) { + double out = *((double*)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; + case 12: + 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(); - } - else - { - ofstream outstr(times+"/"+modelName+"_output_"+to_string(i)+".bin", ios::out|ios::binary); - - outstr.write((char*)outData, len); + } else { + ofstream outstr(times + "/" + modelName + "_output_" + to_string(i) + ".bin", ios::out | ios::binary); + + outstr.write((char*)outData, len); outstr.close(); } - if (!g_isDevice) { ret = aclrtFreeHost(outHostData); @@ -654,28 +588,28 @@ void ModelProcess::OutputModelResult(std::string& s,std::string& modelName,size_ } } } - + INFO_LOG("output data success"); return; } - + void ModelProcess::DestroyOutput() { if (output_ == nullptr) { return; - } - + } + for (size_t i = 0; i < aclmdlGetDatasetNumBuffers(output_); ++i) { aclDataBuffer* dataBuffer = aclmdlGetDatasetBuffer(output_, i); void* data = aclGetDataBufferAddr(dataBuffer); (void)aclrtFree(data); (void)aclDestroyDataBuffer(dataBuffer); } - + (void)aclmdlDestroyDataset(output_); output_ = nullptr; } - + Result ModelProcess::Execute() { aclError ret = aclmdlExecute(modelId_, input_, output_); @@ -683,18 +617,18 @@ Result ModelProcess::Execute() ERROR_LOG("execute model failed, modelId is %u", modelId_); return FAILED; } - + INFO_LOG("model execute success"); return SUCCESS; } - + void ModelProcess::Unload() { if (!loadFlag_) { WARN_LOG("no model had been loaded, unload failed"); return; } - + aclError ret = aclmdlUnload(modelId_); if (ret != ACL_ERROR_NONE) { ERROR_LOG("unload model failed, modelId is %u", modelId_); @@ -703,18 +637,18 @@ void ModelProcess::Unload() (void)aclmdlDestroyDesc(modelDesc_); modelDesc_ = nullptr; } - + if (modelMemPtr_ != nullptr) { aclrtFree(modelMemPtr_); modelMemPtr_ = nullptr; modelMemSize_ = 0; - } - if (modelWeightPtr_ != nullptr) { - aclrtFree(modelWeightPtr_); - modelWeightPtr_ = nullptr; - modelWeightSize_ = 0; - } - - loadFlag_ = false; - INFO_LOG("unload model success, model Id is %u", modelId_); + } + if (modelWeightPtr_ != nullptr) { + aclrtFree(modelWeightPtr_); + modelWeightPtr_ = nullptr; + modelWeightSize_ = 0; + } + + loadFlag_ = false; + INFO_LOG("unload model success, model Id is %u", modelId_); } diff --git a/msame/src/sample_process.cpp b/msame/src/sample_process.cpp old mode 100755 new mode 100644 index 811301158876411d62a37aad874dfeba7054a753..3207d6d3adc390f91085b3ffc9a1205ecb3ab8f6 --- a/msame/src/sample_process.cpp +++ b/msame/src/sample_process.cpp @@ -1,5 +1,5 @@ //Sample_process.cpp - + /** * @file sample_process.cpp * @@ -10,8 +10,8 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. */ #include "sample_process.h" -#include "model_process.h" #include "acl/acl.h" +#include "model_process.h" #include "utils.h" using namespace std; extern bool g_isDevice; @@ -22,42 +22,34 @@ 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) { } - + SampleProcess::~SampleProcess() { DestroyResource(); } - + Result SampleProcess::InitResource() { // ACL init aclError ret; - const char *aclConfigPath = "acl.json"; - if (is_profi == true){ + const char* aclConfigPath = "acl.json"; + if (is_profi == true) { ret = aclInit(aclConfigPath); - } else - { + } else { ret = aclInit(nullptr); } 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"); return FAILED; - } + } INFO_LOG("acl init success"); - + // open device deviceId_ = device; ret = aclrtSetDevice(deviceId_); @@ -66,7 +58,7 @@ Result SampleProcess::InitResource() return FAILED; } INFO_LOG("open device %d success", deviceId_); - + // create context (set current) ret = aclrtCreateContext(&context_, deviceId_); if (ret != ACL_ERROR_NONE) { @@ -74,7 +66,7 @@ Result SampleProcess::InitResource() return FAILED; } INFO_LOG("create context success"); - + // create stream ret = aclrtCreateStream(&stream_); if (ret != ACL_ERROR_NONE) { @@ -82,7 +74,7 @@ Result SampleProcess::InitResource() return FAILED; } INFO_LOG("create stream success"); - + // get run mode aclrtRunMode runMode; ret = aclrtGetRunMode(&runMode); @@ -93,32 +85,22 @@ Result SampleProcess::InitResource() g_isDevice = (runMode == ACL_DEVICE); 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; } - -Result SampleProcess::Process(map& params, vector& input_files) + +Result SampleProcess::Process(map& params, vector& input_files) { // model init ModelProcess processModel; - const char* omModelPath = params['m'].c_str(); + const std::string& omModelPath = params['m']; std::string output_path = params['o'].c_str(); const char* outfmt = params['f'].c_str(); 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 modelName = Utils::modelName(modelPath); - + struct timeval begin; struct timeval end; double inference_time[loop]; @@ -127,24 +109,14 @@ Result SampleProcess::Process(map& params, vector& input_fi ERROR_LOG("load model from file failed"); return FAILED; } - + ret = processModel.CreateDesc(); if (ret != SUCCESS) { ERROR_LOG("create model description 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){ + + if (is_debug) { ret = processModel.PrintDesc(); if (ret != SUCCESS) { ERROR_LOG("print model descrtption failed"); @@ -156,16 +128,15 @@ Result SampleProcess::Process(map& params, vector& input_fi ERROR_LOG("create model output 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); + } else { + vector picDevBuffer(input_files.size(), nullptr); for (size_t index = 0; index < input_files.size(); ++index) { INFO_LOG("start to process file:%s", input_files[index].c_str()); // model process @@ -193,9 +164,6 @@ Result SampleProcess::Process(map& params, vector& input_fi std::cout << "Inference time: " << inference_time[t] << "ms" << endl; if (ret != SUCCESS) { ERROR_LOG("model execute failed"); -// for (size_t i = 0; i < input_files.size(); i++) { -// aclrtFree(picDevBuffer[i]); -// } return FAILED; } processModel.OutputModelResult(output_path, modelName, t); @@ -208,23 +176,17 @@ Result SampleProcess::Process(map& params, vector& input_fi } processModel.DestroyInput(); - if (is_dump || is_profi){ - if (remove("acl.json")==0){ + if (is_dump || is_profi) { + if (remove("acl.json") == 0) { INFO_LOG("delete acl.json success"); - } - else{ + } 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; } - + void SampleProcess::DestroyResource() { aclError ret; @@ -236,7 +198,7 @@ void SampleProcess::DestroyResource() stream_ = nullptr; } INFO_LOG("end to destroy stream"); - + if (context_ != nullptr) { ret = aclrtDestroyContext(context_); if (ret != ACL_ERROR_NONE) { @@ -245,25 +207,16 @@ void SampleProcess::DestroyResource() context_ = nullptr; } INFO_LOG("end to destroy context"); - + ret = aclrtResetDevice(deviceId_); if (ret != ACL_ERROR_NONE) { ERROR_LOG("reset device failed"); } 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(); if (ret != ACL_ERROR_NONE) { ERROR_LOG("finalize acl failed"); } INFO_LOG("end to finalize acl"); - } diff --git a/msame/src/utils.cpp b/msame/src/utils.cpp old mode 100755 new mode 100644 index 51e8b6e63c1cf9db05e348424f35877c726816de..20a53b40e5d84146716116e2c7ab2af339980062 --- a/msame/src/utils.cpp +++ b/msame/src/utils.cpp @@ -1,5 +1,5 @@ //Util.cpp - + /** * @file utils.cpp * @@ -10,8 +10,8 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. */ #include "utils.h" -#include #include "acl/acl.h" +#include using namespace std; extern bool g_isDevice; extern bool f_isTXT; @@ -19,14 +19,14 @@ 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) { std::ifstream binFile(fileName, std::ifstream::binary); if (binFile.is_open() == false) { ERROR_LOG("open file %s failed", fileName.c_str()); return nullptr; } - + binFile.seekg(0, binFile.end); uint32_t binFileBufferLen = binFile.tellg(); if (binFileBufferLen == 0) { @@ -34,9 +34,9 @@ void* Utils::ReadBinFile(std::string fileName, uint32_t &fileSize) binFile.close(); return nullptr; } - + binFile.seekg(0, binFile.beg); - + void* binFileBufferData = nullptr; aclError ret = ACL_ERROR_NONE; if (!g_isDevice) { @@ -54,14 +54,14 @@ void* Utils::ReadBinFile(std::string fileName, uint32_t &fileSize) return nullptr; } } - - binFile.read(static_cast(binFileBufferData), binFileBufferLen); + + binFile.read(static_cast(binFileBufferData), binFileBufferLen); binFile.close(); fileSize = binFileBufferLen; return binFileBufferData; } - -void* Utils::GetDeviceBufferOfFile(std::string fileName, uint32_t &fileSize) + +void* Utils::GetDeviceBufferOfFile(std::string fileName, uint32_t& fileSize) { uint32_t inputHostBuffSize = 0; void* inputHostBuff = Utils::ReadBinFile(fileName, inputHostBuffSize); @@ -69,7 +69,7 @@ void* Utils::GetDeviceBufferOfFile(std::string fileName, uint32_t &fileSize) return nullptr; } if (!g_isDevice) { - void *inBufferDev = nullptr; + void* inBufferDev = nullptr; uint32_t inBufferSize = inputHostBuffSize; aclError ret = aclrtMalloc(&inBufferDev, inBufferSize, ACL_MEM_MALLOC_NORMAL_ONLY); if (ret != ACL_ERROR_NONE) { @@ -77,7 +77,7 @@ void* Utils::GetDeviceBufferOfFile(std::string fileName, uint32_t &fileSize) aclrtFreeHost(inputHostBuff); return nullptr; } - + ret = aclrtMemcpy(inBufferDev, inBufferSize, inputHostBuff, inputHostBuffSize, ACL_MEMCPY_HOST_TO_DEVICE); if (ret != ACL_ERROR_NONE) { ERROR_LOG("memcpy failed. device buffer size is %u, input host buffer size is %u", @@ -94,15 +94,14 @@ void* Utils::GetDeviceBufferOfFile(std::string fileName, uint32_t &fileSize) return inputHostBuff; } } - + void Utils::SplitString(std::string& s, std::vector& v, char c) { std::string::size_type pos1, pos2; pos2 = s.find(c); pos1 = 0; - while(std::string::npos != pos2) - { - std::string s1 = s.substr(pos1, pos2-pos1); + while (std::string::npos != pos2) { + 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); @@ -115,8 +114,7 @@ void Utils::SplitString(std::string& s, std::vector& v, char c) pos1 = pos2 + 1; pos2 = s.find(c, pos1); } - if(pos1 != s.length()) - { + if (pos1 != s.length()) { std::string s1 = s.substr(pos1); size_t n = s1.find_last_not_of(" \r\n\t"); if (n != string::npos) { @@ -129,18 +127,16 @@ void Utils::SplitString(std::string& s, std::vector& v, char c) v.push_back(s1); } } - -int Utils::str2num(char *str) + +int Utils::str2num(char* str) { int n = 0; int flag = 0; - while(*str >= '0' && *str <= '9') - { - n = n*10 + (*str - '0'); + while (*str >= '0' && *str <= '9') { + n = n * 10 + (*str - '0'); str++; } - if(flag == 1) - { + if (flag == 1) { n = -n; } return n; @@ -148,71 +144,67 @@ int Utils::str2num(char *str) std::string Utils::modelName(string& s) { - string::size_type position1,position2; - position1 = s.find_last_of("/"); - if (position1 == s.npos) - { - position1 = 0; - } - position2 = s.find_last_of("."); - std::string modelName = s.substr(position1,position2-position1); - return modelName; + string::size_type position1, position2; + position1 = s.find_last_of("/"); + if (position1 == s.npos) { + position1 = 0; + } + position2 = s.find_last_of("."); + std::string modelName = s.substr(position1, position2 - position1); + return modelName; } -std::string Utils::TimeLine() +std::string Utils::TimeLine() { - time_t currentTime = time(NULL); - char chCurrentTime[64]; - strftime(chCurrentTime, sizeof(chCurrentTime), "%Y%m%d_%H%M%S", localtime(¤tTime)); - std::string stCurrentTime = chCurrentTime; - return stCurrentTime; + time_t currentTime = time(NULL); + char chCurrentTime[64]; + strftime(chCurrentTime, sizeof(chCurrentTime), "%Y%m%d_%H%M%S", localtime(¤tTime)); + std::string stCurrentTime = chCurrentTime; + return stCurrentTime; } void Utils::printCurrentTime() { - char szBuf[256] = {0}; - struct timeval tv; - struct timezone tz; - struct tm *p; + char szBuf[256] = { 0 }; + struct timeval tv; + struct timezone tz; + struct tm* p = nullptr; gettimeofday(&tv, &tz); 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); - } void Utils::printHelpLetter() { - cout<< endl; - cout<< "Usage:" << 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 << endl; + cout << "Usage:" << 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<< "arguments explain:" << 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<< " --output Output path(User needs to have permission to create directories)" << endl; - cout<< " --outfmt Output file format (TXT or BIN)" << endl; - cout<< " --loop loop time(must in 1 to 100)" << endl; - cout<< " --dump Enable dump (true or false)(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<< "NOTECE: " << endl; -// cout<< " The order of parameter must follow in --model --input --output --outfmt --loop " << endl; + cout << "arguments explain:" << 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 << " --output Output path(User needs to have permission to create directories)" << endl; + cout << " --outfmt Output file format (TXT or BIN)" << endl; + cout << " --loop loop time(must in 1 to 100)" << endl; + cout << " --dump Enable dump (true or false)(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; } - double Utils::printDiffTime(time_t begin, time_t 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; } -double Utils::InferenceTimeAverage(double *x, int len) +double Utils::InferenceTimeAverage(double* x, int len) { double sum = 0; for (int i = 0; i < len; i++) @@ -220,54 +212,43 @@ double Utils::InferenceTimeAverage(double *x, int len) return sum / len; } -double Utils::InferenceTimeAverageWithoutFirst(double *x, int len) +double Utils::InferenceTimeAverageWithoutFirst(double* x, int len) { double sum = 0; for (int i = 0; i < len; i++) - if (i !=0){ - sum += x[i]; - } - + if (i != 0) { + sum += x[i]; + } + return sum / (len - 1); } -void Utils::ProfilerJson(bool isprof, map& params) +void Utils::ProfilerJson(bool isprof, map& params) { - if (isprof){ + 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); + 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); + 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& params) +void Utils::DumpJson(bool isdump, map& params) { - if (is_dump){ + if (is_dump) { std::string modelPath = params['m'].c_str(); std::string modelName = Utils::modelName(modelPath); std::string out_path = params['o'].c_str(); @@ -279,24 +260,15 @@ void Utils::DumpJson(bool isdump, map& params) 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); + 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); + if (NULL == opendir(temp_s1)) { + mkdir(temp_s1, 0775); } - // { - // "dump": { - // "dump_path": "output_path", - // "dump_mode": "output", - // "dump_list": [{ - // "model_name": "model_name", - // }] - // } - // } } }