Skip to content
Merged
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
13 changes: 8 additions & 5 deletions alonet/torch2trt/TRTExecutor.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,9 @@ def __init__(
else:
self.engine = engine
self.context = self.engine.create_execution_context()
if self.context is None:
raise Exception("Execution context creation failed")

if profiling:
self.context.profiler = CustomProfiler()
# Allocate_buffer take into account if engine has dynamic axes
Expand Down Expand Up @@ -127,13 +130,13 @@ def execute(self, inputs_from_cpu=False, outputs_to_cpu=False):
Parameters
----------
inputs_from_cpu: bool, reload inputs from CPU again.
outputs_from_cpu: bool, transfer back all outputs back from GPU to CPU.
outputs_to_cpu: bool, transfer back all outputs back from GPU to CPU.

Examples
--------
~ Example of engine with 2 inputs eand 2 outputs ~
>>> # Normal use.
>>> engine = TRTExecutor(**kwrags)
>>> engine = TRTExecutor(shared_mem={}, **kwrags)
>>> engine.inputs[0].host, engine.inpts[1].host = np.ones(1), np.ones(1)
>>> outputs = engine.execute()
>>>
Expand All @@ -145,10 +148,10 @@ def execute(self, inputs_from_cpu=False, outputs_to_cpu=False):
>>> if i == 0:
>>> ## First time only
>>> engine.input[0].host = np.zeros(0)
>>> ekawrgs["inputs_from_cpu"] = True
>>> ekwargs["inputs_from_cpu"] = True
>>> engine.execute(**ekwargs)
>>> # Retieve last output 1 from gpu
>>> engine.execute(outputs_to_cpu)
>>> # Retieve last output of index 1 from gpu
>>> engine.execute(outputs_to_cpu=True)
>>> print(engine.outputs.host[1])
"""
if self.has_dynamic_axes:
Expand Down