diff --git a/AMEXEC/amexec测试用例.xlsx b/AMEXEC/amexec测试用例.xlsx deleted file mode 100755 index 9d8c90e..0000000 Binary files a/AMEXEC/amexec测试用例.xlsx and /dev/null differ diff --git a/AMEXEC/inc/sample_process.h b/AMEXEC/inc/sample_process.h index ee988ff..afc7f06 100755 --- a/AMEXEC/inc/sample_process.h +++ b/AMEXEC/inc/sample_process.h @@ -39,7 +39,7 @@ public: * @brief sample process * @return result */ - Result Process(vector& params, vector& inputs, size_t idx); + Result Process(vector& params, vector& inputs); private: void DestroyResource(); diff --git a/AMEXEC/inc/utils.h b/AMEXEC/inc/utils.h index ead38c0..f5d8d2c 100755 --- a/AMEXEC/inc/utils.h +++ b/AMEXEC/inc/utils.h @@ -20,13 +20,14 @@ #include #include #include +#include #define INFO_LOG(fmt, args...) fprintf(stdout, "[INFO] " 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; +//static size_t loop = 1; typedef enum Result { SUCCESS = 0, FAILED = 1 @@ -65,7 +66,10 @@ public: static void printCurrentTime(); static void printHelpLetter(); + + static double printDiffTime(time_t begin, time_t end); + static double InferenceTimeAverage(double *x, int len); }; #pragma once diff --git a/AMEXEC/out/amexec b/AMEXEC/out/amexec index 9e91619..2f4ccb0 100755 Binary files a/AMEXEC/out/amexec and b/AMEXEC/out/amexec differ diff --git a/AMEXEC/readMe.md b/AMEXEC/readMe.md index b795d3e..9075c3a 100755 --- a/AMEXEC/readMe.md +++ b/AMEXEC/readMe.md @@ -1,25 +1,71 @@ -**此工具为模型推理工具** +# amexec工具为模型推理工具 + +### 功能 +输入.om模型和模型所需要的输入bin文件,输出模型的输出数据文件,支持多次推理(指对同一输入数据进行推理)。 + +模型必须是通过c7x版本的atc工具转换的om模型,输入bin文件需要符合模型的输入要求(支持模型多输入) + +### 使用环境 +Centos7.6或Ubuntu16.4 +必须按照《驱动和开发环境安装指南》装好C7x环境 + +### 获取 +1. 下载压缩包方式获取。 + + 将 https://gitee.com/atlasdevelop/c7x_samples 仓中的脚本下载至服务器的任意目录。 + + 例如存放路径为:$HOME/AscendProjects/amexec。 + +2. 命令行使用git命令方式获取。 + + 在命令行中:$HOME/AscendProjects目录下执行以下命令下载代码。 + + **git clone https://gitee.com/atlasdevelop/c7x_samples.git** - - - -功能:输入.om模型和模型所需要的输入bin文件,输出模型的输出数据文件 - - - -模型必须是通过c7x版本的atc工具转换的om模型,输入bin文件需要符合模型的输入要求 - +### 使用方法 +进入AMEXEC目录 +``` +cd $HOME/AscendProjects/c7x_samples/amexec/ +``` +进入out目录 +``` +cd $HOME/AscendProjects/c7x_samples/amexec/out +``` +工具就在out目录下 工具为命令行的运行方式,例如 +``` +./amexec --model /home/HwHiAiUser/ljj/colorization.om --input /home/HwHiAiUser/ljj/colorization_input.bin --output /home/HwHiAiUser/ljj/AMEXEC/out/output1 --outfmt TXT --loop 2 +``` +需要注意的是这几个参数的顺序不能颠倒,outfmt与loop为可选参数,默认值分别有BIN、1。 +如果有多个输入,需要用“,”隔开。 +其他参数详情可使用--help查询。 -*./amexec --model /home/HwHiAiUser/ljj/colorization.om --input /home/HwHiAiUser/ljj/colorization_input.bin --output /home/HwHiAiUser/ljj/AMEXEC/out/output1 --outfmt TXT --loop 2* - -需要注意的是这几个参数的顺序不能颠倒,outfmt与loop为可选参数,默认值分别有BIN、1。其他参数详情可使用--help查询。 - - +### 编译 +工具也支持源码编译,或者使用者需要添加或者修改代码,使用者重新编译 +进入AMEXEC目录 +``` +cd $HOME/AscendProjects/c7x_samples/amexec/ +``` +运行编译脚本 +``` +./build.sh +``` +重新编译的工具在out目录下 +## 注意事项 运行工具的用户在当前目录需要有创建目录以及执行工具的权限,使用前请自行检查。 +dump、profiling以及动态多batch功能暂不支持。 -dump、profiling以及动态多batch功能暂不支持。 \ No newline at end of file +## 参数说明 + +| 参数名 | 说明 | +| -------- | ------------------------------- | +| --model | 需要进行推理的om模型 | +| --input | 模型需要的输入 | +| --output | 推理数据输出路径 | +| --outfmt | 输出数据的格式,TXT或者BIN | +| --loop | 推理次数 [1,100],可选参数默认1 | +| --help | 工具使用帮助信 | \ No newline at end of file diff --git a/AMEXEC/src/main.cpp b/AMEXEC/src/main.cpp index f88d44a..8a54658 100755 --- a/AMEXEC/src/main.cpp +++ b/AMEXEC/src/main.cpp @@ -16,6 +16,7 @@ using namespace std; bool f_isTXT = false; bool g_isDevice = false; +int loop = 1; string input_Ftype = ".bin"; string model_Ftype = ".om"; string check = ""; @@ -78,6 +79,7 @@ void InitAndCheckParams(int argc, char* argv[], vector& params, vector 100 || loop < 1) { printf("loop must in 1 to 100\n"); @@ -120,14 +122,13 @@ int main(int argc, char* argv[]) ERROR_LOG("Sample init resource failed."); return FAILED; } - for (size_t i = 0;i < loop;i++){ - std::cout << i << endl; - ret = processSample.Process(params, inputs, i); - if (ret != SUCCESS) { - ERROR_LOG("Sample process failed."); - return FAILED; - } + + ret = processSample.Process(params, inputs); + if (ret != SUCCESS) { + ERROR_LOG("Sample process failed."); + return FAILED; } + INFO_LOG("Execute sample success."); printf("Test Finish!\n"); printf("******************************\n"); diff --git a/AMEXEC/src/model_process.cpp b/AMEXEC/src/model_process.cpp index 0965309..4f01763 100755 --- a/AMEXEC/src/model_process.cpp +++ b/AMEXEC/src/model_process.cpp @@ -567,5 +567,5 @@ void ModelProcess::Unload() } loadFlag_ = false; - INFO_LOG("unload model syccess, model Id is %u", modelId_); + INFO_LOG("unload model success, model Id is %u", modelId_); } diff --git a/AMEXEC/src/sample_process.cpp b/AMEXEC/src/sample_process.cpp index 60c2908..cbdc214 100755 --- a/AMEXEC/src/sample_process.cpp +++ b/AMEXEC/src/sample_process.cpp @@ -16,6 +16,7 @@ using namespace std; extern bool g_isDevice; extern bool f_isTXT; +extern int loop; SampleProcess::SampleProcess() :deviceId_(0), context_(nullptr), stream_(nullptr) { @@ -73,7 +74,7 @@ Result SampleProcess::InitResource() return SUCCESS; } -Result SampleProcess::Process(vector& params, vector& input_files, size_t idx) +Result SampleProcess::Process(vector& params, vector& input_files) { // model init ModelProcess processModel; @@ -86,9 +87,12 @@ Result SampleProcess::Process(vector& params, vector& input_file const char* profConf = params[5].c_str(); const char* dymBatch = params[6].c_str(); - std::string modelPath = params[0].c_str(); - std::string modelName = Utils::modelName(modelPath); + std::string modelPath = params[0].c_str(); + std::string modelName = Utils::modelName(modelPath); + struct timeval begin; + struct timeval end; + double inference_time[loop]; Result ret = processModel.LoadModelFromFileWithMem(omModelPath); if (ret != SUCCESS) { ERROR_LOG("load model from file failed"); @@ -122,33 +126,34 @@ Result SampleProcess::Process(vector& params, vector& input_file 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]); } return FAILED; } - - // loop end - - printf("Inference begin time: "); - Utils::printCurrentTime(); - ret = processModel.Execute(); - printf("Inference end time: "); - Utils::printCurrentTime(); - if (ret != SUCCESS) { - ERROR_LOG("model execute failed"); - for (size_t i = 0; i < index; i++) { - aclrtFree(picDevBuffer[i]); - } - return FAILED; } - - // print the top 5 confidence values with indexes.use function DumpModelOutputResult - // if want to dump output result to file in the current directory - //processModel.DumpModelOutputResult(); - processModel.OutputModelResult(output_path,modelName,idx); + // loop end + for (size_t t = 0; t < loop; ++t){ + gettimeofday(&begin,NULL); + ret = processModel.Execute(); + gettimeofday(&end,NULL); + inference_time[t] = 1000*(end.tv_sec - begin.tv_sec) + (end.tv_usec - begin.tv_usec)/1000.000; + //std::cout << "usec: " << end.tv_usec - begin.tv_usec << endl; + std::cout << "Inference time: "<