Skip to content
This repository has been archived by the owner on Nov 17, 2023. It is now read-only.

Commit

Permalink
Merge pull request #158 from tqchen/master
Browse files Browse the repository at this point in the history
[ENGINE] Change obj pool to normal struct instead of union
  • Loading branch information
tqchen committed Sep 26, 2015
2 parents e459646 + a801b3e commit f7fecc9
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 3 deletions.
3 changes: 2 additions & 1 deletion include/mxnet/base.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@
* Used to support g++-4.6 and g++4.7
*/
#if DMLC_USE_CXX11 && defined(__GNUC__) && !defined(__clang_version__)
#if __GNUC__ == 4 && __GNUC_MINOR__ == 6
#if __GNUC__ == 4 && __GNUC_MINOR__ < 8
#error "Currently we need g++ 4.8 or higher to fully support c++11 features"
#define override
#define final
#endif
Expand Down
1 change: 1 addition & 0 deletions scripts/travis_script.sh
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ if [ ${TASK} == "cpp_unittest" ]; then
echo "GTEST_PATH="${CACHE_PREFIX} >> config.mk
make test || exit -1
export MXNET_ENGINE_TYPE=ThreadedEngine
export MXNET_ENGINE_INFO=true
for test in tests/cpp/*_test; do
./$test || exit -1
done
Expand Down
7 changes: 6 additions & 1 deletion src/common/object_pool.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,15 @@ class ObjectPool {
* \brief Internal structure to hold pointers.
*/
struct LinkedList {
#if defined(_MSC_VER)
T t;
LinkedList* next{nullptr};
#else
union {
LinkedList* next{nullptr};
T t;
LinkedList* next{nullptr};
};
#endif
};
/*!
* \brief Page size of allocation.
Expand Down
6 changes: 6 additions & 0 deletions src/engine/threaded_engine.cc
Original file line number Diff line number Diff line change
Expand Up @@ -302,11 +302,17 @@ void ThreadedEngine::WaitForVar(VarHandle var) {
if (threaded_var->ready_to_read()) return;
std::atomic<bool> done{false};
this->PushSync([this, &done](RunContext) {
if (engine_info_) {
LOG(INFO) << "Sync is executed";
}
{
std::unique_lock<std::mutex> lock{finished_m_};
done.store(true);
}
finished_cv_.notify_all();
if (engine_info_) {
LOG(INFO) << "Sync is notified";
}
}, Context::CPU(), {var}, {}, FnProperty::kNormal);
{
std::unique_lock<std::mutex> lock{finished_m_};
Expand Down
6 changes: 5 additions & 1 deletion src/engine/threaded_engine.h
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,9 @@ class ThreadedEngine : public Engine {
shutdown_phase_.store(true);
}

ThreadedEngine() {}
ThreadedEngine() {
engine_info_ = dmlc::GetEnv("MXNET_ENGINE_INFO", false);
}
~ThreadedEngine() {
{
std::unique_lock<std::mutex> lock{finished_m_};
Expand Down Expand Up @@ -319,6 +321,8 @@ class ThreadedEngine : public Engine {
std::atomic<bool> kill_{false};
/*! \brief whether it is during shutdown phase*/
std::atomic<bool> shutdown_phase_{false};
/*!\brief show more information from engine actions */
bool engine_info_{false};
/*!
* \brief Mutex and condition_variable,
* used to Notify waits for single or all variables.
Expand Down

0 comments on commit f7fecc9

Please sign in to comment.