Skip to content
This repository was archived by the owner on Jan 24, 2024. It is now read-only.

fix bug in build arm #300

Open
wants to merge 15 commits into
base: developing
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 72 additions & 9 deletions framework/core/thread_pool.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<void(void)> task;
{
std::unique_lock<std::mutex> 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 functor, typename ...ParamTypes>
typename function_traits<functor>::return_type RunSync(functor function, ParamTypes ...args);
typename function_traits<functor>::return_type RunSync(functor function, ParamTypes ...args)
EXCLUSIVE_LOCKS_REQUIRED(_mut) {
auto task = std::make_shared<std::packaged_task<typename function_traits<functor>::return_type(void)> >( \
std::bind(function, std::forward<ParamTypes>(args)...)
);
std::future<typename function_traits<functor>::return_type> result = task->get_future();
{
std::unique_lock<std::mutex> lock(this->_mut);
this->_tasks.emplace( [&]() { (*task)(); } );
}
this->_cv.notify_one();
return result.get();
}


/**
* \brief Lanuch the normal function task in async.
*/
template<typename functor, typename ...ParamTypes>
typename std::future<typename function_traits<functor>::return_type> RunAsync(functor function, ParamTypes ...args);

std::future<typename function_traits<functor>::return_type> RunAsync(functor function, ParamTypes ...args)
EXCLUSIVE_LOCKS_REQUIRED(_mut) {
auto task = std::make_shared<std::packaged_task<typename function_traits<functor>::return_type(void)> >( \
std::bind(function, std::forward<ParamTypes>(args)...)
);
std::future<typename function_traits<functor>::return_type> result = task->get_future();
{
std::unique_lock<std::mutex> lock(this->_mut);
this->_tasks.emplace( [=]() { (*task)(); } );
}
this->_cv.notify_one();
return result;
}
/// Stop the pool.
void stop();
void stop() {
std::unique_lock<std::mutex> 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;
Expand All @@ -66,8 +127,10 @@ class ThreadPool {
bool _stop{false};
};


} /* namespace anakin */

#include "thread_pool.inl"
//#include "thread_pool.inl"


#endif
4 changes: 2 additions & 2 deletions framework/core/thread_pool.inl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

namespace anakin {

/*
void ThreadPool::launch() {
for(size_t i = 0; i<_num_thread; ++i) {
_workers.emplace_back(
Expand Down Expand Up @@ -75,5 +75,5 @@ std::future<typename function_traits<functor>::return_type> ThreadPool::RunAsync
this->_cv.notify_one();
return result;
}

*/
} /* namespace anakin */
2 changes: 1 addition & 1 deletion saber/funcs/attension_lstm.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions saber/funcs/sequence_expand.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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 {
Expand Down