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

PyCuda/Examples/Manhattan_Distance_For_2D_Array (last edited 2013-09-05 03:40:32 by 99-121-203-69)