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

The first succesful CUDA kernel test.

parent 77ac114f
Loading
Loading
Loading
Loading
+31 −2
Original line number Diff line number Diff line
#include <cuda.h> 
#include <core/tnlString.h>

#include <core/tnlLongVector.h>
#include <core/tnlLongVectorCUDA.h>
#include <core/tnlLongVectorCUDATester.h>

__global__ void setZeros( float* A )
__global__ void setNumber( float* A, float c )
{
   int i = threadIdx. x;
   A[ i ] = 0.0;
   A[ i ] = c;
}

void testKernel()
{
   tnlLongVectorCUDA< float > device_vector( 500 );
   tnlLongVector< float > host_vector( 500 );
   float* data = device_vector. Data();
   setNumber<<< 1, 500 >>>( data, 0.0 );
   host_vector. copyFrom( device_vector );
   int errors( 0 );
   for( int i = 0; i < 500; i ++ )
   {
      if( host_vector[ i ] != 0.0 ) errors ++;
      cout << host_vector[ i ] << "-";
   }
   CPPUNIT_ASSERT( ! errors );
   setNumber<<< 1, 500 >>>( data, 1.0 );
   host_vector. copyFrom( device_vector );
   errors = 0;
   for( int i = 0; i < 500; i ++ )
   {
      if( host_vector[ i ] != 1.0 ) errors ++;
      cout << host_vector[ i ] << "-";
   }
   CPPUNIT_ASSERT( ! errors );
}
 No newline at end of file
+5 −2
Original line number Diff line number Diff line
@@ -29,7 +29,7 @@
#include <core/tnlLongVector.h>

#ifdef HAVE_CUDA
__global__ void setZeros( float* A );
void testKernel();
#endif


@@ -63,7 +63,10 @@ template< class T > class tnlLongVectorCUDATester : public CppUnit :: TestCase
   void testKernel()
   {
#ifdef HAVE_CUDA

      :: testKernel();
#else
      cout << "CUDA is not supported." << endl;
      CPPUNIT_ASSERT( true );
#endif
   };