Skip to content
This repository was archived by the owner on Nov 17, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all 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
22 changes: 22 additions & 0 deletions doc/env_var.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
Environment Variables
=====================
MXNet have several settings that can be changed via environment variable.
Usually you do not need to change these settings, but they are listed here for reference.

* MXNET_GPU_WORKER_NTHREADS (default=1 when number of cpu<8, otherwise 2)
- Maximum number of threads that do the computation job on each GPU.
* MXNET_GPU_COPY_NTHREADS (default=1)
- Maximum number of threads that do memory copy job on each GPU.
* MXNET_CPU_WORKER_NTHREADS (default=1)
- Maximum number of threads that do the CPU computation job.
* MXNET_EXEC_ENABLE_INPLACE (default=true)
- Whether to enable inplace optimization in symbolic execution.
* MXNET_EXEC_MATCH_RANGE (default=10)
- The rough matching scale in symbolic execution memory allocator.
- Set this to 0 if we do not want to enable memory sharing between graph nodes(for debug purpose).
* MXNET_ENGINE_TYPE (default=ThreadedEnginePerDevice)
- The type of underlying execution engine of MXNet.
- List of choices
- NaiveEngine: very simple engine that use master thread to do computation.
- ThreadedEngine: a threaded engine that uses global thread pool to schedule jobs.
- ThreadedEnginePerDevice: a threaded engine that allocates thread per GPU.
2 changes: 1 addition & 1 deletion doc/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ User Guide
Developer Guide
---------------
* [Developer Documents](developer-guide/index.md)
* [Environment Variables for MXNet](env_var.md)
* [Contributor Guideline](contribute.md)
* [Doxygen Version of C++ API](https://mxnet.readthedocs.org/en/latest/doxygen)


Indices and tables
------------------

Expand Down
13 changes: 13 additions & 0 deletions src/common/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,26 @@
#include <type_traits>
#include <utility>
#include <random>
#include <thread>
#endif // DMLC_USE_CXX11

#include <dmlc/logging.h>

namespace mxnet {
namespace common {

#if DMLC_USE_CXX11

// heuristic to dermine number of threads per GPU
inline int GetNumThreadPerGPU() {
int nthread = std::thread::hardware_concurrency();
if (nthread < 8) {
return dmlc::GetEnv("MXNET_GPU_WORKER_NTHREADS", 1);
} else {
return dmlc::GetEnv("MXNET_GPU_WORKER_NTHREADS", 2);
}
}

/*!
* \brief Random Engine
*/
Expand Down
6 changes: 4 additions & 2 deletions src/engine/threaded_engine_perdevice.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@
* \brief ThreadedEngine that uses fix amount of thread for each device.
*/
#include <dmlc/base.h>
#include <dmlc/omp.h>
#include <dmlc/logging.h>
#include <dmlc/parameter.h>
#include <dmlc/concurrency.h>
#include "./threaded_engine.h"
#include "./thread_pool.h"
#include "../common/lazy_alloc_array.h"
#include "../common/utils.h"

namespace mxnet {
namespace engine {
Expand All @@ -24,8 +26,8 @@ namespace engine {
class ThreadedEnginePerDevice : public ThreadedEngine {
public:
ThreadedEnginePerDevice() noexcept(false) {
cpu_worker_nthreads_ = dmlc::GetEnv("MXNET_CPU_WORKER_NTHREADS", 2);
gpu_worker_nthreads_ = dmlc::GetEnv("MXNET_GPU_WORKER_NTHREADS", 2);
cpu_worker_nthreads_ = dmlc::GetEnv("MXNET_CPU_WORKER_NTHREADS", 1);
gpu_worker_nthreads_ = common::GetNumThreadPerGPU();
gpu_copy_nthreads_ = dmlc::GetEnv("MXNET_GPU_COPY_NTHREADS", 1);
// create CPU task
cpu_worker_.reset(new ThreadWorkerBlock());
Expand Down
2 changes: 1 addition & 1 deletion src/io/iter_image_recordio.cc
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ inline void ImageRecordIOParser::Init(
#pragma omp parallel
{
// be conservative, set number of real cores
maxthread = std::max(omp_get_num_procs() / 2, 1);
maxthread = std::max(omp_get_num_procs() / 2 - 1, 1);
}
param_.preprocess_threads = std::min(maxthread, param_.preprocess_threads);
#pragma omp parallel num_threads(param_.preprocess_threads)
Expand Down
3 changes: 3 additions & 0 deletions src/symbol/graph_memory_allocator.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include <algorithm>
#include "./static_graph.h"
#include "./graph_algorithm.h"
#include "../common/utils.h"

namespace mxnet {
/*!
Expand Down Expand Up @@ -119,6 +120,8 @@ GraphStorageAllocator::GraphStorageAllocator(
// color based match will cost a bit more memory usually
// but also enables more parallelization.
num_match_color_ = dmlc::GetEnv("MXNET_EXEC_MATCH_NUM_COLOR", 4);
num_match_color_ = std::min(static_cast<uint32_t>(common::GetNumThreadPerGPU()),
num_match_color_);
this->InitColor(topo_order);
}

Expand Down