Re: [PyCUDA] Sharing is caring
Sharing demo code sounds like a good way to build up the examples directory and ease the learning curve for us newbies... On 30 January 2010 20:09, Jason M jaybo...@yahoo.com wrote: Hey PyCUDA folks, Is there someplace where we can share our code? Should we make some place? Does anyone want some place? I'm attaching some self-organizing map code I messed with. It makes a pretty picture ;) ___ PyCUDA mailing list pyc...@host304.hostmonster.com http://host304.hostmonster.com/mailman/listinfo/pycuda_tiker.net -- Ian Ozsvald (Professional Screencaster) i...@procasts.co.uk http://ProCasts.co.uk/examples.html http://TheScreencastingHandbook.com http://IanOzsvald.com + http://ShowMeDo.com http://twitter.com/ianozsvald ___ PyCUDA mailing list pyc...@host304.hostmonster.com http://host304.hostmonster.com/mailman/listinfo/pycuda_tiker.net
Re: [PyCUDA] Sharing is caring
Perhaps, similar to the showcase on the wiki, we could add an examples page: http://wiki.tiker.net/PyCuda/ShowCase Andreas, what do you think? P At Sun, 31 Jan 2010 09:41:38 +, Ian Ozsvald wrote: [1 multipart/alternative (7bit)] [1.1 text/plain; ISO-8859-1 (7bit)] [1.2 text/html; ISO-8859-1 (quoted-printable)] Sharing demo code sounds like a good way to build up the examples directory and ease the learning curve for us newbies... On 30 January 2010 20:09, Jason M jaybo...@yahoo.com wrote: Hey PyCUDA folks, Is there someplace where we can share our code? Should we make some place? Does anyone want some place? I'm attaching some self-organizing map code I messed with. It makes a pretty picture ;) ___ PyCUDA mailing list pyc...@host304.hostmonster.com http://host304.hostmonster.com/mailman/listinfo/pycuda_tiker.net -- Ian Ozsvald (Professional Screencaster) i...@procasts.co.uk http://ProCasts.co.uk/examples.html http://TheScreencastingHandbook.com http://IanOzsvald.com + http://ShowMeDo.com http://twitter.com/ianozsvald [2 text/plain; us-ascii (7bit)] ___ PyCUDA mailing list pyc...@host304.hostmonster.com http://host304.hostmonster.com/mailman/listinfo/pycuda_tiker.net ___ PyCUDA mailing list pyc...@host304.hostmonster.com http://host304.hostmonster.com/mailman/listinfo/pycuda_tiker.net
Re: [PyCUDA] Sharing is caring
As another newbie (and also python newbie), I find example/demo code extremely helpful. I want to thank Michael Rule, on this list, for sending me some statistics code to speed up a huge number of correlations. Now I have to just figure out how it works ;-) On Sun, 2010-01-31 at 07:26 -0500, Per B. Sederberg wrote: Perhaps, similar to the showcase on the wiki, we could add an examples page: http://wiki.tiker.net/PyCuda/ShowCase Andreas, what do you think? P At Sun, 31 Jan 2010 09:41:38 +, Ian Ozsvald wrote: [1 multipart/alternative (7bit)] [1.1 text/plain; ISO-8859-1 (7bit)] [1.2 text/html; ISO-8859-1 (quoted-printable)] Sharing demo code sounds like a good way to build up the examples directory and ease the learning curve for us newbies... On 30 January 2010 20:09, Jason M jaybo...@yahoo.com wrote: Hey PyCUDA folks, Is there someplace where we can share our code? Should we make some place? Does anyone want some place? I'm attaching some self-organizing map code I messed with. It makes a pretty picture ;) ___ PyCUDA mailing list pyc...@host304.hostmonster.com http://host304.hostmonster.com/mailman/listinfo/pycuda_tiker.net -- Ian Ozsvald (Professional Screencaster) i...@procasts.co.uk http://ProCasts.co.uk/examples.html http://TheScreencastingHandbook.com http://IanOzsvald.com + http://ShowMeDo.com http://twitter.com/ianozsvald [2 text/plain; us-ascii (7bit)] ___ PyCUDA mailing list pyc...@host304.hostmonster.com http://host304.hostmonster.com/mailman/listinfo/pycuda_tiker.net ___ PyCUDA mailing list pyc...@host304.hostmonster.com http://host304.hostmonster.com/mailman/listinfo/pycuda_tiker.net ___ PyCUDA mailing list pyc...@host304.hostmonster.com http://host304.hostmonster.com/mailman/listinfo/pycuda_tiker.net
Re: [PyCUDA] Sharing is caring
On Sonntag 31 Januar 2010, Per B. Sederberg wrote: Perhaps, similar to the showcase on the wiki, we could add an examples page: http://wiki.tiker.net/PyCuda/ShowCase Andreas, what do you think? Good idea. See http://wiki.tiker.net/PyCuda/Examples The examples/ subdirectory now has a link to that web page and only contains the most basic examples to get people started. In addition, the examples directory now also contains a script that automatically downloads all the Wiki examples to keep them as easily runnable as before. Thanks for the suggestion! Andreas signature.asc Description: This is a digitally signed message part. ___ PyCUDA mailing list pyc...@host304.hostmonster.com http://host304.hostmonster.com/mailman/listinfo/pycuda_tiker.net
Re: [PyCUDA] Sharing is caring
That looks like a mighty fine solution - syntax colouring too :-) I'll add some beginner-steps tutorials when I'm next back on this project. Cheers, Ian. On 31 January 2010 17:24, Andreas Klöckner li...@informa.tiker.net wrote: On Sonntag 31 Januar 2010, Per B. Sederberg wrote: Perhaps, similar to the showcase on the wiki, we could add an examples page: http://wiki.tiker.net/PyCuda/ShowCase Andreas, what do you think? Good idea. See http://wiki.tiker.net/PyCuda/Examples The examples/ subdirectory now has a link to that web page and only contains the most basic examples to get people started. In addition, the examples directory now also contains a script that automatically downloads all the Wiki examples to keep them as easily runnable as before. Thanks for the suggestion! Andreas -- Ian Ozsvald (Professional Screencaster) i...@procasts.co.uk http://ProCasts.co.uk/examples.html http://TheScreencastingHandbook.com http://IanOzsvald.com + http://ShowMeDo.com http://twitter.com/ianozsvald ___ PyCUDA mailing list pyc...@host304.hostmonster.com http://host304.hostmonster.com/mailman/listinfo/pycuda_tiker.net
[PyCUDA] Sharing is caring
Hey PyCUDA folks, Is there someplace where we can share our code? Should we make some place? Does anyone want some place? I'm attaching some self-organizing map code I messed with. It makes a pretty picture ;) from __future__ import division ## Self-organizing map using PyCUDA (0.94beta) http://mathema.tician.de/software/pycuda ## Jason Madsen (jaybob20 (at) yahoo..com) ## January 30, 2010 ## ## Based on code found at: ## http://paraschopra.com/sourcecode/SOM/index.php ## This code is licensed and released under the GNU GPL from math import * import sys import pycuda.autoinit import pycuda.gpuarray as gpuarray import numpy from pycuda.curandom import rand as curand from pycuda.elementwise import ElementwiseKernel from pycuda.compiler import SourceModule class SOM: def __init__(self, height=10, width=10, FV_size=10, learning_rate=0.005): self.height = height self.width = width self.size = height * width self.FV_size = FV_size self.radius = (height+width)/3 self.learning_rate = learning_rate self.nodes = numpy.array([[ [0 for i in range(FV_size)] for x in range(width)] for y in range(height)],dtype=numpy.float32) self.distances=numpy.zeros(self.size,dtype='float32') self.ctemp_dist=gpuarray.empty(self.size, dtype='float32') self.cnodes=curand((self.size*self.FV_size,),dtype=numpy.float32)*255 temp_arguments=float *d,float *r,float *fv temp_function=d[i]=sqrt(++.join([pow(r[i++str(x*self.size)+]-fv[+str(x)+],2) for x in xrange(self.FV_size)])+) self.distance_calc=ElementwiseKernel(temp_arguments,temp_function,distance_calc) self.inf_lrd_calc=ElementwiseKernel(float *in,float *out,float raddiv,float ratedecay, out[i]=exp((-1.0*pow(in[i],2))/raddiv)*ratedecay, inf_lrd_calc) self.learn_calc=ElementwiseKernel(float *nodes,float *inflrd,float *TV, nodes[i]=nodes[i]+(inflrd[i%+str(self.size)+]*(TV[i/+str(self.size)+]-nodes[i])), learn_calc) mod = SourceModule(__global__ void make_distances_n_inf_lrd(float *d, int pnt, float dist,float raddiv,float ratedecay) { int idx = threadIdx.x + blockIdx.x*blockDim.x; float my_d; my_d = sqrtf(powf((idx/%d - pnt/%d),2)+powf((idx%%%d - pnt%%%d),2)); if (my_d dist) { d[idx]=exp((-1.0*pow(my_d,2))/raddiv)*ratedecay; } else { d[idx]=0.f; } } %(self.width,self.width,self.width,self.width)) self.dist_neighborhood = mod.get_function(make_distances_n_inf_lrd) # train_vector: [ FV0, FV1, FV2, ...] - [ [...], [...], [...], ...] # train vector may be a list, will be converted to a list of numpy arrays def train(self, iterations=1000, train_vector=[[]]): train_vector = [numpy.array(t,dtype='float32') for t in train_vector] gpu_train_vector = [gpuarray.to_gpu(t) for t in train_vector] time_constant = iterations/log(self.radius) for i in range(1, iterations+1): radius_decaying=self.radius*exp(-1.0*i/time_constant) rad_div_val = 2 * radius_decaying * i learning_rate_decaying=self.learning_rate*exp(-1.0*i/time_constant) sys.stdout.write(\rTraining Iteration: + str(i) + / + str(iterations)) for j in gpu_train_vector: best = self.best_match2(j) self.dist_neighborhood(self.ctemp_dist, numpy.uint32(best), numpy.float32(radius_decaying), numpy.float32(rad_div_val), numpy.float32(learning_rate_decaying) ,block=(self.width,1,1),grid=(self.height,1)) self.learn_calc(self.cnodes,self.ctemp_dist,j) sys.stdout.write(\n) self.nodes=self.cnodes.get().reshape(self.FV_size,self.height,self.width).transpose(1,2,0) # Returns location of best match, uses Euclidean distance # target_FV is a numpy array def best_match(self, target_FV): self.distance_calc(self.ctemp_dist, self.cnodes, target_FV) loc = numpy.argmin(self.ctemp_dist.get()) return (loc//self.width, loc%self.width) def best_match2(self, target_FV): self.distance_calc(self.ctemp_dist, self.cnodes, target_FV) loc = numpy.argmin(self.ctemp_dist.get()) return (loc) # returns the Euclidean distance between two Feature Vectors # FV_1, FV_2 are numpy arrays def FV_distance(self, FV_1, FV_2): return (sum((FV_1 - FV_2)**2))**0.5 if __name__ == __main__: print Initialization... colors = [ [0, 0, 0], [0, 0, 255], [0, 255, 0], [0, 255, 255], [255, 0, 0], [255, 0, 255], [255, 255, 0], [255, 255, 255]] width = 64 height = 64