From 1591cf3c6d85f40a612c8380d99d47bdcb2c727e Mon Sep 17 00:00:00 2001 From: Tomas Oberhuber <tomas.oberhuber@fjfi.cvut.cz> Date: Sun, 10 Jan 2010 19:56:40 +0000 Subject: [PATCH] The first succesful CUDA kernel test. --- src/core/tnlLongVectorCUDATester.cu | 33 +++++++++++++++++++++++++++-- src/core/tnlLongVectorCUDATester.h | 7 ++++-- 2 files changed, 36 insertions(+), 4 deletions(-) diff --git a/src/core/tnlLongVectorCUDATester.cu b/src/core/tnlLongVectorCUDATester.cu index 8be1abbc5e..35e41eb10d 100644 --- a/src/core/tnlLongVectorCUDATester.cu +++ b/src/core/tnlLongVectorCUDATester.cu @@ -1,8 +1,37 @@ +#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 diff --git a/src/core/tnlLongVectorCUDATester.h b/src/core/tnlLongVectorCUDATester.h index 2041a9f7e3..a814b8f4ff 100644 --- a/src/core/tnlLongVectorCUDATester.h +++ b/src/core/tnlLongVectorCUDATester.h @@ -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 }; -- GitLab