MCPcopy Create free account
hub / github.com/Project-MONAI/MONAI / set_inputs

Method set_inputs

monai/networks/trt_compiler.py:168–202  ·  view source on GitHub ↗

Sets input bindings for TRT engine according to feed_dict Args: feed_dict: a dictionary [str->Tensor] stream: CUDA stream to use

(self, feed_dict, stream)

Source from the content-addressed store, hash-verified

166 ctx.set_tensor_address(binding, t.data_ptr())
167
168 def set_inputs(self, feed_dict, stream):
169 """
170 Sets input bindings for TRT engine according to feed_dict
171 Args:
172 feed_dict: a dictionary [str->Tensor]
173 stream: CUDA stream to use
174 """
175 e = self.engine
176 ctx = self.context
177
178 last_profile = self.cur_profile
179
180 def try_set_inputs():
181 for binding in self.input_names:
182 t = feed_dict.get(self.input_table[binding], None)
183 if t is not None:
184 t = t.contiguous()
185 shape = t.shape
186 ctx.set_input_shape(binding, shape)
187 ctx.set_tensor_address(binding, t.data_ptr())
188
189 while True:
190 try:
191 try_set_inputs()
192 break
193 except ShapeError:
194 next_profile = (self.cur_profile + 1) % e.num_optimization_profiles
195 if next_profile == last_profile:
196 raise
197 self.cur_profile = next_profile
198 ctx.set_optimization_profile_async(self.cur_profile, stream)
199 except Exception:
200 raise
201 left = ctx.infer_shapes()
202 assert len(left) == 0
203
204 def infer(self, stream, use_cuda_graph=False):
205 """

Callers 1

forwardMethod · 0.80

Calls

no outgoing calls

Tested by

no test coverage detected