Skip to content
Snippets Groups Projects
Commit 04c68239 authored by Tomáš Oberhuber's avatar Tomáš Oberhuber
Browse files

CUDA kernel tests rewritten as templates. (Tests to not pass.)

parent 1591cf3c
No related branches found
No related tags found
No related merge requests found
......@@ -88,6 +88,7 @@ libcore_tests_sources = tnlStringTester.cpp \
tnlObjectTester.cpp \
tnlObjectTester.h \
tnlLongVectorCUDATester.cu \
tnlLongVectorCUDATester.cu.h \
tnlLongVectorCUDATester.h
......
......@@ -125,6 +125,7 @@ template< class T > class tnlLongVectorCUDA : public tnlObject
{
assert( long_vector. GetSize() == GetSize() );
cudaMemcpy( data, long_vector. Data(), GetSize() * sizeof( T ), cudaMemcpyHostToDevice );
return true;
}
virtual
......@@ -148,6 +149,7 @@ template< class T > bool tnlLongVector< T > :: copyFrom( const tnlLongVectorCUDA
{
assert( cuda_vector. GetSize() == GetSize() );
cudaMemcpy( data, cuda_vector. Data(), GetSize() * sizeof( T ), cudaMemcpyDeviceToHost );
return true;
}
#endif
......
#include <cuda.h>
#include <core/tnlString.h>
#include <tnlLongVectorCUDATester.cu.h>
#include <core/tnlLongVector.h>
#include <core/tnlLongVectorCUDA.h>
#include <core/tnlLongVectorCUDATester.h>
__global__ void setNumber( float* A, float c )
void testKernelStarter( const float& number, const int size )
{
int i = threadIdx. x;
A[ i ] = c;
testKernel( number, size );
}
void testKernel()
void testKernelStarter( const double& number, const int size )
{
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
testKernel( number, size );
}
#include <cuda.h>
#include <cppunit/extensions/HelperMacros.h>
#include <core/tnlString.h>
#include <core/tnlLongVector.h>
#include <core/tnlLongVectorCUDA.h>
#include <core/tnlLongVectorCUDATester.h>
#ifndef tnlLongVectorCUDATester_cu_h
#define tnlLongVectorCUDATester_cu_h
template< class T > __global__ void setNumber( T* A, T c )
{
int i = threadIdx. x;
A[ i ] = c;
};
template< class T > void testKernel( const T& number, const int size )
{
tnlLongVectorCUDA< T > device_vector( size );
tnlLongVector< T > host_vector( size );
T* data = device_vector. Data();
setNumber<<< 1, size >>>( data, number );
host_vector. copyFrom( device_vector );
int errors( 0 );
for( int i = 0; i < size; i ++ )
{
cout << host_vector[ i ] << "-";
if( host_vector[ i ] != number ) errors ++;
}
CPPUNIT_ASSERT( ! errors );
};
#endif
......@@ -29,7 +29,8 @@
#include <core/tnlLongVector.h>
#ifdef HAVE_CUDA
void testKernel();
void testKernelStarter( const float& number, const int size );
void testKernelStarter( const double& number, const int size );
#endif
......@@ -54,16 +55,21 @@ template< class T > class tnlLongVectorCUDATester : public CppUnit :: TestCase
& tnlLongVectorCUDATester< float > :: testCopying )
);
suiteOfTests -> addTest( new CppUnit :: TestCaller< tnlLongVectorCUDATester< float > >(
"testKernel",
"testKernelFloat",
& tnlLongVectorCUDATester< float > :: testKernel )
);
/*suiteOfTests -> addTest( new CppUnit :: TestCaller< tnlLongVectorCUDATester< double > >(
"testKernelDouble",
& tnlLongVectorCUDATester< double > :: testKernel )
);*/
return suiteOfTests;
}
void testKernel()
{
#ifdef HAVE_CUDA
:: testKernel();
for( int i = 0; i < 10; i ++ )
:: testKernelStarter( ( T ) i, 1000 );
#else
cout << "CUDA is not supported." << endl;
CPPUNIT_ASSERT( true );
......
......@@ -56,7 +56,6 @@ int main( int argc, char* argv[] )
tnlObjectTester tnl_object_tester;
tnl_object_tester. Test( tester );
tester. PrintStatistics();
return EXIT_SUCCESS;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment