【问题标题】:Call to cuMemcpyDtoH results in UNKNOWN_CUDA_ERROR with Numba guVectorize tags使用 Numba guVectorize 标签调用 cuMemcpyDtoH 会导致 UNKNOWN_CUDA_ERROR
【发布时间】:2020-09-04 17:01:12
【问题描述】:

我正在尝试获取我编写的 Python 双边过滤器,以便在我的 GPU 上工作,但我一直遇到错误,而且我得到了一个对我来说非常神秘的过滤器。当我运行代码时,我得到了

Call to cuMemcpyDtoH results in UNKNOWN_CUDA_ERROR

根据其他帖子,这似乎是内存问题?但是由于我没有在 cuda 中编写代码或弄乱内存(我只是添加标签以使其在 GPU 上运行)我不确定解决此问题的最佳方法是什么。我是否将代码转换为错误地在 GPU 上运行?

import numpy as np
import cv2
import sys
import math
import cmath
import tqdm
from numba import jit, cuda, vectorize, guvectorize, float64, int64

sIntesity = 12.0
sSpace = 16.0
diameter = 100

@guvectorize([(float64[:,:], float64[:,:])],  '(n,m)->(n,m)',target='cuda',nopython =True)
def apply_filter(img, filteredImage):

    #imh, imw = img.shape[:2]
    imh = 600
    imw = 600
    hd = int((diameter - 1) / 2)

    for h in range(hd, imh - hd):
        for w in range(hd, imw - hd):
            Wp = 0
            filteredPixel = 0
            radius = diameter // 2
            for x in range(0, diameter):
                for y in range(0, diameter):

                    currentX = w - (radius - x)
                    cureentY = h - (radius - y)

                    intensityDifferent = img[currentX][cureentY] - img[w][h]
                    intensity = (1.0/ (2 * math.pi * (sIntesity ** 2))* math.exp(-(intensityDifferent ** 2) / (2 * sIntesity ** 2)))
                    foo = (currentX - w) ** 2 + (cureentY - h) ** 2
                    distance = cmath.sqrt(foo)
                    smoothing = (1.0 / (2 * math.pi * (sSpace ** 2))) * math.exp( -(distance.real ** 2) / (2 * sSpace ** 2))
                    weight = intensity * smoothing
                    filteredPixel += img[currentX][cureentY] * weight
                    Wp += weight

            filteredImage[h][w] = int(round(filteredPixel / Wp))


if __name__ == "__main__":
    src = cv2.imread("messy2.png", cv2.IMREAD_GRAYSCALE)
    src = src.astype(float)
    filtered_image_own = np.zeros(src.shape)
    print(type(src),type(filtered_image_own))
    apply_filter(src, filtered_image_own)
    filtered_image_own = filtered_image_own.astype(np.uint8) 
    cv2.imwrite("filtered_image4.png", filtered_image_own)

【问题讨论】:

  • 如果你能包含一个最小的、完整的例子,会更容易提供帮助。看起来您可以在不使用 openCV 并显示示例数据数组的情况下创建示例。
  • 以某种方式摆脱 cv2 摆脱了问题?但是它运行得太慢了,而且当时不在 GPU 上。我不知道这怎么可能

标签: python gpu numba


【解决方案1】:

将它从 CUDA 切换到 cpu 让我看到代码中存在错误并且它试图获取无效索引,该错误正是它告诉我有问题的方式

【讨论】:

  • 澄清一下,用@guvectorize切换到CPU意味着@guvectorize([(float64[:,:], float64[:,:])], '(n,m)->(n,m)',target='cpu',nopython =True)而不是...,target='cuda'
  • 如果您使用 cuda.jit 而不是 guvectorize,则可以使用 Numba 的 CUDA Simulator 通过 import os; os.environ["NUMBA_ENABLE_CUDASIM"] = "1"; os.environ["NUMBA_CUDA_DEBUGINFO"] = "1"; 执行简单的交换 preceding from numba import ... 语句.完成调试后将两者交换回"0"。有关如何在 Spyder 中使用 pdb 执行此操作的教程,请参阅 68859699/13697228
猜你喜欢
  • 2021-02-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-06-07
  • 1970-01-01
  • 2016-05-22
  • 2022-01-17
相关资源
最近更新 更多