Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 关于pycuda的问题。\u driver.logicalError:cuMemcpyDtoH失败:参数无效_Python_Python 3.x_Pycuda_Tensorrt - Fatal编程技术网

Python 关于pycuda的问题。\u driver.logicalError:cuMemcpyDtoH失败:参数无效

Python 关于pycuda的问题。\u driver.logicalError:cuMemcpyDtoH失败:参数无效,python,python-3.x,pycuda,tensorrt,Python,Python 3.x,Pycuda,Tensorrt,我试图运行一个基于以下链接的代码 在这个链接中运行代码就可以了 这是我的版本,具有类似的定义。请注意,我是在引擎上下文下运行的,因为我想运行engine.execute函数 import pycuda.driver as cuda import pycuda.autoinit import tensorrt as trt import numpy as np from keras.datasets import mnist dims = (1, 28, 28) dims2 = (

我试图运行一个基于以下链接的代码

在这个链接中运行代码就可以了

这是我的版本,具有类似的定义。请注意,我是在引擎上下文下运行的,因为我想运行engine.execute函数

import pycuda.driver as cuda 
import pycuda.autoinit 
import tensorrt as trt 

import numpy as np
from keras.datasets import mnist 

dims = (1, 28, 28) 
dims2 = (1, 1, 10) 
batch_size = 1000 

nbytes = batch_size * trt.volume(dims) * np.dtype(np.float32).itemsize 
nbytes2 = batch_size * trt.volume(dims2) * np.dtype(np.float32).itemsize 

self.d_src  = cuda.mem_alloc(nbytes) 
self.d_dst = cuda.mem_alloc(nbytes2) 

bindings = [int(self.d_src), int(self.d_dst)] 

(x_train, y_train), (x_test, y_test) = mnist.load_data()

img_h = x_test.shape[1]
img_w = x_test.shape[2]

x_test = x_test.reshape(x_test.shape[0], 1, img_h, img_w)

x_test = x_test.astype('float32')
x_test /= 255
num_test = x_test.shape[0]

output_size = batch_size * trt.volume(dims2)

y = np.empty((num_test,output_size), np.float32)

for i in range(0, num_test, batch_size): 
     x_part = x_test[i : i + batch_size] 
     y_part = y[i : i + batch_size] 
     cuda.memcpy_htod(self.d_src, x_part) 

     cuda.memcpy_dtoh(y_part, self.d_dst) 
然而,它在memcpydtoh失败了,然而memcpyhtod工作了

File "a.py", line 164, in infer
    cuda.memcpy_dtoh(y_part, self.d_dst)
pycuda._driver.LogicError: cuMemcpyDtoH failed: invalid argument

为什么会这样?定义与链接中的代码类似。

我已经解决了它

对于
x\u部件
y\u部件
,设备分配需要不同,因为它们的大小不同

因此,如果我定义
output\u size=trt.volume(dims2)
,它就可以工作了


这个错误消息一开始并没有什么帮助&让我觉得我输入了错误的参数

这段代码有什么帮助?我自己跑不了。什么是x_部分和y_部分?编辑以包含x&y定义,尽管我最初认为您可以使用前面链接中定义的x&y。您好,我最近刚开始在tensorrt工作,我被完全相同的错误所困扰。如果您能更详细地解释您的答案,比如如何将
output\u size=batch\u size*trt.volume(dims2)
更改为
output\u size=trt.volume(dims2)
,那将对我大有帮助。我可能只是问了一个幼稚的问题,我也试图从文档中了解更多。