PyCuda Error in Execution

2024/9/21 5:40:54

This is my pycuda code for rotation.I have installed the latest cuda drivers and I use a nvidia gpu with cuda support.I have also installed the cuda toolkit and pycuda drivers.Still I get this strange error.

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. *pia = 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] +1gridy = new_image_dim[1]/blocks[1] if \new_image_dim[1]%blocks[1]==0 else new_image_dim[1]/blocks[1] +1output = 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 outputif __name__ == '__main__':import Imageimport sysdef 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()

This is my error.

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

Please help me fix this.

Answer

Did you google the error before asking here?Anyways try this BoostInstallationHowto#LD_LIBRARY_PATH.Please google before you ask here.Hope this helps you.

https://en.xdnf.cn/q/119985.html

Related Q&A

Python code to Download Specific JSON key value data through REST API calls

I am trying to write a code in python which download only specific key value in the Calls. So the solution might beDownloading the Raw data and later removing the unwanted through regex or 2)Applying s…

How to measure pairwise distances between two sets of points?

I have two datasets (csv files). Both of them contains latitudes-longitudes of two sets (220 and 4400) of points. Now I want to measure pairwise distances (miles) between these two sets of points (220 …

Interactively Re-color Bars in Matplotlib Bar Chart using Confidence Intervals

Trying to shade the bars in this chart based on the confidence that a selected y-value (represented by the red line) lies within a confidence interval. See recolorBars() method in the class example bel…

Unlock password protected Workbook using VBA or Python

I have a workbook name m.xlsx, but its password protected and Ive forgotten the password. How can I open it or un-protect it?The following code does not work:Unprotect workbook without password I need…

How do I make a variable detect if it is greater than or less than another one?

I am currently learning Python, and I decided to build a small "Guess the Number" type of game. I am using the random feature, and trying to make it so it will detect if the users input is eq…

Python Regular Expression from File

I want to extract lines following some sequence from a file. E.g. a file contains many lines and I want line in sequencejourney (a,b) from station south chennai to station punjab chandigarh journey (c,…

Changing the words keeping its meaning intact [closed]

Its difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying thi…

How to create index for a SQLite3 database using SQLAlchemy?

I have multiple SQLite3 databases for which the models are not available. def index_db(name, tempdb):print(f{name.ljust(padding)} Indexing file: {tempdb})if tempdb.endswith(primary.sqlite):conn = sqlit…

Implementing ast.literal_eval on a numpy array

With the following expression, you can convert a string to a python dict.>>> import ast >>> a = ast.literal_eval("{muffin : lolz, foo : kitty}") >>> a {muffin: lolz…

Best way to make argument parser accept absolute number and percentage?

I am trying to write a Nagios style check to use with Nagios. I have working script that takes in something like -w 15 -c 10 and interprets that as "Warning at 15%, Critical at 10%". But I ju…