【问题标题】:PyCuda Error in ExecutionPyCuda 执行错误
【发布时间】:2012-09-01 16:11:41
【问题描述】:

这是我用于旋转的 pycuda 代码。我已经安装了最新的 cuda 驱动程序,并使用了支持 cuda 的 nvidia gpu。我还安装了 cuda 工具包和 pycuda 驱动程序。但我仍然收到这个奇怪的错误。

import pycuda.driver as cuda
import pycuda.compiler
import pycuda.autoinit
import numpy
from math import pi,cos,sin

_rotation_kernel_source = """
texture<float, 2> tex;

__global__ void copy_texture_kernel(
    const float resize_val, 
    const float alpha, 
    unsigned short oldiw, unsigned short oldih,
    unsigned short newiw, unsigned short newih,
    unsigned char* data) {

        unsigned int x = blockIdx.x * blockDim.x + threadIdx.x;
        unsigned int y = blockIdx.y * blockDim.y + threadIdx.y;

        if( (x >= newiw) || (y >= newih) )
            return;

        unsigned int didx = y * newiw + x;

        float xmiddle = (x-newiw/2.) / resize_val;
        float ymiddle = (y-newih/2.) / resize_val;
        float sx = ( xmiddle*cos(alpha)+ymiddle*sin(alpha) + oldiw/2.) ;
        float sy = ( -xmiddle*sin(alpha)+ymiddle*cos(alpha) + oldih/2.);

        if( (sx < 0) || (sx >= oldiw) || (sy < 0) || (sy >= oldih) ) { 
            data[didx] = 255; 
            return;
        }

        data[didx] = tex2D(tex, sx, sy);
    }
"""
mod_copy_texture=pycuda.compiler.SourceModule( _rotation_kernel_source )

copy_texture_func = mod_copy_texture.get_function("copy_texture_kernel")
texref = mod_copy_texture.get_texref("tex")

def rotate_image( a, resize = 1.5, angle = 20., interpolation = "linear", blocks = (16,16,1)  ):


    angle = angle/180. *pi


    a = a.astype("float32")

    calc_x = lambda (x,y): (x*a.shape[1]/2.*cos(angle)-y*a.shape[0]/2.*sin(angle))
    calc_y = lambda (x,y): (x*a.shape[1]/2.*sin(angle)+y*a.shape[0]/2.*cos(angle))

    xs = [ calc_x(p) for p in [ (-1.,-1.),(1.,-1.),(1.,1.),(-1.,1.) ] ]
    ys = [ calc_y(p) for p in [ (-1.,-1.),(1.,-1.),(1.,1.),(-1.,1.) ] ]

    new_image_dim = (
        int(numpy.ceil(max(ys)-min(ys))*resize),
        int(numpy.ceil(max(xs)-min(xs))*resize),
    )


    cuda.matrix_to_texref(a, texref, order="C")


    if interpolation == "linear":
        texref.set_filter_mode(cuda.filter_mode.LINEAR)


    gridx = new_image_dim[0]/blocks[0] if \
            new_image_dim[0]%blocks[0]==1 else new_image_dim[0]/blocks[0] +1
    gridy = new_image_dim[1]/blocks[1] if \
            new_image_dim[1]%blocks[1]==0 else new_image_dim[1]/blocks[1] +1

    output = numpy.zeros(new_image_dim,dtype="uint8")

    copy_texture_func(
        numpy.float32(resize), numpy.float32(angle),
        numpy.uint16(a.shape[1]), numpy.uint16(a.shape[0]),
        numpy.uint16(new_image_dim[1]), numpy.uint16(new_image_dim[0]),
            cuda.Out(output),texrefs=[texref],block=blocks,grid=(gridx,gridy))

    return output

if __name__ == '__main__':
    import Image
    import sys

    def main( ):
        if len(sys.argv) != 2:
            print "You should really read the source...\n\nUsage: rotate.py <Imagename>\n"
            sys.exit(-1)

        img = Image.open(sys.argv[1]).convert("L")
        i = numpy.fromstring(img.tostring(),dtype="uint8").reshape(img.size[1],img.size[0])

        irot = rotate_image(i)
        rotimg = Image.fromarray(irot,mode="L")

        rotimg.save("rotated.png")
        rotimg.show()

    main()

这是我的错误。

ImportError: libboost_python-gcc43-mt-1_39.so.1.39.0: cannot open
    shared object file: No such file or directory

请帮我解决这个问题。

【问题讨论】:

  • 这是一个非常不言自明的错误。要么你没有安装 boost.python,要么它不在运行的 python 实例可以找到的地方。

标签: python cuda pycuda


【解决方案1】:

你在这里问之前用谷歌搜索了错误吗?无论如何试试这个BoostInstallationHowto#LD_LIBRARY_PATH。在你问这里之前请谷歌。希望这对你有帮助。

【讨论】:

  • 你提到的这个链接,不存在
猜你喜欢
  • 1970-01-01
  • 2015-02-17
  • 1970-01-01
  • 2018-05-13
  • 2013-08-27
  • 2015-08-04
  • 2018-12-04
  • 2011-08-08
  • 1970-01-01
相关资源
最近更新 更多