update amexec
This commit is contained in:
Binary file not shown.
@@ -39,7 +39,7 @@ public:
|
||||
* @brief sample process
|
||||
* @return result
|
||||
*/
|
||||
Result Process(vector<string>& params, vector<string>& inputs, size_t idx);
|
||||
Result Process(vector<string>& params, vector<string>& inputs);
|
||||
|
||||
private:
|
||||
void DestroyResource();
|
||||
|
||||
+5
-1
@@ -20,13 +20,14 @@
|
||||
#include <algorithm>
|
||||
#include <stdio.h>
|
||||
#include <time.h>
|
||||
#include <sys/time.h>
|
||||
|
||||
#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
|
||||
|
||||
Binary file not shown.
+62
-16
@@ -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功能暂不支持。
|
||||
## 参数说明
|
||||
|
||||
| 参数名 | 说明 |
|
||||
| -------- | ------------------------------- |
|
||||
| --model | 需要进行推理的om模型 |
|
||||
| --input | 模型需要的输入 |
|
||||
| --output | 推理数据输出路径 |
|
||||
| --outfmt | 输出数据的格式,TXT或者BIN |
|
||||
| --loop | 推理次数 [1,100],可选参数默认1 |
|
||||
| --help | 工具使用帮助信 |
|
||||
+8
-7
@@ -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<string>& params, vector<s
|
||||
break;
|
||||
case 'l':
|
||||
loop = Utils::str2num(optarg);
|
||||
cout << "loop:" << loop << endl;
|
||||
if (loop > 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");
|
||||
|
||||
@@ -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_);
|
||||
}
|
||||
|
||||
@@ -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<string>& params, vector<string>& input_files, size_t idx)
|
||||
Result SampleProcess::Process(vector<string>& params, vector<string>& input_files)
|
||||
{
|
||||
// model init
|
||||
ModelProcess processModel;
|
||||
@@ -86,9 +87,12 @@ Result SampleProcess::Process(vector<string>& params, vector<string>& 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<string>& params, vector<string>& 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: "<<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);
|
||||
}
|
||||
double infer_time_ave = Utils::InferenceTimeAverage(inference_time, loop);
|
||||
printf("Inference average time: %f ms\n", infer_time_ave);
|
||||
|
||||
processModel.DestroyInput();
|
||||
}
|
||||
|
||||
// release model input buffer
|
||||
for (size_t i = 0; i < input_files.size(); i++) {
|
||||
aclrtFree(picDevBuffer[i]);
|
||||
|
||||
@@ -175,3 +175,18 @@ void Utils::printHelpLetter()
|
||||
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 diffT = difftime(begin, end);
|
||||
printf("The inference time is: %f millisecond\n", 1000*diffT);
|
||||
return diffT*1000;
|
||||
}
|
||||
|
||||
double Utils::InferenceTimeAverage(double *x, int len)
|
||||
{
|
||||
double sum = 0;
|
||||
for (int i = 0; i < len; i++)
|
||||
sum += x[i];
|
||||
return sum/len;
|
||||
}
|
||||
|
||||
Binary file not shown.
Reference in New Issue
Block a user