如何使用PyCuda mem_alloc_pitch()

2024-03-28 09:11:34 发布

您现在位置:Python中文网/ 问答频道 /正文

我最近一直在尝试PyCuda

我现在想做一些非常简单的事情,分配一些内存。我假设我有一些基本的误解,因为这是一个相当简单的任务。我的理解是,通过下面的代码,我将创建一个512宽、160高、elementsize为1字节的2d Cuda阵列

下面是一些测试代码

import pycuda.driver as cuda
import pycuda.autoinit
# Alloc some gpu memory
test_pitch = cuda.mem_alloc_pitch(512,160,1)

当我试着运行这段代码时,我得到了以下错误

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
pycuda._driver.LogicError: cuMemAllocPitch failed: invalid argument

如果有人对我做错了什么有任何见解,我们将不胜感激


Tags: 内存代码importpycuda字节asdriver事情
1条回答
网友
1楼 · 发布于 2024-03-28 09:11:34

引用CUDA驱动程序APIdocumentation

cuMemAllocPitch ( CUdeviceptr* dptr, 
                  size_t* pPitch, 
                  size_t WidthInBytes, 
                  size_t Height, 
                  unsigned int  ElementSizeBytes )

The function may pad the allocation to ensure that corresponding pointers in any given row will continue to meet the alignment requirements for coalescing as the address is updated from row to row. ElementSizeBytes specifies the size of the largest reads and writes that will be performed on the memory range. ElementSizeBytes may be 4, 8 or 16 (since coalesced memory transactions are not possible on other data sizes)

在本例中,前两个参数是PyCUDA调用中mem_alloc_pitch的返回值,而ElementSizeBytesaccess_size

你有:

cuda.mem_alloc_pitch(512,160,1)

也就是说,你的access_size是1,这是非法的。只有4、8或16是合法的。这就是错误

相关问题 更多 >