[ADMB Users] A nontrivial cuda example
dave fournier
davef at otter-rsch.com
Wed Sep 14 15:42:05 PDT 2011
On 11-09-14 01:52 PM, CHRIS GRANDIN wrote:
It is not so bad to work in C. For example for the df12variable
suppose you have
struct df12variable a,b;
and the product u=a*b
you can replace this with the prod fucntion below and write
u=prod(a,b);
It would be nice if the function could be inlined.
struct df12variable
{
double v[3]; // v[0] holds value,
//v[1] holds derivative wrt first variable
//v[2] holds derivative wrt second variable
};
struct df12variable prod( struct df12variable * a, struct
df12variable *b)
{
struct df12variable c;
c.v[1]=a->v[0]*b->v[1] + a->v[1]*b->v[0];
c.v[2]=a->v[0]*b->v[2] + a->v[2]*b->v[0];
c.v[0]=a->v[0]*b->v[0];
return c;
}
> Thank you very much Dave, I will work to convert this to opencl, as I
> already have the opencl library included into the admb source build
> steps it shouldn't be too big a deal. I knew we needed to change the
> operator overloading to structs but figured it was too much work, i.e.
> rewriting all the overloads in admb... I was kinda hoping opencl would
> come out with a C++-friendly library..
> Chris
>
> ----- Original Message -----
> From: dave fournier <davef at otter-rsch.com>
> Date: Wednesday, September 14, 2011 1:13 pm
> Subject: A nontrivial cuda example
> To: CHRIS GRANDIN <cgrandin at shaw.ca>
> Cc: users at admb-project.org
>
> > As Chris anticipated (ruining my surprise) I figured out that
> > difficulty in understanding
> > derivative stuff might be holding up some of the parallel
> > processing so I
> > took a few hours to write an example of GPU processing within ADMB.
> >
> > Here is a vectorized log_negative binomial density
> > example. It is a rather silly
> > negative binomial regression, but it does call the
> > log_negative_binomial density function
> > a lot of times. I has to do forward AD for functions of
> > one or two variables in C
> > rather than C++
> > which means you put in the AD code rather than overloading the
> > operators.
> > It runs on the GPU or CPU depending on whether you enter 1 or 2
> > when prompted.
> >
> > The example shows how to calculate the derivatives and how to
> > make sure they are correct.
> >
> > I hope we can all build on this to clean up the GPU interface
> > and move it to opencl.
> > the current version is cuda.
> >
> > In order to build the example I used the makefile from the cuda
> > sdk examples
> > modified to include the admb stuff. The cpp file was
> > renamed to a cu file
> > 'cause cuda seems to like that.
> >
> > It should run a lot faster on Chris's fancy government thing.
> >
> > Have fun,
> >
> > Dave
> >
More information about the Users
mailing list