From 90a9c960a99f327faa264299f483f78f6907e76d Mon Sep 17 00:00:00 2001 From: chenjiaoAngel Date: Fri, 10 Aug 2018 14:45:04 +0800 Subject: [PATCH 1/6] Update thread_pool.inl --- framework/core/thread_pool.inl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/framework/core/thread_pool.inl b/framework/core/thread_pool.inl index 3aa8bab05..2528847a3 100644 --- a/framework/core/thread_pool.inl +++ b/framework/core/thread_pool.inl @@ -1,6 +1,6 @@ namespace anakin { - +/* void ThreadPool::launch() { for(size_t i = 0; i<_num_thread; ++i) { _workers.emplace_back( @@ -75,5 +75,5 @@ std::future::return_type> ThreadPool::RunAsync this->_cv.notify_one(); return result; } - +*/ } /* namespace anakin */ From 8f8e6ed245239c76687ec82fe5f643ad1ab1997c Mon Sep 17 00:00:00 2001 From: chenjiaoAngel Date: Fri, 10 Aug 2018 14:45:25 +0800 Subject: [PATCH 2/6] Update thread_pool.h --- framework/core/thread_pool.h | 81 ++++++++++++++++++++++++++++++++---- 1 file changed, 72 insertions(+), 9 deletions(-) diff --git a/framework/core/thread_pool.h b/framework/core/thread_pool.h index 1f4c72d62..73723e046 100644 --- a/framework/core/thread_pool.h +++ b/framework/core/thread_pool.h @@ -32,30 +32,91 @@ namespace anakin { class ThreadPool { public: ThreadPool(int num_thread):_num_thread(num_thread) {} - virtual ~ThreadPool(); - void launch(); + //virtual ~ThreadPool(); + void launch() { + for(size_t i = 0; i<_num_thread; ++i) { + _workers.emplace_back( + [i ,this]() { + // initial + this->init(); + for(;;) { + std::function task; + { + std::unique_lock lock(this->_mut); + while(!this->_stop && this->_tasks.empty()) { + this->_cv.wait(lock); + } + if(this->_stop) { + return ; + } + task = std::move(this->_tasks.front()); + this->_tasks.pop(); + } + DLOG(INFO) << " Thread (" << i <<") processing"; + auxiliary_funcs(); + task(); + } + } + ); + } + } /** * \brief Lanuch the normal function task in sync. */ template - typename function_traits::return_type RunSync(functor function, ParamTypes ...args); + typename function_traits::return_type RunSync(functor function, ParamTypes ...args) + EXCLUSIVE_LOCKS_REQUIRED(_mut) { + auto task = std::make_shared::return_type(void)> >( \ + std::bind(function, std::forward(args)...) + ); + std::future::return_type> result = task->get_future(); + { + std::unique_lock lock(this->_mut); + this->_tasks.emplace( [&]() { (*task)(); } ); + } + this->_cv.notify_one(); + return result.get(); + } + /** * \brief Lanuch the normal function task in async. */ template - typename std::future::return_type> RunAsync(functor function, ParamTypes ...args); - + std::future::return_type> RunAsync(functor function, ParamTypes ...args) + EXCLUSIVE_LOCKS_REQUIRED(_mut) { + auto task = std::make_shared::return_type(void)> >( \ + std::bind(function, std::forward(args)...) + ); + std::future::return_type> result = task->get_future(); + { + std::unique_lock lock(this->_mut); + this->_tasks.emplace( [=]() { (*task)(); } ); + } + this->_cv.notify_one(); + return result; + } /// Stop the pool. - void stop(); + void stop() { + std::unique_lock lock(this->_mut); + _stop = true; + } + + ~ThreadPool() { + stop(); + this->_cv.notify_all(); + for(auto & worker: _workers){ + worker.join(); + } + } private: /// The initial function should be overrided by user who derive the ThreadPool class. - virtual void init(); + virtual void init() {} /// Auxiliary function should be overrided when you want to do other things in the derived class. - virtual void auxiliary_funcs(); + virtual void auxiliary_funcs() {} private: int _num_thread; @@ -66,8 +127,10 @@ class ThreadPool { bool _stop{false}; }; + } /* namespace anakin */ -#include "thread_pool.inl" +//#include "thread_pool.inl" + #endif From f8cc500a6364503117d075a11e4fb72a7ca9a627 Mon Sep 17 00:00:00 2001 From: chenjiaoAngel Date: Fri, 10 Aug 2018 16:59:37 +0800 Subject: [PATCH 3/6] fix bug in build arm --- saber/funcs/attension_lstm.h | 2 +- saber/funcs/sequence_expand.h | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/saber/funcs/attension_lstm.h b/saber/funcs/attension_lstm.h index a2b7225fc..a56cfb952 100644 --- a/saber/funcs/attension_lstm.h +++ b/saber/funcs/attension_lstm.h @@ -29,7 +29,7 @@ #endif #ifdef USE_ARM_PLACE //todo -//#include "saber/funcs/impl/impl_attension_lstm.h" +#include "saber/funcs/impl/impl_attension_lstm.h" #endif namespace anakin { namespace saber { diff --git a/saber/funcs/sequence_expand.h b/saber/funcs/sequence_expand.h index ec1c2b2c5..15d5312c7 100644 --- a/saber/funcs/sequence_expand.h +++ b/saber/funcs/sequence_expand.h @@ -18,7 +18,7 @@ #include "saber/funcs/base.h" #include "saber/funcs/impl/impl_base.h" -#include "saber/funcs/impl/impl_activation.h" +#include "saber/funcs/impl/impl_sequence_expand.h" #ifdef NVIDIA_GPU #include "saber/funcs/impl/cuda/saber_sequence_expand.h" @@ -30,7 +30,7 @@ #endif #ifdef USE_ARM_PLACE -//#include "saber/funcs/impl/arm/saber_activation.h" +#include "saber/funcs/impl/impl_sequence_expand.h" #endif namespace anakin { From 6054af3c4ab53948b41a0028747eba1864809a8b Mon Sep 17 00:00:00 2001 From: chenjiaoAngel Date: Mon, 27 Aug 2018 10:59:22 +0800 Subject: [PATCH 4/6] fix code style --- docs/Manual/Converter_ch.md | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/docs/Manual/Converter_ch.md b/docs/Manual/Converter_ch.md index 7984c795c..20433fa1b 100644 --- a/docs/Manual/Converter_ch.md +++ b/docs/Manual/Converter_ch.md @@ -4,19 +4,19 @@ Anakin 支持不同框架的模型预测。但由于格式的差别,Anakin 需 ## 简介 -Anakin 模型转换器输入支持 Caffe 和 Fluid 两种格式的预测模型,模型包含网络结构(model 或 prototxt)和权重参数(param 或 caffemodel)。 +Anakin 模型转换器输入支持 Caffe 和 Fluid 两种格式的预测模型,模型包含网络结构(model 或 prototxt)和权重参数(param 或 caffemodel)。 -模型转换的输出是一个 bin 文件,它作为 Anakin 框架的 graph 参数导入。 +模型转换的输出是一个 bin 文件,它作为 Anakin 框架的 graph 参数导入。 -您还可以使用模型转换器的 launch board 功能生成网络结构的 HTML 预览。 +您还可以使用模型转换器的 launch board 功能生成网络结构的 HTML 预览。 ## 系统要求 - Python 2.7+ -- Protobuf 3.1+(务必注意 Python 与系统环境 Protobuf 版本一致) -- PaddlePaddle 0.12.0+ (Fluid 模式下) -- flask, bson, matplotlib, scikit-image +- Protobuf 3.1+ (Make sure that Pip Protobuf is consistent with the system Protobuf version.) +- PaddlePaddle 0.12.0+ (Fluid mode) +- flask, bson, matplotlib, scikit-image - tkinter @@ -39,7 +39,7 @@ OPTIONS: Server: ip: 0.0.0.0 port: 8888 # 从一个可用端口访问预览页面 - OptimizedGraph: # 仅当您执行完预测并使用 Optimized 功能时,才应打开此项 + OptimizedGraph: # 当您使用了 Anakin 框架的 Optimized 功能时,才应该打开此项 enable: OFF path: /path/to/anakin_optimized_anakin_model/googlenet.anakin.bin.saved LOGGER: @@ -61,7 +61,7 @@ TARGET: - / PrototxtPath: /path/to/fluid/inference_model ModelPath: /path/to/fluid/inference_model - # ... + # ... ``` ### 3、转换 From 20a1b0690624a9a0f8f52e72c97eaaac03e81f84 Mon Sep 17 00:00:00 2001 From: chenjiaoAngel Date: Mon, 27 Aug 2018 11:00:31 +0800 Subject: [PATCH 5/6] fix code style --- docker/README.md | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/docker/README.md b/docker/README.md index 3f2a628c2..8b34b6bb4 100644 --- a/docker/README.md +++ b/docker/README.md @@ -1,5 +1,4 @@ -# Anakin 2.0 And Docker ---- +# Anakin 2.0 Docker ## Requirement @@ -32,15 +31,18 @@ $./anakin_docker_build_and_run.sh -p NVIDIA-GPU -o Centos -m Build ``` #### Run docker + ```bash $/usr/bash anakin_docker_build_and_run.sh -p NVIDIA-GPU -o Centos -m Run or $chmod +x ./anakin_docker_build_and_run.sh $./anakin_docker_build_and_run.sh -p NVIDIA-GPU -o Centos -m Run ``` + When running docker successfully, you can find Anakin source code at /Anakin directory. ### X86 Docker + #### Build Image ```bash @@ -60,23 +62,26 @@ $/usr/bash anakin_docker_build_and_run.sh -p X86-ONLY -o Centos -m Run $chmod +x ./anakin_docker_build_and_run.sh $./anakin_docker_build_and_run.sh -p X86-ONLY -o Centos -m Run -# or +# or # run docker by docker run command. # firt find the x86 image you just built. $docker images -# This command will list all docker images you have built. +# This command will list all docker images you have built. #Then, find anakin and it's tag. finally, run x86 docker. # for ubuntu, type anakin:x86_ubuntu16.04-x86 instead. $docker run -it anakin:x86_centos7-x86 /bin/bash ``` + When running docker successfully, you can find Anakin source code at /Anakin directory. ### ARM Docker We only support arm docker based on centos for now. + #### Build Image + ```bash $/usr/bash anakin_docker_build_and_run.sh -p ARM -o Centos -m Build @@ -99,14 +104,16 @@ $./anakin_docker_build_and_run.sh -p ARM -o Centos -m Run $docker images -# This command will list all docker images you have built. +# This command will list all docker images you have built. #Then, find anakin and it's tag. finally, run arm docker. $docker run -it anakin:arm_centos7-armv7 /bin/bash ``` + When running docker successfully, you can find Anakin source code at /Anakin directory. -NOTE -If you want to use opencv(only used in Anakin samples), please refer [run on arm](../docs/Manual/run_on_arm_en.md) to install opencv and recompile Anakin -(you just need to run 'Anakin/tools/andrid_build.sh'). You can install it before the arm docker image's building has done successfully. At last, don't forget to commit your changes to the docker image you built. \ No newline at end of file +### NOTE + +If you want to use opencv(only used in Anakin samples), please refer [run on arm](../docs/Manual/run_on_arm_en.md) to install opencv and recompile Anakin +(you just need to run 'Anakin/tools/andrid_build.sh'). You can install it before the arm docker image's building has done successfully. At last, don't forget to commit your changes to the docker image you built. From 1cef8123b0fcba180e8fd9adaf690115caaeb1c4 Mon Sep 17 00:00:00 2001 From: chenjiaoAngel Date: Mon, 27 Aug 2018 11:01:08 +0800 Subject: [PATCH 6/6] fix code style and add x86, arm docker --- docker/README_cn.md | 76 ++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 72 insertions(+), 4 deletions(-) diff --git a/docker/README_cn.md b/docker/README_cn.md index 6d5ed994a..262c71ca9 100644 --- a/docker/README_cn.md +++ b/docker/README_cn.md @@ -1,5 +1,4 @@ -# Anakin 2.0 And Docker ---- +# Anakin 2.0 Docker ## 依赖软件 @@ -21,7 +20,9 @@ Usage: anakin_docker_build_and_run.sh -p -o -m ``` ### GPU Docker + #### 构建镜像 + ```bash /usr/bash anakin_docker_build_and_run.sh -p NVIDIA-GPU -o Centos -m Build 或者 @@ -30,6 +31,7 @@ chmod +x ./anakin_docker_build_and_run.sh ``` #### 运行 docker容器 + ```bash /usr/bash anakin_docker_build_and_run.sh -p NVIDIA-GPU -o Centos -m Run 或者 @@ -37,10 +39,76 @@ chmod +x ./anakin_docker_build_and_run.sh ./anakin_docker_build_and_run.sh -p NVIDIA-GPU -o Centos -m Run ``` +当docker运行成功后,你可以在./Anakin目录下找到Anakin代码 + ### X86 Docker -> Not support yet +#### 构建镜像 + +```bash +$/usr/bash anakin_docker_build_and_run.sh -p X86-ONLY -o Centos -m Build + +# or +$chmod +x ./anakin_docker_build_and_run.sh +$./anakin_docker_build_and_run.sh -p X86-ONLY -o Centos -m Build +``` + +#### 运行 docker容器 + +```bash +$/usr/bash anakin_docker_build_and_run.sh -p X86-ONLY -o Centos -m Run + +# or +$chmod +x ./anakin_docker_build_and_run.sh +$./anakin_docker_build_and_run.sh -p X86-ONLY -o Centos -m Run + +# or +# run docker by docker run command. +# firt find the x86 image you just built. + +$docker images + +# This command will list all docker images you have built. +#Then, find anakin and it's tag. finally, run x86 docker. +# for ubuntu, type anakin:x86_ubuntu16.04-x86 instead. +$docker run -it anakin:x86_centos7-x86 /bin/bash +``` + +当docker运行成功后,你可以在./Anakin目录下找到Anakin代码 ### ARM Docer -> Not support yet +我们目前只支持centos系统系统下的arm docker + +#### 构建镜像 + +```bash +$/usr/bash anakin_docker_build_and_run.sh -p ARM -o Centos -m Build + +# or +$chmod +x ./anakin_docker_build_and_run.sh +$./anakin_docker_build_and_run.sh -p ARM -o Centos -m Build +``` + +#### 运行 docker容器 + +```bash +$/usr/bash anakin_docker_build_and_run.sh -p ARM -o Centos -m Run + +# or +$chmod +x ./anakin_docker_build_and_run.sh +$./anakin_docker_build_and_run.sh -p ARM -o Centos -m Run + +# or run docker by docker run command. +# firt find the arm image you just built. + +$docker images + +# This command will list all docker images you have built. +#Then, find anakin and it's tag. finally, run arm docker. + +$docker run -it anakin:arm_centos7-armv7 /bin/bash + +``` + +当docker运行成功后,你可以在./Anakin目录下找到Anakin代码