Skip to content
Snippets Groups Projects

Tutorials

Merged Tomáš Oberhuber requested to merge tutorials into develop
8 files
+ 64
58
Compare changes
  • Side-by-side
  • Inline
Files
8
@@ -9,14 +9,26 @@ using ArrayCuda = Containers::Array< int, Devices::Cuda >;
@@ -9,14 +9,26 @@ using ArrayCuda = Containers::Array< int, Devices::Cuda >;
struct Tuple
struct Tuple
{
{
 
Tuple( const int size ):
 
a1( size ), a2( size ){};
 
 
void setSize( const int size )
 
{
 
a1->setSize( size );
 
a2->setSize( size );
 
}
 
Pointers::SharedPointer< ArrayCuda > a1, a2;
Pointers::SharedPointer< ArrayCuda > a1, a2;
};
};
__global__ void checkArray( const Tuple t )
__global__ void printTuple( const Tuple t )
{
{
printf( "Array size is: %d\n", ptr->getSize() );
printf( "Tuple size is: %d\n", t.a1->getSize() );
for( int i = 0; i < ptr->getSize(); i++ )
for( int i = 0; i < t.a1->getSize(); i++ )
printf( "a[ %d ] = %d \n", i, ( *ptr )[ i ] );
{
 
printf( "a1[ %d ] = %d \n", i, ( *t.a1 )[ i ] );
 
printf( "a2[ %d ] = %d \n", i, ( *t.a2 )[ i ] );
 
}
}
}
int main( int argc, char* argv[] )
int main( int argc, char* argv[] )
@@ -25,23 +37,20 @@ int main( int argc, char* argv[] )
@@ -25,23 +37,20 @@ int main( int argc, char* argv[] )
* Create a tuple of arrays and print the in CUDA kernel
* Create a tuple of arrays and print the in CUDA kernel
*/
*/
#ifdef HAVE_CUDA
#ifdef HAVE_CUDA
Tuple t;
Tuple t( 3 );
t.a1.modifyData< Devices::Host >().setSize( 10 );
*t.a1 = 1;
t.a1.modifyData< Devices::Host >() = 1;
*t.a2 = 2;
t.a2.modifyData< Devices::Host >().setSize( 10 );
t.a2.modifyData< Devices::Host >() = 2;
Pointers::synchronizeSmartPointersOnDevice< Devices::Cuda >();
Pointers::synchronizeSmartPointersOnDevice< Devices::Cuda >();
printkArrays<<< 1, 1 >>>( t );
printTuple<<< 1, 1 >>>( t );
/***
/***
* Resize the array
* Resize the array
*/
*/
t.a1.modifyData< Devices::Host >().setSize( 5 );
t.setSize( 5 );
t.a1.modifyData< Devices::Host >() = 3;
*t.a1 = 3;
t.a2.modifyData< Devices::Host >().setSize( 5 );
*t.a2 = 4;
t.a2.modifyData< Devices::Host >() = 4;
Pointers::synchronizeSmartPointersOnDevice< Devices::Cuda >();
Pointers::synchronizeSmartPointersOnDevice< Devices::Cuda >();
printArrays<<< 1, 1 >>>( t );
printTuple<<< 1, 1 >>>( t );
#endif
#endif
return EXIT_SUCCESS;
return EXIT_SUCCESS;
Loading