szha commented on a change in pull request #20043:
URL: https://github.com/apache/incubator-mxnet/pull/20043#discussion_r613502931



##########
File path: src/storage/pooled_storage_manager.h
##########
@@ -148,9 +157,21 @@ void GPUPooledStorageManager::Alloc(Storage::Handle* 
handle) {
     mxnet::common::cuda::DeviceStore device_store(handle->ctx.real_dev_id(), 
true);
     size_t free, total;
     cudaMemGetInfo(&free, &total);
-    if (free <= total * reserve_ / 100 || size > free - total * reserve_ / 100)
+    double mem_limit_in_bytes = total * memory_limit_percentage_ / 100.0;
+    free = mem_limit_in_bytes - used_memory_;
+    if (free <= mem_limit_in_bytes * reserve_ / 100 ||
+        size > free - mem_limit_in_bytes * reserve_ / 100)
       ReleaseAll();
 
+    if (used_memory_ + size > mem_limit_in_bytes) {
+      // This calls abort() unless
+      // DMLC_LOG_FATAL_THROW != 0, then it
+      // throws std::runtime_error()
+      LOG(FATAL) << "memory limit reached, used: " << used_memory_ << "  
limit: "
+                 << mem_limit_in_bytes << " (" << memory_limit_percentage_ << 
"% of "
+                 << total << ")";
+    }

Review comment:
       Why?




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to