提交 1b871466 编写于 作者: 吴承辉

Merge branch 'master' into 'master'

Refactor hexagon engine since several changes break it.

See merge request !205
...@@ -513,14 +513,22 @@ const OperatorDef &NetDef::op(const int idx) const { ...@@ -513,14 +513,22 @@ const OperatorDef &NetDef::op(const int idx) const {
MaceEngine::MaceEngine(const NetDef *net_def, DeviceType device_type) : MaceEngine::MaceEngine(const NetDef *net_def, DeviceType device_type) :
op_registry_(new OperatorRegistry()), device_type_(device_type), op_registry_(new OperatorRegistry()), device_type_(device_type),
ws_(new Workspace()), net_(nullptr), hexagon_controller_(nullptr) { ws_(new Workspace()), net_(nullptr), hexagon_controller_(nullptr) {
ws_->CreateTensor("mace_input_node:0",
GetDeviceAllocator(device_type_),
DT_FLOAT);
ws_->CreateTensor("mace_output_node:0",
GetDeviceAllocator(device_type_),
DT_FLOAT);
if (device_type == HEXAGON) { if (device_type == HEXAGON) {
hexagon_controller_.reset(new HexagonControlWrapper()); hexagon_controller_.reset(new HexagonControlWrapper());
hexagon_controller_->Init(); hexagon_controller_->Init();
hexagon_controller_->SetDebugLevel(0); hexagon_controller_->SetDebugLevel(
static_cast<int>(mace::internal::LogMessage::MinVLogLevel()));
hexagon_controller_->Config(); hexagon_controller_->Config();
hexagon_controller_->SetupGraph(*net_def); hexagon_controller_->SetupGraph(*net_def);
hexagon_controller_->PrintGraph(); if (VLOG_IS_ON(2)) {
hexagon_controller_->PrintGraph();
}
} else { } else {
ws_->LoadModelTensor(*net_def, device_type); ws_->LoadModelTensor(*net_def, device_type);
...@@ -531,19 +539,15 @@ MaceEngine::MaceEngine(const NetDef *net_def, DeviceType device_type) : ...@@ -531,19 +539,15 @@ MaceEngine::MaceEngine(const NetDef *net_def, DeviceType device_type) :
LOG(FATAL) << "Net init run failed"; LOG(FATAL) << "Net init run failed";
} }
ws_->RemoveUnsedTensor(); ws_->RemoveUnsedTensor();
ws_->CreateTensor("mace_input_node:0",
GetDeviceAllocator(device_type_),
DT_FLOAT);
ws_->CreateTensor("mace_output_node:0",
GetDeviceAllocator(device_type_),
DT_FLOAT);
net_ = std::move(CreateNet(op_registry_, *net_def, ws_.get(), device_type)); net_ = std::move(CreateNet(op_registry_, *net_def, ws_.get(), device_type));
} }
} }
MaceEngine::~MaceEngine() { MaceEngine::~MaceEngine() {
if (device_type_ == HEXAGON) { if (device_type_ == HEXAGON) {
hexagon_controller_->GetPerfInfo(); if (VLOG_IS_ON(2)) {
hexagon_controller_->PrintLog(); hexagon_controller_->GetPerfInfo();
hexagon_controller_->PrintLog();
}
hexagon_controller_->TeardownGraph(); hexagon_controller_->TeardownGraph();
hexagon_controller_->Finalize(); hexagon_controller_->Finalize();
} }
......
...@@ -184,7 +184,7 @@ void HexagonControlWrapper::SetDebugLevel(int level) { ...@@ -184,7 +184,7 @@ void HexagonControlWrapper::SetDebugLevel(int level) {
void HexagonControlWrapper::GetPerfInfo() { void HexagonControlWrapper::GetPerfInfo() {
LOG(INFO) << "Get perf info"; LOG(INFO) << "Get perf info";
vector<hexagon_nn_perfinfo> perf_info(MAX_NODE); vector<hexagon_nn_perfinfo> perf_info(MAX_NODE);
unsigned int n_items; unsigned int n_items = 0;
hexagon_nn_get_perfinfo(nn_id_, perf_info.data(), MAX_NODE, &n_items); hexagon_nn_get_perfinfo(nn_id_, perf_info.data(), MAX_NODE, &n_items);
std::unordered_map<uint32_t, float> node_id_counters; std::unordered_map<uint32_t, float> node_id_counters;
......
...@@ -124,7 +124,7 @@ int main(int argc, char **argv) { ...@@ -124,7 +124,7 @@ int main(int argc, char **argv) {
Flag("output_shape", &output_shape, "output shape, separated by comma"), Flag("output_shape", &output_shape, "output shape, separated by comma"),
Flag("input_file", &input_file, "input file name"), Flag("input_file", &input_file, "input file name"),
Flag("output_file", &output_file, "output file name"), Flag("output_file", &output_file, "output file name"),
Flag("device", &device, "CPU/NEON"), Flag("device", &device, "CPU/NEON/OPENCL/HEXAGON"),
Flag("round", &round, "round"), Flag("round", &round, "round"),
Flag("malloc_check_cycle", &malloc_check_cycle, Flag("malloc_check_cycle", &malloc_check_cycle,
"malloc debug check cycle, -1 to disable"), "malloc debug check cycle, -1 to disable"),
...@@ -175,7 +175,7 @@ int main(int argc, char **argv) { ...@@ -175,7 +175,7 @@ int main(int argc, char **argv) {
input_size * sizeof(float)); input_size * sizeof(float));
in_file.close(); in_file.close();
} else { } else {
LOG(ERROR) << "Open input file failed"; LOG(FATAL) << "Open input file failed";
} }
// Init model // Init model
......
...@@ -36,13 +36,17 @@ build_and_run() ...@@ -36,13 +36,17 @@ build_and_run()
--cpu=armeabi-v7a \ --cpu=armeabi-v7a \
--copt="-std=c++11" \ --copt="-std=c++11" \
--copt="-D_GLIBCXX_USE_C99_MATH_TR1" \ --copt="-D_GLIBCXX_USE_C99_MATH_TR1" \
--copt="-Werror=return-type" --copt="-Werror=return-type" \
--copt="-DMACE_MODEL_TAG=${MODEL_TAG}" \
--define hexagon=true --define production=true || exit -1
adb shell "mkdir -p ${PHONE_DATA_DIR}" adb shell "mkdir -p ${PHONE_DATA_DIR}" || exit -1
adb push ${MODEL_DIR}/${INPUT_FILE_NAME} ${PHONE_DATA_DIR} adb push ${MODEL_DIR}/${INPUT_FILE_NAME} ${PHONE_DATA_DIR} || exit -1
adb push bazel-bin/mace/examples/mace_run ${PHONE_DATA_DIR} adb push bazel-bin/mace/examples/mace_run ${PHONE_DATA_DIR} || exit -1
adb push mace/core/runtime/hexagon/libhexagon_controller.so ${PHONE_DATA_DIR} || exit -1
adb </dev/null shell \ adb </dev/null shell \
LD_LIBRARY_PATH=${PHONE_DATA_DIR} \
MACE_CPP_MIN_VLOG_LEVEL=$VLOG_LEVEL \ MACE_CPP_MIN_VLOG_LEVEL=$VLOG_LEVEL \
MACE_RUN_PARAMETER_PATH=${PHONE_DATA_DIR}/mace_run.config \ MACE_RUN_PARAMETER_PATH=${PHONE_DATA_DIR}/mace_run.config \
${PHONE_DATA_DIR}/mace_run \ ${PHONE_DATA_DIR}/mace_run \
...@@ -50,15 +54,15 @@ build_and_run() ...@@ -50,15 +54,15 @@ build_and_run()
--output_shape="1,${IMAGE_SIZE},${IMAGE_SIZE},2"\ --output_shape="1,${IMAGE_SIZE},${IMAGE_SIZE},2"\
--input_file=${PHONE_DATA_DIR}/${INPUT_FILE_NAME} \ --input_file=${PHONE_DATA_DIR}/${INPUT_FILE_NAME} \
--output_file=${PHONE_DATA_DIR}/${OUTPUT_FILE_NAME} \ --output_file=${PHONE_DATA_DIR}/${OUTPUT_FILE_NAME} \
--device=HEXAGON \ --device=HEXAGON \
--round=$round --round=2 || exit -1
} }
echo "Step 1: Generate input data" echo "Step 1: Generate input data"
rm -rf ${MODEL_DIR}/${INPUT_FILE_NAME} rm -rf ${MODEL_DIR}/${INPUT_FILE_NAME}
python tools/validate.py --generate_data true \ python tools/validate.py --generate_data true \
--input_file=${MODEL_DIR}/${INPUT_FILE_NAME} \ --input_file=${MODEL_DIR}/${INPUT_FILE_NAME} \
--input_shape="${IMAGE_SIZE},${IMAGE_SIZE},3" --input_shape="${IMAGE_SIZE},${IMAGE_SIZE},3" || exit -1
echo "Step 2: Convert tf model to mace model and optimize memory" echo "Step 2: Convert tf model to mace model and optimize memory"
bazel build //mace/python/tools:tf_converter bazel build //mace/python/tools:tf_converter
...@@ -73,7 +77,7 @@ bazel-bin/mace/python/tools/tf_converter --input=${TF_MODEL_FILE_PATH} \ ...@@ -73,7 +77,7 @@ bazel-bin/mace/python/tools/tf_converter --input=${TF_MODEL_FILE_PATH} \
--output_type=source \ --output_type=source \
--template=${MACE_SOURCE_DIR}/mace/python/tools/model.template \ --template=${MACE_SOURCE_DIR}/mace/python/tools/model.template \
--model_tag=${MODEL_TAG} \ --model_tag=${MODEL_TAG} \
--obfuscate=True --obfuscate=True || exit -1
echo "Step 3: Generate version source" echo "Step 3: Generate version source"
rm -rf ${VERSION_SOURCE_PATH} rm -rf ${VERSION_SOURCE_PATH}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册