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

Reply via email to