You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tvm.apache.org by GitBox <gi...@apache.org> on 2021/06/01 23:37:56 UTC

[GitHub] [tvm] trevor-m commented on a change in pull request #8172: [BYOC][TensorRT] Reuse TRT engines based on max_batch_size for dynamic batching, improve device buffer allocation

trevor-m commented on a change in pull request #8172:
URL: https://github.com/apache/tvm/pull/8172#discussion_r643553887



##########
File path: src/runtime/contrib/tensorrt/tensorrt_runtime.cc
##########
@@ -174,25 +176,50 @@ class TensorRTRuntime : public JSONRuntimeBase {
       int binding_index = engine->getBindingIndex(name.c_str());
       ICHECK_NE(binding_index, -1);
       if (data_entry_[eid]->device.device_type != kDLCUDA) {
-        device_buffers[binding_index].CopyTo(const_cast<DLTensor*>(data_entry_[eid]));
+        auto device_buffer = GetOrAllocateDeviceBuffer(eid, binding_index);
+        device_buffer.CopyTo(const_cast<DLTensor*>(data_entry_[eid]));
       }
     }
   }
 
  private:
+  /*! \brief Get batch size for engine from the runtime input shapes. */
+  int GetBatchSize() {
+    return data_entry_[input_var_eid_[0]]->ndim == 0 ? 1 : data_entry_[input_var_eid_[0]]->shape[0];
+  }
+
+  /*! \brief TensorRT engines are built for a maximum batch size. If an engine doesn't exist for a
+   * certain batch size already, see if we can reuse an engine built for a higher batch size. */
+  bool FindCompatibleEngine(int batch_size, int* compatible_engine_batch_size) {
+    // Check for exact match
+    if (trt_engine_cache_.count(std::make_pair(symbol_name_, batch_size))) {
+      *compatible_engine_batch_size = batch_size;
+      return true;
+    }

Review comment:
       Thanks for the review! Yes, I suppose we could do that instead. 




-- 
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:
users@infra.apache.org