[PyCuda] Odd results from PyCUDA port of options pricing example

2009-04-29 Thread Raefer Gabriel
Hi all,

I am trying to port the binomial options example from the CUDA SDK to pyCuda
as a learning  exercise primarily, and I seem to be getting incorrect
results and am having trouble tracking down the problem.  I am new to CUDA
and pyCuda.

Source code is here (no external dependencies other than pycuda - I'm
running Python 2.6 here on Ubuntu 9.04, and CUDA and pyCuda pass all
included tests as working fine):
http://www.alaricuscapital.com/pycuda-binomial.txt

I know that the basic logic in the kernel is correct, since it is copied
from the binomialOptions example in the SDK.  However, I had to make a few
minor tweaks to it - namely, instead of using static arrays, I am passing in
the options input data as array arguments to the kernel, and I copied in
some #defines from the header to make it compile smoothly.

I have verified that this data I'm trying to pass is being received properly
in the kernel, by changing the kernel's return values to match each of the
input variables - so I am at least getting data to the function!

And I verified my comparison function binomialOptionFromProcessed against
a known-good implementation of European Call binomial option pricing from
the pyFinancials library - they produce identical results for the same
number of steps, so I know I didn't munge that up.

However, they are clearly not producing consistent results.

So the two possibilities seem to be that I'm doing something wrong in the
pyCuda portion of my code that is mucking up my data down at the bottom of
the binomialOptionsGPU function, or that in tweaking the kernel from the SDK
I have broken something in the kernel (either because I replaced the static
arrays, or something else).

I was hoping for some guidance on this, at least to help me rule out stupid
mistakes with how I am invoking pyCUDA so I can better focus my debugging
efforts.

Thanks in advance for any help!

Raefer Gabriel




___
PyCuda mailing list
PyCuda@tiker.net
http://tiker.net/mailman/listinfo/pycuda_tiker.net


Re: [PyCuda] Odd results from PyCUDA port of options pricing example

2009-04-29 Thread Andreas Klöckner
I see one potential issue:

  b_gpu = cuda.mem_alloc(len(h_OptionData))

You probably mean len(h_OptionData)*numpy.dtype(numpy.float32).itemsize,
which is a long way of saying len(h_OptionData)*4.

Word of advice: Use gpuarrays. Less foot-shooting potential.

Andreas

On Mittwoch 29 April 2009, Raefer Gabriel wrote:
 Hi all,

 I am trying to port the binomial options example from the CUDA SDK to
 pyCuda as a learning  exercise primarily, and I seem to be getting
 incorrect results and am having trouble tracking down the problem.  I am
 new to CUDA and pyCuda.

 Source code is here (no external dependencies other than pycuda - I'm
 running Python 2.6 here on Ubuntu 9.04, and CUDA and pyCuda pass all
 included tests as working fine):
 http://www.alaricuscapital.com/pycuda-binomial.txt

 I know that the basic logic in the kernel is correct, since it is copied
 from the binomialOptions example in the SDK.  However, I had to make a few
 minor tweaks to it - namely, instead of using static arrays, I am passing
 in the options input data as array arguments to the kernel, and I copied in
 some #defines from the header to make it compile smoothly.

 I have verified that this data I'm trying to pass is being received
 properly in the kernel, by changing the kernel's return values to match
 each of the input variables - so I am at least getting data to the
 function!

 And I verified my comparison function binomialOptionFromProcessed against
 a known-good implementation of European Call binomial option pricing from
 the pyFinancials library - they produce identical results for the same
 number of steps, so I know I didn't munge that up.

 However, they are clearly not producing consistent results.

 So the two possibilities seem to be that I'm doing something wrong in the
 pyCuda portion of my code that is mucking up my data down at the bottom of
 the binomialOptionsGPU function, or that in tweaking the kernel from the
 SDK I have broken something in the kernel (either because I replaced the
 static arrays, or something else).

 I was hoping for some guidance on this, at least to help me rule out stupid
 mistakes with how I am invoking pyCUDA so I can better focus my debugging
 efforts.

 Thanks in advance for any help!

 Raefer Gabriel




 ___
 PyCuda mailing list
 PyCuda@tiker.net
 http://tiker.net/mailman/listinfo/pycuda_tiker.net




signature.asc
Description: This is a digitally signed message part.
___
PyCuda mailing list
PyCuda@tiker.net
http://tiker.net/mailman/listinfo/pycuda_tiker.net