Description
Edit 3 hours later:I find the problem is caused by stream.use(), comment it and solve the problem.
Original problem:
I try to use cupy to process data and set bindings equal to the cupy data ptr. But when I use tensorrt to infer, I got an error
[TensorRT] ERROR: 1: [resize.cu::performLinearKernelLaunch::457] Error Code 1: Cuda Runtime (invalid argument).
I try to debug and find nan in outputs.
I am confused with how to use cupy in tensorrt. Could you give an example?
My code is as follows:
def infer(self, input):
# use pycuda context
self.cfx.push()
stream = cp.cuda.Stream(non_blocking=False)
stream.use()
bindings = []
# the input is a list [cp.array(), cp.array()]
for index, data in enumerate(input):
self.context.set_binding_shape(index, data.shape)
# bindings append the cupy data ptr
bindings.append(int(data.data))
# set output
outputs = []
for binding in self.engine:
if not self.engine.binding_is_input(binding):
size = trt.volume(
self.context.get_binding_shape(self.engine.get_binding_index(binding))) *
self.engine.max_batch_size * 2
device_mem = cp.cuda.alloc(size)
bindings.append(int(device_mem))
outputs.append(device_mem)
self.context.execute_async(bindings=bindings, stream_handle=stream.ptr)
results = []
for idx, (output, shape) in enumerate(zip(outputs, self.output_shape)):
if idx == 3:
cpu = np.zeros([1, 1080, 1920], dtype=np.float16)
output.copy_to_host(cpu.ctypes.data, 1080 * 1920 * 2)
print(cpu)
stream.synchronize()
self.cfx.pop()
Environment
TensorRT Version: 8.0
GPU Type: 2080ti
Nvidia Driver Version: 470
CUDA Version: 11.3
CUDNN Version: 8.2
Operating System + Version: ubuntu18.04
Python Version (if applicable): 3.9
PyTorch Version (if applicable): 1.11