Concise Name for your example

Please briefly describe your example here.

If you like, you may put your contact info here.

License of this example:

Sugeerth Murugesan sugeerth@gmail.com

Date:

September 4th

PyCUDA version:

   1 import numpy
   2 import pycuda.autoinit
   3 import pycuda.driver as cuda
   4 
   5 from pycuda.compiler import SourceModule
   6 
   7 w = 7
   8 
   9 mod = SourceModule("""
  10         #include<math.h>
  11         __global__ void diffusion(  int* result,int width, int height,float x,float y,float z) {
  12 
  13             int xIndex = blockDim.x * blockIdx.x + threadIdx.x;
  14             int yIndex = blockDim.y * blockIdx.y + threadIdx.y;
  15 
  16             int flatIndex = xIndex + width * yIndex;
  17             int topIndex = xIndex + width * (yIndex - 1);
  18             int bottomIndex = xIndex + width * (yIndex + 1);
  19 
  20             int inc = 1;
  21 
  22             result[flatIndex] = (result[flatIndex]-x)+(result[flatIndex]-y)+(result[flatIndex]-z);
  23         }
  24 
  25         """)
  26 
  27 diff_func   = mod.get_function("diffusion")
  28 
  29 
  30 def diffusion(res):
  31 
  32     x = numpy.float32(2)
  33     y = numpy.float32(1)
  34     z = numpy.float32(1)
  35 
  36 
  37     height, width = numpy.int32(len(res)), numpy.int32(len(res[0]))
  38 
  39     diff_func(
  40         cuda.InOut(res),
  41         width,
  42         height,x,y,z,
  43         block=(w,w,1)
  44         )
  45 
  46 def run(res, step):
  47 
  48     diffusion(res)
  49     print res
  50 
  51 res   = numpy.array([[0 \
  52                         for _ in xrange(0, w)]\
  53                         for _ in xrange(0, w)], dtype='int32')
  54 print res
  55 run(res, 0)

PyCuda/Examples/Manhattan_Distance_For_2D_Array (last edited 2014-12-15 22:29:21 by ::ffff:205)