Commit bccd1586 authored by Tomáš Oberhuber's avatar Tomáš Oberhuber
Browse files

Implementing CUDA support in matrix fromats.

parent 05c949c3
Loading
Loading
Loading
Loading
+4 −2
Original line number Diff line number Diff line
@@ -418,10 +418,12 @@ ostream& operator << ( ostream& str, const tnlArray< Element, Device, Index >& v

#ifdef TEMPLATE_EXPLICIT_INSTANTIATION

extern template class tnlArray< float, tnlHost, int >;
// TODO: this does not work with CUDA 5.5 - fix it later

/*extern template class tnlArray< float, tnlHost, int >;
extern template class tnlArray< double, tnlHost, int >;
extern template class tnlArray< float, tnlHost, long int >;
extern template class tnlArray< double, tnlHost, long int >;
extern template class tnlArray< double, tnlHost, long int >;*/

#ifdef HAVE_CUDA
/*extern template class tnlArray< float, tnlCuda, int >;
+41 −21
Original line number Diff line number Diff line
@@ -149,6 +149,16 @@ bool tnlCSRMatrix< Real, Device, Index >::operator != ( const tnlCSRMatrix< Real
   return ! ( ( *this ) == matrix );
}

template< typename Real,
          typename Device,
          typename Index >
bool tnlCSRMatrix< Real, Device, Index >::setElementFast( const IndexType row,
                                                          const IndexType column,
                                                          const Real& value )
{
   return this->addElementFast( row, column, value, 0.0 );
}

template< typename Real,
          typename Device,
          typename Index >
@@ -156,13 +166,14 @@ bool tnlCSRMatrix< Real, Device, Index >::setElement( const IndexType row,
                                                      const IndexType column,
                                                      const Real& value )
{
   return this->addElement( row, column, value, 0.0 );
   return this->addElementFast( row, column, value, 0.0 );
}


template< typename Real,
          typename Device,
          typename Index >
bool tnlCSRMatrix< Real, Device, Index >::addElement( const IndexType row,
bool tnlCSRMatrix< Real, Device, Index >::addElementFast( const IndexType row,
                                                          const IndexType column,
                                                          const RealType& value,
                                                          const RealType& thisElementMultiplicator )
@@ -210,7 +221,7 @@ bool tnlCSRMatrix< Real, Device, Index >::addElement( const IndexType row,
template< typename Real,
          typename Device,
          typename Index >
bool tnlCSRMatrix< Real, Device, Index > :: setRow( const IndexType row,
bool tnlCSRMatrix< Real, Device, Index > :: setRowFast( const IndexType row,
                                                        const IndexType* columnIndexes,
                                                        const RealType* values,
                                                        const IndexType elements )
@@ -234,7 +245,7 @@ bool tnlCSRMatrix< Real, Device, Index > :: setRow( const IndexType row,
template< typename Real,
          typename Device,
          typename Index >
bool tnlCSRMatrix< Real, Device, Index > :: addRow( const IndexType row,
bool tnlCSRMatrix< Real, Device, Index > :: addRowFast( const IndexType row,
                                                        const IndexType* columns,
                                                        const RealType* values,
                                                        const IndexType numberOfElements,
@@ -247,7 +258,7 @@ bool tnlCSRMatrix< Real, Device, Index > :: addRow( const IndexType row,
template< typename Real,
          typename Device,
          typename Index >
Real tnlCSRMatrix< Real, Device, Index >::getElement( const IndexType row,
Real tnlCSRMatrix< Real, Device, Index >::getElementFast( const IndexType row,
                                                          const IndexType column ) const
{
   IndexType elementPtr = this->rowPointers[ row ];
@@ -262,7 +273,16 @@ Real tnlCSRMatrix< Real, Device, Index >::getElement( const IndexType row,
template< typename Real,
          typename Device,
          typename Index >
void tnlCSRMatrix< Real, Device, Index >::getRow( const IndexType row,
Real tnlCSRMatrix< Real, Device, Index >::getElement( const IndexType row,
                                                      const IndexType column ) const
{
   return this->getElementFast( row, column );
}

template< typename Real,
          typename Device,
          typename Index >
void tnlCSRMatrix< Real, Device, Index >::getRowFast( const IndexType row,
                                                      IndexType* columns,
                                                      RealType* values ) const
{
+40 −20
Original line number Diff line number Diff line
@@ -296,6 +296,16 @@ bool tnlChunkedEllpackMatrix< Real, Device, Index >::operator != ( const tnlChun
   return ! ( ( *this ) == matrix );
}

template< typename Real,
          typename Device,
          typename Index >
bool tnlChunkedEllpackMatrix< Real, Device, Index >::setElementFast( const IndexType row,
                                                                     const IndexType column,
                                                                     const Real& value )
{
   return this->addElement( row, column, value, 0.0 );
}

template< typename Real,
          typename Device,
          typename Index >
@@ -306,10 +316,11 @@ bool tnlChunkedEllpackMatrix< Real, Device, Index >::setElement( const IndexType
   return this->addElement( row, column, value, 0.0 );
}


template< typename Real,
          typename Device,
          typename Index >
bool tnlChunkedEllpackMatrix< Real, Device, Index >::addElement( const IndexType row,
bool tnlChunkedEllpackMatrix< Real, Device, Index >::addElementFast( const IndexType row,
                                                                     const IndexType column,
                                                                     const RealType& value,
                                                                     const RealType& thisElementMultiplicator )
@@ -366,7 +377,7 @@ bool tnlChunkedEllpackMatrix< Real, Device, Index >::addElement( const IndexType
template< typename Real,
          typename Device,
          typename Index >
bool tnlChunkedEllpackMatrix< Real, Device, Index > :: setRow( const IndexType row,
bool tnlChunkedEllpackMatrix< Real, Device, Index > :: setRowFast( const IndexType row,
                                                                   const IndexType* columnIndexes,
                                                                   const RealType* values,
                                                                   const IndexType elements )
@@ -394,7 +405,7 @@ bool tnlChunkedEllpackMatrix< Real, Device, Index > :: setRow( const IndexType r
template< typename Real,
          typename Device,
          typename Index >
bool tnlChunkedEllpackMatrix< Real, Device, Index > :: addRow( const IndexType row,
bool tnlChunkedEllpackMatrix< Real, Device, Index > :: addRowFast( const IndexType row,
                                                                   const IndexType* columns,
                                                                   const RealType* values,
                                                                   const IndexType numberOfElements,
@@ -407,7 +418,7 @@ bool tnlChunkedEllpackMatrix< Real, Device, Index > :: addRow( const IndexType r
template< typename Real,
          typename Device,
          typename Index >
Real tnlChunkedEllpackMatrix< Real, Device, Index >::getElement( const IndexType row,
Real tnlChunkedEllpackMatrix< Real, Device, Index >::getElementFast( const IndexType row,
                                                                     const IndexType column ) const
{
   const IndexType& sliceIndex = slicesToRowsMapping[ row ];
@@ -427,7 +438,16 @@ Real tnlChunkedEllpackMatrix< Real, Device, Index >::getElement( const IndexType
template< typename Real,
          typename Device,
          typename Index >
void tnlChunkedEllpackMatrix< Real, Device, Index >::getRow( const IndexType row,
Real tnlChunkedEllpackMatrix< Real, Device, Index >::getElement( const IndexType row,
                                                                 const IndexType column ) const
{
   return this->getElementFast( row, column );
}

template< typename Real,
          typename Device,
          typename Index >
void tnlChunkedEllpackMatrix< Real, Device, Index >::getRowFast( const IndexType row,
                                                                 IndexType* columns,
                                                                 RealType* values ) const
{
+98 −7
Original line number Diff line number Diff line
@@ -117,6 +117,17 @@ void tnlDenseMatrix< Real, Device, Index >::reset()
   this->values.reset();
}

template< typename Real,
          typename Device,
          typename Index >
bool tnlDenseMatrix< Real, Device, Index >::setElementFast( const IndexType row,
                                                            const IndexType column,
                                                            const RealType& value )
{
   this->values.operator[]( this->getElementIndex( row, column ) ) = value;
   return true;
}

template< typename Real,
          typename Device,
          typename Index >
@@ -128,6 +139,23 @@ bool tnlDenseMatrix< Real, Device, Index >::setElement( const IndexType row,
   return true;
}


template< typename Real,
          typename Device,
          typename Index >
bool tnlDenseMatrix< Real, Device, Index >::addElementFast( const IndexType row,
                                                            const IndexType column,
                                                            const RealType& value,
                                                            const RealType& thisElementMultiplicator )
{
   const IndexType elementIndex = this->getElementIndex( row, column );
   if( thisElementMultiplicator == 1.0 )
      this->values.operator[]( elementIndex ) += value;
   else
      this->values.operator[]( elementIndex ) =
         thisElementMultiplicator * this->values.operator[]( elementIndex ) + value;
}

template< typename Real,
          typename Device,
          typename Index >
@@ -138,10 +166,29 @@ bool tnlDenseMatrix< Real, Device, Index >::addElement( const IndexType row,
{
   const IndexType elementIndex = this->getElementIndex( row, column );
   if( thisElementMultiplicator == 1.0 )
      values->operator[]( elementIndex ) += value;
      this->values.setElement( elementIndex,
                               this->values.getElement( elementIndex ) + value );
   else
      values->operator[]( elementIndex ) =
         thisElementMultiplicator * values->operator[]( elementIndex ) + value;
      this->values.setElement( elementIndex,
                               thisElementMultiplicator * this->values.getElement( elementIndex ) + value );
}


template< typename Real,
          typename Device,
          typename Index >
bool tnlDenseMatrix< Real, Device, Index >::setRowFast( const IndexType row,
                                                        const IndexType* columns,
                                                        const RealType* values,
                                                        const IndexType elements )
{
   tnlAssert( elements <= this->getColumns(),
            cerr << " elements = " << elements
                 << " this->columns = " << this->getColumns()
                 << " this->getName() = " << this->getName() );
   for( IndexType i = 0; i < elements; i++ )
      this->setElementFast( row, columns[ i ], values[ i ] );
   return true;
}

template< typename Real,
@@ -152,12 +199,31 @@ bool tnlDenseMatrix< Real, Device, Index >::setRow( const IndexType row,
                                                    const RealType* values,
                                                    const IndexType elements )
{
   tnlAssert( elements <= this->getDimensions().y(),
   tnlAssert( elements <= this->getColumns(),
            cerr << " elements = " << elements
                 << " this->columns = " << this->getDimensions().y()
                 << " this->columns = " << this->getColumns()
                 << " this->getName() = " << this->getName() );
   for( IndexType i = 0; i < elements; i++ )
      this->operator()( row, columns[ i ] ) = values[ i ];
      this->setElement( row, columns[ i ], values[ i ] );
   return true;
}

template< typename Real,
          typename Device,
          typename Index >
bool tnlDenseMatrix< Real, Device, Index >::addRowFast( const IndexType row,
                                                        const IndexType* columns,
                                                        const RealType* values,
                                                        const IndexType elements,
                                                        const RealType& thisRowMultiplicator )
{
   tnlAssert( elements <= this->columns,
            cerr << " elements = " << elements
                 << " this->columns = " << this->columns
                 << " this->getName() = " << this->getName() );
   for( IndexType i = 0; i < elements; i++ )
      this->setElementFast( row, columns[ i ],
                            thisRowMultiplicator * this->getElementFast( row, columns[ i ] ) + values[ i ] );
   return true;
}

@@ -180,6 +246,16 @@ bool tnlDenseMatrix< Real, Device, Index >::addRow( const IndexType row,
   return true;
}


template< typename Real,
          typename Device,
          typename Index >
Real tnlDenseMatrix< Real, Device, Index >::getElementFast( const IndexType row,
                                                            const IndexType column ) const
{
   return this->values.operator[]( this->getElementIndex( row, column ) );
}

template< typename Real,
          typename Device,
          typename Index >
@@ -189,6 +265,20 @@ Real tnlDenseMatrix< Real, Device, Index >::getElement( const IndexType row,
   return this->values.getElement( this->getElementIndex( row, column ) );
}

template< typename Real,
          typename Device,
          typename Index >
void tnlDenseMatrix< Real, Device, Index >::getRowFast( const IndexType row,
                                                        IndexType* columns,
                                                        RealType* values ) const
{
   for( IndexType i = 0; i < this->getColumns(); i++ )
   {
      columns[ i ] = i;
      values[ i ] = this->getElementFast( row, i );
   }
}

template< typename Real,
          typename Device,
          typename Index >
@@ -203,6 +293,7 @@ void tnlDenseMatrix< Real, Device, Index >::getRow( const IndexType row,
   }
}


template< typename Real,
          typename Device,
          typename Index >
+39 −18
Original line number Diff line number Diff line
@@ -155,6 +155,16 @@ bool tnlEllpackMatrix< Real, Device, Index >::operator != ( const tnlEllpackMatr
   return ! ( ( *this ) == matrix );
}

template< typename Real,
          typename Device,
          typename Index >
bool tnlEllpackMatrix< Real, Device, Index > :: setElementFast( const IndexType row,
                                                                const IndexType column,
                                                                const Real& value )
{
   return this->addElement( row, column, value, 0.0 );
}

template< typename Real,
          typename Device,
          typename Index >
@@ -165,10 +175,11 @@ bool tnlEllpackMatrix< Real, Device, Index > :: setElement( const IndexType row,
   return this->addElement( row, column, value, 0.0 );
}


template< typename Real,
          typename Device,
          typename Index >
bool tnlEllpackMatrix< Real, Device, Index > :: addElement( const IndexType row,
bool tnlEllpackMatrix< Real, Device, Index > :: addElementFast( const IndexType row,
                                                                const IndexType column,
                                                                const RealType& value,
                                                                const RealType& thisElementMultiplicator )
@@ -215,7 +226,7 @@ bool tnlEllpackMatrix< Real, Device, Index > :: addElement( const IndexType row,
template< typename Real,
          typename Device,
          typename Index >
bool tnlEllpackMatrix< Real, Device, Index > :: setRow( const IndexType row,
bool tnlEllpackMatrix< Real, Device, Index > :: setRowFast( const IndexType row,
                                                            const IndexType* columnIndexes,
                                                            const RealType* values,
                                                            const IndexType elements )
@@ -237,7 +248,7 @@ bool tnlEllpackMatrix< Real, Device, Index > :: setRow( const IndexType row,
template< typename Real,
          typename Device,
          typename Index >
bool tnlEllpackMatrix< Real, Device, Index > :: addRow( const IndexType row,
bool tnlEllpackMatrix< Real, Device, Index > :: addRowFast( const IndexType row,
                                                            const IndexType* columns,
                                                            const RealType* values,
                                                            const IndexType numberOfElements,
@@ -250,7 +261,7 @@ bool tnlEllpackMatrix< Real, Device, Index > :: addRow( const IndexType row,
template< typename Real,
          typename Device,
          typename Index >
Real tnlEllpackMatrix< Real, Device, Index >::getElement( const IndexType row,
Real tnlEllpackMatrix< Real, Device, Index >::getElementFast( const IndexType row,
                                                              const IndexType column ) const
{
   IndexType elementPtr( row * this->rowLengths );
@@ -264,7 +275,17 @@ Real tnlEllpackMatrix< Real, Device, Index >::getElement( const IndexType row,
template< typename Real,
          typename Device,
          typename Index >
void tnlEllpackMatrix< Real, Device, Index >::getRow( const IndexType row,
Real tnlEllpackMatrix< Real, Device, Index >::getElement( const IndexType row,
                                                          const IndexType column ) const
{
   return this->getElementFast( row, column );
}


template< typename Real,
          typename Device,
          typename Index >
void tnlEllpackMatrix< Real, Device, Index >::getRowFast( const IndexType row,
                                                          IndexType* columns,
                                                          RealType* values ) const
{
Loading