clean code

This commit is contained in:
liuchengju
2020-09-01 11:51:28 +08:00
parent bea100c789
commit 7d654d22cb
44 changed files with 4486 additions and 724 deletions
Executable → Regular
+80 -82
View File
@@ -1,119 +1,117 @@
//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"
/**
* ModelProcess
*/
* ModelProcess
*/
class ModelProcess {
public:
/**
* @brief Constructor
*/
* @brief Constructor
*/
ModelProcess();
/**
* @brief Destructor
*/
* @brief Destructor
*/
~ModelProcess();
/**
* @brief load model from file with mem
* @param [in] modelPath: model path
* @return result
*/
Result LoadModelFromFileWithMem(const char *modelPath);
* @brief load model from file with mem
* @param [in] modelPath: model path
* @return result
*/
Result LoadModelFromFileWithMem(const string& modelPath);
/**
* @brief unload model
*/
* @brief unload model
*/
void Unload();
/**
* @brief create model desc
* @return result
*/
* @brief create model desc
* @return result
*/
Result CreateDesc();
/**
* @brief PrintDesc
*/
* @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);
/**
* @brief create model input
* @return result
*/
/**
* @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);
/**
* @brief create model input
* @return result
*/
Result CreateZeroInput();
/**
* @brief destroy input resource
*/
* @brief destroy input resource
*/
void DestroyInput();
/**
* @brief create output buffer
* @return result
*/
* @brief create output buffer
* @return result
*/
Result CreateOutput();
/**
* @brief destroy output resource
*/
* @brief destroy output resource
*/
void DestroyOutput();
/**
* @brief model execute
* @return result
*/
* @brief model execute
* @return result
*/
Result Execute();
/**
* @brief dump model output result to file
*/
* @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);
* @brief get model output result
*/
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_;
};
};
#endif
Executable → Regular
+11 -12
View File
@@ -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 <stdio.h>
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<char,string>& params, vector<string>& inputs);
Result Process(std::map<char, std::string>& params, std::vector<std::string>& inputs);
private:
void DestroyResource();
int32_t deviceId_;
aclrtContext context_;
aclrtStream stream_;
};
#endif
Executable → Regular
+38 -41
View File
@@ -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 <iostream>
#include <sstream>
#include <fstream>
#include <cstring>
#include <string>
#include <map>
#include <vector>
#ifndef _UTILS_H_
#define _UTILS_H_
#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 <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 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<std::string>& 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<char,string>& params);
static double InferenceTimeAverage(double* x, int len);
static void DumpJson(bool isdump, map<char,string>& params);
static double InferenceTimeAverageWithoutFirst(double* x, int len);
static void ProfilerJson(bool isprof, std::map<char, std::string>& params);
static void DumpJson(bool isdump, std::map<char, std::string>& params);
};
#pragma once
#endif