help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Writing GPU Array Type: Which Array Class to Inherit From?


From: David Bateman
Subject: Re: Writing GPU Array Type: Which Array Class to Inherit From?
Date: Thu, 09 Jul 2009 21:32:39 +0200
User-agent: Mozilla-Thunderbird 2.0.0.19 (X11/20090103)

cjbattagl wrote:
David Bateman-2 wrote:
Wouldn't it be better to inherit from octave_matrix and store a copy of the matrix in the original octave_matrix::matrix value and the version in GPU memory in the new class and synchronize the two values as needed.. You won't inherit the operators at the octave prompt if you inherit directly for a liboctave class.


I'm now inheriting from octave_float_matrix, which was a good start:.. the
class allocates CPU and GPU memory, prints it out on request by reading the
GPU vectors, and can assign the data to other types of Matrices:

GPUArray (FloatMatrix A) : octave_float_matrix(A) { ... }

It looks like I need to overload every single operator, though... I get the
following behavior for every operator:

A=single(rand(4)); G=NewGPUArray(A);
G = G + 1;
gives:  error: T& Array<T>::checkelem (5, -1): range error

I haven't changed modified any important functions of FloatArray in
GPUArray, so I suspect the fix should be easy for now.
In examples I see use of the macros INSTALL_BINOP and CAST_BINOP_ARGS...
would these provide a quick and dirty way for me to make GPUArray act
exactly like FloatMatrix? (I would like GPUArray to act like a normal
FloatArray at first, while I go through and add GPU functionality to each
function)..

If not, I will probably end up using the new @-classes in Octave to
implement all of the functions/operators; it just seems like it wouldn't be
as fast, though.

Thanks for your help! Casey

As long as you don't might the operators that are overloaded returning float matrices, then adding the numerical conversion function from your GPU type to the float matrix like

octave_base_value::type_conv_info
GPUArray::numeric_conversion_function (void) const
 {
return octave_base_value::type_conv_info (default_numeric_conversion_function, octave_float_matrix::static_type_id ());
 }

will be enough. Look at the triangular matrix type on octave-forge for an example of overloading in this manner

http://octave.svn.sourceforge.net/viewvc/octave/trunk/octave-forge/extra/triangular/

D.






--
David Bateman                                address@hidden
35 rue Gambetta                              +33 1 46 04 02 18 (Home)
92100 Boulogne-Billancourt FRANCE            +33 6 72 01 06 33 (Mob)



reply via email to

[Prev in Thread] Current Thread [Next in Thread]