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

Adde tnlCudaSupport.h for passing structures to Cuda devices.

parent f55cad06
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -13,6 +13,7 @@ EXTRA_DIST = tnlConfigDescriptionParser.y \
headers = tnlAssert.h \
          tnlConfigDescription.h \
    	    tnlCurve.h \
    	    tnlCudaSupport.h \
		    tnlDataElement.h \
		    tnlField1D.h \
		    tnlFieldCUDA1D.h \
+42 −0
Original line number Diff line number Diff line
/***************************************************************************
                          tnlCudaSupport.h  -  description
                             -------------------
    begin                : Feb 23, 2010
    copyright            : (C) 2010 by Tomas Oberhuber
    email                : tomas.oberhuber@fjfi.cvut.cz
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 ***************************************************************************/

#ifndef TNLCUDASUPPORT_H_
#define TNLCUDASUPPORT_H_

template< class T >
T* passToCudaDevice( const T& data )
{
#ifdef HAVE_CUDA
   T* cuda_data;
   if( cudaMalloc( ( void** ) & cuda_data, sizeof( T ) ) != cudaSuccess )
   {
      cerr << "Unable to allocate CUDA device memory to pass a data structure there." << endl;
      return 0;
   }
   if( cudaMemcpy( cuda_data, &data, sizeof( T ), cudaMemcpyHostToDevice ) != cudaSuccess )
   {
      cerr << "Unable to pass data structure to CUDA device." << endl;
      return 0;
   }
   return cuda_data;
#else
   return 0;
#endif
}

#endif /* TNLCUDASUPPORT_H_ */