Hi oyster, I have fixed two things in order to make your program runnable: - replaced 'numPoint.x' and 'numPoint.y' with 'numPointX' and 'numPointY', - added 'startTime = time.time()' line before the kernel call
There are the following problems with the code: - The shape of 'iter' is incorrect: you are addressing it as if it was (numPointY, numPointX), but it has the shape (numPointX, numPointY). It is not the cause of the launch failure, but will probably give you incorrect results. - When you calculate 'offset' in the kernel, you are multiplying 'yIdx' by the total width of the grid ('blockDim.x*gridDim.x'), but your array is continuous, so you need to multiply by its actual dimension ('numPointx') instead. After fixing these, your program runs without errors. Best regards, Bogdan On Sat, Dec 7, 2013 at 1:58 AM, oyster <lepto.pyt...@gmail.com> wrote: > Hi, there. Can anyone help me to fix my code, thanks > > I want to draw 2D function picture of F(x, y). The thought behind it > is very simple: to calculate F(x,y) on every pixels(xi, yi), if F(xi, > yi)<=eps, we put this pixel in BLACK color > > In the following is the code: > startCordx and startCordy means the start point to begin search > numPointx and numPointy means how many points that we devided x and y into > divx and divy means the smallest step we used to increase > iter holds our returned array > > however my code says > [quote] > File "e:\prg\py\python-2.7.3\lib\site-packages\pycuda\driver.py", > line 377, in function_call Context.synchronize() > pycuda._driver.LaunchError: cuCtxSynchronize failed: launch failed > PyCUDA WARNING: a clean-up operation failed (dead context maybe?) > cuMemFree failed: launch failed > PyCUDA WARNING: a clean-up operation failed (dead context maybe?) > cuModuleUnload failed: launch failed > [/quote] > > > [python code] > #coding=utf-8 > import PIL.Image as Image > import time > import numpy > import PIL.ImageOps as ImageOps > import pycuda.gpuarray as gpuarray > import pycuda.autoinit > import pycuda.driver as drv > from pycuda.compiler import SourceModule > > eps= 5 > > divX=divY=0.002 > > startCordX, startCordY=-5, -5 > endCordX, endCordY=5, 6 > > numPointX=int((endCordX-startCordX)/divX+1) > numPointY=int((endCordY-startCordY)/divY+1) > > # allocate a numpy array > iter = numpy.ones((numPointX, numPointY)).astype(numpy.uint8)*0xff > > > mod = SourceModule(""" > __global__ void multiply_them( > int startCordx, int startCordy, > unsigned int numPointx, unsigned int numPointy, > float divx, float divy, > unsigned char eps, > unsigned char *iter) > { > > const unsigned int xIdx = threadIdx.x+blockIdx.x*blockDim.x; > const unsigned int yIdx = threadIdx.y+blockIdx.y*blockDim.y; > > unsigned int offset=xIdx+yIdx*blockDim.x*gridDim.x; > > float x=startCordx + xIdx * divx; > float y=startCordy + yIdx * divy; > > if ((xIdx<numPointx)&&(yIdx<numPointy)) > { > if ( > abs((17*x*x-16*abs(x)*y+17*y*y-255))<=eps > ) > { > iter[offset]=0; > } > else > { > iter[offset]=255; > } > } > } > """) > > multiply_them = mod.get_function("multiply_them") > > multiply_them( > numpy.int32(startCordX), numpy.int32(startCordY), > numpy.uint32(numPointX), numpy.uint32(numPointY), > numpy.float32(divX), numpy.float32(divY), > numpy.uint8(eps), > drv.InOut(iter), > grid=((numPoint.x+15)//16,(numPoint.y+15)//16,), > block=(16,16,1) > ) > > endTime=time.time() > print 'Time used: %.2f seconds' % (endTime-startTime) > > img=Image.fromarray(iter, mode='L') > img=ImageOps.flip(img) > > img.show() > [/python code] > > _______________________________________________ > PyCUDA mailing list > PyCUDA@tiker.net > http://lists.tiker.net/listinfo/pycuda _______________________________________________ PyCUDA mailing list PyCUDA@tiker.net http://lists.tiker.net/listinfo/pycuda