Skip to content

Commit

Permalink
Do not touch GPU 0 during ReleaseAll (apache#14550)
Browse files Browse the repository at this point in the history
* Do not touch GPU 0 during ReleaseAll

* Fixing lint and fixes from review

* Fix

* Fixes from review
  • Loading branch information
ptrendx authored and haohuw committed Jun 23, 2019
1 parent 7b62303 commit f270f28
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
16 changes: 14 additions & 2 deletions src/storage/pooled_storage_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,11 @@ class GPUPooledStorageManager final : public StorageManager {
public:
/*!
* \brief Default constructor.
*
* \param initial_context context used by this Storage Manager
*/
GPUPooledStorageManager() {
explicit GPUPooledStorageManager(Context initial_context) :
initial_context_(initial_context) {
reserve_ = dmlc::GetEnv("MXNET_GPU_MEM_POOL_RESERVE", 5);
page_size_ = dmlc::GetEnv("MXNET_GPU_MEM_POOL_PAGE_SIZE", 4096);
large_alloc_round_size_ = dmlc::GetEnv("MXNET_GPU_MEM_LARGE_ALLOC_ROUND_SIZE", 2 * 1024 * 1024);
Expand Down Expand Up @@ -123,6 +126,8 @@ class GPUPooledStorageManager final : public StorageManager {
int reserve_;
// number of devices
const size_t NDEV = 32;
// context used by this Storage Manager
const Context initial_context_;
// memory pool
std::unordered_map<size_t, std::vector<void*>> memory_pool_;
DISALLOW_COPY_AND_ASSIGN(GPUPooledStorageManager);
Expand Down Expand Up @@ -177,6 +182,7 @@ void GPUPooledStorageManager::ReleaseAll() {
Storage::Handle handle;
handle.dptr = j;
handle.size = i.first;
handle.ctx = initial_context_;
DirectFreeNoLock(handle);
}
}
Expand All @@ -201,8 +207,11 @@ class GPUPooledRoundedStorageManager final : public StorageManager {
public:
/*!
* \brief Default constructor.
*
* \param initial_context context used by this Storage Manager
*/
GPUPooledRoundedStorageManager() {
explicit GPUPooledRoundedStorageManager(Context initial_context) :
initial_context_(initial_context) {
reserve_ = dmlc::GetEnv("MXNET_GPU_MEM_POOL_RESERVE", 5);
page_size_ = dmlc::GetEnv("MXNET_GPU_MEM_POOL_PAGE_SIZE", 4096);
cut_off_ = dmlc::GetEnv("MXNET_GPU_MEM_POOL_ROUND_LINEAR_CUTOFF", 24);
Expand Down Expand Up @@ -290,6 +299,8 @@ class GPUPooledRoundedStorageManager final : public StorageManager {
size_t cut_off_;
// percentage of reserved memory
int reserve_;
// context used by this Storage Manager
const Context initial_context_;
// memory pool
std::vector<std::vector<void*>> memory_pool_;
DISALLOW_COPY_AND_ASSIGN(GPUPooledRoundedStorageManager);
Expand Down Expand Up @@ -345,6 +356,7 @@ void GPUPooledRoundedStorageManager::ReleaseAll() {
Storage::Handle handle;
handle.size = size;
handle.dptr = j;
handle.ctx = initial_context_;
DirectFreeNoLock(handle);
}
memory_pool_[i].clear();
Expand Down
4 changes: 2 additions & 2 deletions src/storage/storage.cc
Original file line number Diff line number Diff line change
Expand Up @@ -104,13 +104,13 @@ void StorageImpl::Alloc(Storage::Handle* handle) {
std::string strategy = type;

if (strategy == "Round") {
ptr = new storage::GPUPooledRoundedStorageManager();
ptr = new storage::GPUPooledRoundedStorageManager(handle->ctx);
LOG(INFO) << "Using GPUPooledRoundedStorageManager.";
} else {
if (strategy != "Naive") {
LOG(FATAL) << "Unknown memory pool strategy specified: " << strategy << ".";
}
ptr = new storage::GPUPooledStorageManager();
ptr = new storage::GPUPooledStorageManager(handle->ctx);
}
#else
LOG(FATAL) << "Compile with USE_CUDA=1 to enable GPU usage";
Expand Down

0 comments on commit f270f28

Please sign in to comment.