I am returning with this discussion to the mailing list.

Dnia 2009-10-11, nie o godzinie 10:43 +1100, Frank Burden pisze:
> Thanks Thomas
> 
> I used git to download v0.94 but find that the dot product is 
> incorrectly programmed.

According to PyCUDA documentation
http://documen.tician.de/pycuda/array.html#pycuda.gpuarray.dot
dot is reduction operation. It treats both arguments as 1D arrays
and returns sum of element-wise multiplications.

At the same time __mul__ (i.e. a*b) does not offer full matrix
multiplication but also element-wise one - but at least it saves
original matrix shape.

ElementWise kernel will not be useful here, as it only works
on 1D arrays. Of course one could play with preambles, but IMO
it will be easier to just write own function, especially as
I find loop generated in pycuda.elementwise.get_elwise_module
rather strange.

The easiest thing for now will be for you to write kernel to
multiply those two matrices.

But IMO you pointed important thing - if PyCUDA is to be
compatible with numpy, having similar behaviour for functions
having the same names is important.


> 
> A dot product of x and y should be z[i,j] = sum over k of x[i,k]*[y[k,j]
> 
> I've appended my (inelegant) code and the result using simple matrices 
> so that the result is obvious.
> 
> CODE:
> import pycuda.gpuarray as gpuarray
> import pycuda.driver as cuda
> import pycuda.autoinit
> import numpy
> import time
> 
> n=4
> a=numpy.float32(numpy.random.randn(n,n))
> b=numpy.float32(numpy.random.randn(n,n))
> for i in range(n):
>     for j in range(n):
>         a[i,j] = i+j
>         b[i,j] = i+j
>        
> tic=time.time()
> axb=a*b
> print a
> print
> print b
> print
> print numpy.dot(a,b)
> toc=time.time()-tic
> print toc,"CPU"
> 
> 
> tic=time.time()
> a_gpu = gpuarray.to_gpu(a)
> b_gpu = gpuarray.to_gpu(b)
> axbGPU = gpuarray.dot(a_gpu,b_gpu)
> 
> print
> print axbGPU
> toc=time.time()-tic
> print toc,"GPU"
> ======================
> RESULT:
> [[ 0.  1.  2.  3.]
>  [ 1.  2.  3.  4.]
>  [ 2.  3.  4.  5.]
>  [ 3.  4.  5.  6.]]
> 
> [[ 0.  1.  2.  3.]
>  [ 1.  2.  3.  4.]
>  [ 2.  3.  4.  5.]
>  [ 3.  4.  5.  6.]]
> 
> [[ 14.  20.  26.  32.]
>  [ 20.  30.  40.  50.]
>  [ 26.  40.  54.  68.]
>  [ 32.  50.  68.  86.]]
> 0.0 CPU
> 
> 184.0
> 0.203000068665 GPU
> 
> I'm a scientist/programmer working on stem cell microarrays, drug design 
> etc and need to speed up our calculations by an order of magnitude or 
> two without learning all the ins and outs of CUDA.
> 
> Hope you can help.
> 
> Regards
> 
> Frank
> ========================
> You can see that the GPU result is the sum of the first row (or column) 
> of the numpy.dot product.
> > Dnia 2009-10-10, sob o godzinie 10:58 +1100, Frank Burden pisze:
> >   
> >> Thanks but the link 
> >> http://git.tiker.net/trees/pycuda.git is broken.
> >>
> >>     
> >
> > This is not link to be put into browser window.
> > This is URL of the git repository:
> > http://en.wikipedia.org/wiki/Git_(software)
> >
> > When you install the git client, you can always get
> > the latest version of PyCUDA source by
> > git clone http://git.tiker.net/trees/pycuda.git
> >
> > Basically you need to install git client to get
> > source code from the URL I have given to you.
> >
> > Regards.
> >
> >   
> 



-- 
Tomasz Rybak <[email protected]> GPG key ID: F22C D870
Fingerprint 93BC FEEC A426 3765 799F  10EE FAC1 9A2C F22C D870
http://member.acm.org/~tomaszrybak

Attachment: signature.asc
Description: To jest część wiadomości podpisana cyfrowo

_______________________________________________
PyCUDA mailing list
[email protected]
http://tiker.net/mailman/listinfo/pycuda_tiker.net

Reply via email to