Hey,

I tested this and it worked great. My test code is attached. Thanks Andreas!

Jesse.

On Mon, Mar 19, 2012 at 12:48 PM, Jesse Lu <[email protected]> wrote:

> Hey Andreas,
>
> I'm sorry I haven't replied to this yet, I'm working on setting up my box
> and have run into some difficulties. I will give this a shot ASAP. Thanks!
>
>
> On Thu, Mar 8, 2012 at 6:40 AM, Andreas Kloeckner <[email protected]
> > wrote:
>
>> <#part sign=pgpmime>
>> On Thu, 16 Feb 2012 14:44:14 -0800, Jesse Lu <[email protected]>
>> wrote:
>> > Hi guys,
>> >
>> > Just wondering if anyone had a chance to resolve this yet...
>>
>> I've committed what I believe is a fix to this issue. Can you please
>> test it?
>>
>> Thanks!
>> Andreas
>>
>
>
import pycuda.autoinit
from pycuda import gpuarray
import numpy
import unittest

class TestPycudaReduce(unittest.TestCase):
    def setUp(self):
        self.shapes = [(10000,), (100000,), (1000000,), (10000000,), \
            (100,100), (1000,1000), \
            (10,20,30), (40,50,60), (200,200,200)]

    def test_dot(self):
        """ Test dot-product. """
        dtypes = [numpy.float32, numpy.float64, numpy.complex64, numpy.complex128]
        for dtype in dtypes:
            for shape in self.shapes:
                x = gpuarray.to_gpu(numpy.random.randn(*shape).astype(dtype))
                y = gpuarray.to_gpu(numpy.random.randn(*shape).astype(dtype))

                dot_cpu = numpy.dot(x.get().flatten(), y.get().flatten()) 
                dot_gpu = gpuarray.dot(x, y).get()

                print 'shape:', shape
                print 'data type:', dtype 
                print 'numpy computed dot product:', dot_cpu
                print 'gpuarray computed dot product:', dot_gpu
                percent_error = abs(dot_cpu-dot_gpu)/abs(dot_cpu)*100
                print 'percent error:', percent_error, '%'
                print '\n'

                self.assertTrue(percent_error < 1.0, 'Error above 1%.')

    def test_sum(self):
        """ Test sum. """
        dtypes = [numpy.float32, numpy.float64, numpy.complex64, numpy.complex128]
        for dtype in dtypes:
            for shape in self.shapes:
                x = gpuarray.to_gpu(numpy.random.randn(*shape).astype(dtype))

                res_cpu = numpy.sum(x.get().flatten())
                res_gpu = gpuarray.sum(x).get()

                print 'shape:', shape
                print 'data type:', dtype 
                print 'numpy computed result:', res_cpu
                print 'gpuarray computed result:', res_gpu
                percent_error = abs(res_cpu-res_gpu)/abs(res_cpu)*100
                print 'percent error:', percent_error, '%'
                print '\n'

                self.assertTrue(percent_error < 1.0, 'Error above 1%.')

if __name__ == '__main__':
    unittest.main()
_______________________________________________
PyCUDA mailing list
[email protected]
http://lists.tiker.net/listinfo/pycuda

Reply via email to