MCPcopy
hub / github.com/NVIDIA/TensorRT-LLM / _scoped_stream

Function _scoped_stream

tensorrt_llm/runtime/session.py:32–42  ·  view source on GitHub ↗

Create a scoped cuda stream, and synchronize it when the context is destroyed

()

Source from the content-addressed store, hash-verified

30
31@contextlib.contextmanager
32def _scoped_stream():
33 '''Create a scoped cuda stream, and synchronize it when the context is destroyed
34 '''
35 #TODO: delete torch, use cuda native python bindings
36 import torch
37 stream = torch.cuda.current_stream()
38 try:
39 # return a handle, trt and other lib does not recognize torch.cuda.Stream
40 yield stream.cuda_stream
41 finally:
42 stream.synchronize()
43
44
45@dataclass

Callers 3

_debug_runMethod · 0.85

Calls 2

current_streamMethod · 0.80
synchronizeMethod · 0.80

Tested by

no test coverage detected