Newer
Older
/***************************************************************************
tnlIndexMultimapTester.h - description
-------------------
begin : Sep 10, 2015
copyright : (C) 2015 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 TNLINDEXMULTIMAPTESTER_H_
#define TNLINDEXMULTIMAPTESTER_H_
template< typename Multimap,
class tnlIndexMultimapTesterSetter
static bool setup( Multimap& multimap )
{
return true;
}
};
#ifdef HAVE_CPPUNIT
#include <cppunit/TestSuite.h>
#include <cppunit/TestResult.h>
#include <cppunit/TestCaller.h>
#include <cppunit/TestCase.h>
#include <cppunit/Message.h>
#include <core/tnlFile.h>
#include <core/vectors/tnlVector.h>
#ifdef HAVE_CUDA
template< typename IndexMultimapType >
__global__ void tnlIndexMultimapTester__setElementFastTestCudaKernel( IndexMultimapType* graph,
template< typename IndexMultimapType >
__global__ void tnlIndexMultimapTester__setElementFast_DiagonalIndexMultimapTestCudaKernel( IndexMultimapType* graph,
template< typename IndexMultimapType >
__global__ void tnlIndexMultimapTester__setElementFast_DenseIndexMultimapTestCudaKernel1( IndexMultimapType* graph,
template< typename IndexMultimapType >
__global__ void tnlIndexMultimapTester__setElementFast_DenseIndexMultimapTestCudaKernel2( IndexMultimapType* graph,
template< typename IndexMultimapType >
__global__ void tnlIndexMultimapTester__setElementFast_LowerTriangularIndexMultimapTestCudaKernel1( IndexMultimapType* graph,
template< typename IndexMultimapType >
__global__ void tnlIndexMultimapTester__setElementFast_LowerTriangularIndexMultimapTestCudaKernel2( IndexMultimapType* graph,
template< typename IndexMultimapType >
__global__ void tnlIndexMultimapTester__setRowFast_DiagonalIndexMultimapTestCudaKernel( IndexMultimapType* graph,
template< typename IndexMultimapType >
__global__ void tnlIndexMultimapTester__setRowFast_DenseIndexMultimapTestCudaKernel1( IndexMultimapType* graph,
template< typename IndexMultimapType >
__global__ void tnlIndexMultimapTester__setRowFast_DenseIndexMultimapTestCudaKernel2( IndexMultimapType* graph,
template< typename IndexMultimapType >
__global__ void tnlIndexMultimapTester__setRowFast_LowerTriangularIndexMultimapTestCudaKernel( IndexMultimapType* graph,
class tnlIndexMultimapTestDefaultSetup
template< typename IndexMultimap,
typename IndexMultimapSetup = tnlIndexMultimapTestDefaultSetup >
class tnlIndexMultimapTester : public CppUnit :: TestCase
typedef IndexMultimap IndexMultimapType;
typedef typename IndexMultimap::DeviceType DeviceType;
typedef typename IndexMultimap::IndexType IndexType;
typedef tnlIndexMultimapTester< IndexMultimapType, IndexMultimapSetup > TesterType;
typedef tnlIndexMultimapTesterSetter< IndexMultimapType, IndexMultimapSetup > IndexMultimapSetter;
typedef typename CppUnit::TestCaller< TesterType > TestCallerType;
typedef typename IndexMultimapType::ValuesAllocationVectorType ValuesAllocationVectorType;
typedef typename IndexMultimapType::ValuesAccessorType ValuesAccessorType;
tnlIndexMultimapTester(){};
~tnlIndexMultimapTester(){};
static CppUnit :: Test* suite()
{
tnlString testSuiteName( "tnlIndexMultimapTester< " );
testSuiteName += IndexMultimapType::getType() + " >";
CppUnit :: TestSuite* suiteOfTests = new CppUnit :: TestSuite( testSuiteName.getString() );
CppUnit :: TestResult result;
suiteOfTests->addTest( new TestCallerType( "setRangesTest", &TesterType::setRangesTest ) );
//suiteOfTests->addTest( new TestCallerType( "setLikeTest", &TesterType::setLikeTest ) );
suiteOfTests->addTest( new TestCallerType( "setElementTest", &TesterType::setElementTest ) );
/*suiteOfTests->addTest( new TestCallerType( "setElementFastTest", &TesterType::setElementFastTest ) );
suiteOfTests->addTest( new TestCallerType( "setElement_DiagonalIndexMultimapTest", &TesterType::setElement_DiagonalIndexMultimapTest ) );
suiteOfTests->addTest( new TestCallerType( "setElementFast_DiagonalIndexMultimapTest", &TesterType::setElementFast_DiagonalIndexMultimapTest ) );
suiteOfTests->addTest( new TestCallerType( "setElement_DenseIndexMultimapTest", &TesterType::setElement_DenseIndexMultimapTest ) );
suiteOfTests->addTest( new TestCallerType( "setElementFast_DenseIndexMultimapTest", &TesterType::setElementFast_DenseIndexMultimapTest ) );
suiteOfTests->addTest( new TestCallerType( "setElement_LowerTriangularIndexMultimapTest", &TesterType::setElement_LowerTriangularIndexMultimapTest ) );
suiteOfTests->addTest( new TestCallerType( "setElementFast_LowerTriangularIndexMultimapTest", &TesterType::setElementFast_LowerTriangularIndexMultimapTest ) );
suiteOfTests->addTest( new TestCallerType( "setRow_DiagonalIndexMultimapTest", &TesterType::setRow_DiagonalIndexMultimapTest ) );
suiteOfTests->addTest( new TestCallerType( "setRowFast_DiagonalIndexMultimapTest", &TesterType::setRowFast_DiagonalIndexMultimapTest ) );
suiteOfTests->addTest( new TestCallerType( "setRow_DenseIndexMultimapTest", &TesterType::setRow_DenseIndexMultimapTest ) );
suiteOfTests->addTest( new TestCallerType( "setRowFast_DenseIndexMultimapTest", &TesterType::setRowFast_DenseIndexMultimapTest ) );
suiteOfTests->addTest( new TestCallerType( "setRow_LowerTriangularIndexMultimapTest", &TesterType::setRow_LowerTriangularIndexMultimapTest ) );
suiteOfTests->addTest( new TestCallerType( "setRowFast_LowerTriangularIndexMultimapTest", &TesterType::setRowFast_LowerTriangularIndexMultimapTest ) );
suiteOfTests->addTest( new TestCallerType( "addElementTest", &TesterType::addElementTest ) );
suiteOfTests->addTest( new TestCallerType( "vectorProduct_DiagonalIndexMultimapTest", &TesterType::vectorProduct_DiagonalIndexMultimapTest ) );
suiteOfTests->addTest( new TestCallerType( "vectorProduct_DenseIndexMultimapTest", &TesterType::vectorProduct_DenseIndexMultimapTest ) );
suiteOfTests->addTest( new TestCallerType( "vectorProduct_LowerTriangularIndexMultimapTest", &TesterType::vectorProduct_LowerTriangularIndexMultimapTest ) );
/*suiteOfTests -> addTest( new TestCallerType( "graphTranspositionTest", &TesterType::graphTranspositionTest ) );
suiteOfTests -> addTest( new TestCallerType( "addIndexMultimapTest", &TesterType::addIndexMultimapTest ) );*/
return suiteOfTests;
}
IndexMultimapType n;
IndexMultimapSetter::setup( n );
n.setRanges( 10, 10 );
CPPUNIT_ASSERT( n.getKeysRange() == 10 );
CPPUNIT_ASSERT( n.getValuesRange() == 10 );
IndexMultimapType m1, m2;
IndexMultimapSetter::setup( m1 );
IndexMultimapSetter::setup( m2 );
m1.setDimensions( 10, 10 );
IndexVector rowLengths;
rowLengths.setSize( m1.getRows() );
rowLengths.setValue( 5 );
m1.setCompressedRowsLengths( rowLengths );
m2.setLike( m1 );
CPPUNIT_ASSERT( m1.getRows() == m2.getRows() );
}*/
/****
* Set element tests
*/
void setElementTest()
{
IndexMultimapType n;
IndexMultimapSetter::setup( n );
n.setRanges( 10, 10 );
ValuesAllocationVectorType portsAllocationVector;
portsAllocationVector.setSize( n.getKeysRange() );
portsAllocationVector.setValue( 7 );
n.allocate( portsAllocationVector );
ValuesAccessorType p = n.getValues( 0 );
for( int i = 0; i < 7; i++ )
{
p.setOutput( i, i );
//CPPUNIT_ASSERT( n.setPort( 0, i, i ) );
}
//CPPUNIT_ASSERT( m.setElement( 0, 8, 8 ) == false );
for( int i = 0; i < 7; i++ )
CPPUNIT_ASSERT( p.getOutput( i ) == i );
}
#ifdef UNDEF
IndexMultimapType m;
IndexMultimapSetter::setup( m );
m.setDimensions( 10, 10 );
IndexVector rowLengths;
rowLengths.setSize( m.getRows() );
rowLengths.setValue( 7 );
m.setCompressedRowsLengths( rowLengths );
if( DeviceType::getDevice() == tnlHostDevice )
{
for( int i = 0; i < 7; i++ )
CPPUNIT_ASSERT( m.setElementFast( 0, i, i ) );
//CPPUNIT_ASSERT( m.setElementFast( 0, 8, 8 ) == false );
}
if( DeviceType::getDevice() == tnlCudaDevice )
{
#ifdef HAVE_CUDA
IndexMultimapType* kernel_graph = tnlCuda::passToDevice( m );
bool testResult( true );
bool* kernel_testResult = tnlCuda::passToDevice( testResult );
checkCudaDevice;
dim3 cudaBlockSize( 256 ), cudaGridSize( 1 );
tnlIndexMultimapTester__setElementFastTestCudaKernel< IndexMultimapType >
<<< cudaGridSize, cudaBlockSize >>>
( kernel_graph,
kernel_testResult );
CPPUNIT_ASSERT( tnlCuda::passFromDevice( kernel_testResult ) );
tnlCuda::freeFromDevice( kernel_graph );
tnlCuda::freeFromDevice( kernel_testResult );
checkCudaDevice;
#endif
}
for( int i = 0; i < 7; i++ )
CPPUNIT_ASSERT( m.getElement( 0, i ) == i );
}
void setElement_DiagonalIndexMultimapTest()
IndexMultimapType m;
IndexMultimapSetter::setup( m );
m.setDimensions( 10, 10 );
IndexVector rowLengths;
rowLengths.setSize( m.getRows() );
rowLengths.setValue( 7 );
m.setCompressedRowsLengths( rowLengths );
for( int i = 0; i < 10; i++ )
m.setElement( i, i, i );
for( int i = 0; i < 10; i++ )
{
for( int j = 0; j < 10; j++ )
{
if( i == j )
CPPUNIT_ASSERT( m.getElement( i, j ) == i );
else
CPPUNIT_ASSERT( m.getElement( i, j ) == 0 );
}
}
}
void setElementFast_DiagonalIndexMultimapTest()
IndexMultimapType m;
IndexMultimapSetter::setup( m );
m.setDimensions( 10, 10 );
IndexVector rowLengths;
rowLengths.setSize( m.getRows() );
rowLengths.setValue( 7 );
m.setCompressedRowsLengths( rowLengths );
if( DeviceType::DeviceType == ( int ) tnlHostDevice )
{
for( int i = 0; i < 10; i++ )
m.setElementFast( i, i, i );
}
if( DeviceType::DeviceType == ( int ) tnlCudaDevice )
{
#ifdef HAVE_CUDA
IndexMultimapType* kernel_graph = tnlCuda::passToDevice( m );
bool testResult( true );
bool* kernel_testResult = tnlCuda::passToDevice( testResult );
checkCudaDevice;
dim3 cudaBlockSize( 256 ), cudaGridSize( 1 );
tnlIndexMultimapTester__setElementFast_DiagonalIndexMultimapTestCudaKernel< IndexMultimapType >
<<< cudaGridSize, cudaBlockSize >>>
( kernel_graph,
kernel_testResult );
CPPUNIT_ASSERT( tnlCuda::passFromDevice( kernel_testResult ) );
tnlCuda::freeFromDevice( kernel_graph );
tnlCuda::freeFromDevice( kernel_testResult );
checkCudaDevice;
#endif
}
for( int i = 0; i < 10; i++ )
{
for( int j = 0; j < 10; j++ )
{
if( i == j )
CPPUNIT_ASSERT( m.getElement( i, j ) == i );
else
CPPUNIT_ASSERT( m.getElement( i, j ) == 0 );
}
}
}
void setElement_DenseIndexMultimapTest()
IndexMultimapType m;
IndexMultimapSetter::setup( m );
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
m.setDimensions( 10, 10 );
IndexVector rowLengths;
rowLengths.setSize( m.getRows() );
rowLengths.setValue( 10 );
m.setCompressedRowsLengths( rowLengths );
for( int i = 0; i < 10; i++ )
m.setElement( i, i, i );
for( int i = 0; i < 10; i++ )
for( int j = 0; j < 10; j++ )
m.addElement( i, j, 1, 0.5 );
for( int i = 0; i < 10; i++ )
for( int j = 0; j < 10; j++ )
if( i == j )
CPPUNIT_ASSERT( m.getElement( i, j ) == 1.0+0.5*i );
else
CPPUNIT_ASSERT( m.getElement( i, j ) == 1.0 );
m.reset();
m.setDimensions( 10, 10 );
m.setCompressedRowsLengths( rowLengths );
for( int i = 9; i >= 0; i-- )
for( int j = 9; j >= 0; j-- )
m.setElement( i, j, i+j );
for( int i = 9; i >= 0; i-- )
for( int j = 9; j >= 0; j-- )
CPPUNIT_ASSERT( m.getElement( i, j ) == i+j );
}
void setElementFast_DenseIndexMultimapTest()
IndexMultimapType m;
IndexMultimapSetter::setup( m );
m.setDimensions( 10, 10 );
IndexVector rowLengths;
rowLengths.setSize( m.getRows() );
rowLengths.setValue( 10 );
m.setCompressedRowsLengths( rowLengths );
if( DeviceType::DeviceType == ( int ) tnlHostDevice )
{
for( int i = 0; i < 10; i++ )
m.setElementFast( i, i, i );
for( int i = 0; i < 10; i++ )
for( int j = 0; j < 10; j++ )
m.addElementFast( i, j, 1, 0.5 );
}
if( DeviceType::DeviceType == ( int ) tnlCudaDevice )
{
#ifdef HAVE_CUDA
IndexMultimapType* kernel_graph = tnlCuda::passToDevice( m );
bool testResult( true );
bool* kernel_testResult = tnlCuda::passToDevice( testResult );
checkCudaDevice;
dim3 cudaBlockSize( 256 ), cudaGridSize( 1 );
tnlIndexMultimapTester__setElementFast_DenseIndexMultimapTestCudaKernel1< IndexMultimapType >
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
<<< cudaGridSize, cudaBlockSize >>>
( kernel_graph,
kernel_testResult );
CPPUNIT_ASSERT( tnlCuda::passFromDevice( kernel_testResult ) );
tnlCuda::freeFromDevice( kernel_graph );
tnlCuda::freeFromDevice( kernel_testResult );
checkCudaDevice;
#endif
}
for( int i = 0; i < 10; i++ )
for( int j = 0; j < 10; j++ )
if( i == j )
CPPUNIT_ASSERT( m.getElement( i, j ) == 1.0+0.5*i );
else
CPPUNIT_ASSERT( m.getElement( i, j ) == 1.0 );
m.reset();
m.setDimensions( 10, 10 );
m.setCompressedRowsLengths( rowLengths );
if( DeviceType::DeviceType == ( int ) tnlHostDevice )
{
for( int i = 9; i >= 0; i-- )
for( int j = 9; j >= 0; j-- )
m.setElementFast( i, j, i+j );
}
if( DeviceType::DeviceType == ( int ) tnlCudaDevice )
{
#ifdef HAVE_CUDA
IndexMultimapType* kernel_graph = tnlCuda::passToDevice( m );
bool testResult( true );
bool* kernel_testResult = tnlCuda::passToDevice( testResult );
checkCudaDevice;
dim3 cudaBlockSize( 256 ), cudaGridSize( 1 );
tnlIndexMultimapTester__setElementFast_DenseIndexMultimapTestCudaKernel2< IndexMultimapType >
<<< cudaGridSize, cudaBlockSize >>>
( kernel_graph,
kernel_testResult );
CPPUNIT_ASSERT( tnlCuda::passFromDevice( kernel_testResult ) );
tnlCuda::freeFromDevice( kernel_graph );
tnlCuda::freeFromDevice( kernel_testResult );
checkCudaDevice;
#endif
}
for( int i = 9; i >= 0; i-- )
for( int j = 9; j >= 0; j-- )
CPPUNIT_ASSERT( m.getElement( i, j ) == i+j );
}
void setElement_LowerTriangularIndexMultimapTest()
IndexMultimapType m;
IndexMultimapSetter::setup( m );
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
m.setDimensions( 10, 10 );
IndexVector rowLengths;
rowLengths.setSize( m.getRows() );
for( int i = 0; i < 10; i++ )
rowLengths.setElement( i, i+1 );
m.setCompressedRowsLengths( rowLengths );
for( int i = 0; i < 10; i++ )
for( int j = 0; j <= i; j++ )
m.setElement( i, j, i + j );
for( int i = 0; i < 10; i++ )
for( int j = 0; j < 10; j++ )
if( j <= i )
CPPUNIT_ASSERT( m.getElement( i, j ) == i + j );
else
CPPUNIT_ASSERT( m.getElement( i, j ) == 0 );
m.reset();
m.setDimensions( 10, 10 );
m.setCompressedRowsLengths( rowLengths );
for( int i = 9; i >= 0; i-- )
for( int j = i; j >= 0; j-- )
m.setElement( i, j, i + j );
for( int i = 0; i < 10; i++ )
for( int j = 0; j < 10; j++ )
if( j <= i )
CPPUNIT_ASSERT( m.getElement( i, j ) == i + j );
else
CPPUNIT_ASSERT( m.getElement( i, j ) == 0 );
}
void setElementFast_LowerTriangularIndexMultimapTest()
IndexMultimapType m;
IndexMultimapSetter::setup( m );
m.setDimensions( 10, 10 );
IndexVector rowLengths;
rowLengths.setSize( m.getRows() );
for( int i = 0; i < 10; i++ )
rowLengths.setElement( i, i+1 );
m.setCompressedRowsLengths( rowLengths );
if( DeviceType::DeviceType == ( int ) tnlHostDevice )
{
for( int i = 0; i < 10; i++ )
for( int j = 0; j <= i; j++ )
m.setElementFast( i, j, i + j );
}
if( DeviceType::DeviceType == ( int ) tnlCudaDevice )
{
#ifdef HAVE_CUDA
IndexMultimapType* kernel_graph = tnlCuda::passToDevice( m );
bool testResult( true );
bool* kernel_testResult = tnlCuda::passToDevice( testResult );
checkCudaDevice;
dim3 cudaBlockSize( 256 ), cudaGridSize( 1 );
tnlIndexMultimapTester__setElementFast_LowerTriangularIndexMultimapTestCudaKernel1< IndexMultimapType >
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
<<< cudaGridSize, cudaBlockSize >>>
( kernel_graph,
kernel_testResult );
CPPUNIT_ASSERT( tnlCuda::passFromDevice( kernel_testResult ) );
tnlCuda::freeFromDevice( kernel_graph );
tnlCuda::freeFromDevice( kernel_testResult );
checkCudaDevice;
#endif
}
for( int i = 0; i < 10; i++ )
for( int j = 0; j < 10; j++ )
if( j <= i )
CPPUNIT_ASSERT( m.getElement( i, j ) == i + j );
else
CPPUNIT_ASSERT( m.getElement( i, j ) == 0 );
m.reset();
m.setDimensions( 10, 10 );
m.setCompressedRowsLengths( rowLengths );
if( DeviceType::DeviceType == ( int ) tnlHostDevice )
{
for( int i = 9; i >= 0; i-- )
for( int j = i; j >= 0; j-- )
m.setElementFast( i, j, i + j );
}
if( DeviceType::DeviceType == ( int ) tnlCudaDevice )
{
#ifdef HAVE_CUDA
IndexMultimapType* kernel_graph = tnlCuda::passToDevice( m );
bool testResult( true );
bool* kernel_testResult = tnlCuda::passToDevice( testResult );
checkCudaDevice;
dim3 cudaBlockSize( 256 ), cudaGridSize( 1 );
tnlIndexMultimapTester__setElementFast_LowerTriangularIndexMultimapTestCudaKernel2< IndexMultimapType >
<<< cudaGridSize, cudaBlockSize >>>
( kernel_graph,
kernel_testResult );
CPPUNIT_ASSERT( tnlCuda::passFromDevice( kernel_testResult ) );
tnlCuda::freeFromDevice( kernel_graph );
tnlCuda::freeFromDevice( kernel_testResult );
checkCudaDevice;
#endif
}
for( int i = 0; i < 10; i++ )
for( int j = 0; j < 10; j++ )
if( j <= i )
CPPUNIT_ASSERT( m.getElement( i, j ) == i + j );
else
CPPUNIT_ASSERT( m.getElement( i, j ) == 0 );
}
void addElementTest()
{
IndexMultimapType m;
IndexMultimapSetter::setup( m );
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
m.setDimensions( 10, 10 );
IndexVector rowLengths;
rowLengths.setSize( m.getRows() );
rowLengths.setValue( 7 );
m.setCompressedRowsLengths( rowLengths );
for( int i = 0; i < 10; i++ )
m.setElement( i, i, i );
for( int i = 0; i < 10; i++ )
for( int j = 0; j < 10; j++ )
if( abs( i - j ) <= 1 )
m.addElement( i, j, 1 );
for( int i = 0; i < 10; i++ )
for( int j = 0; j < 10; j++ )
if( i == j )
CPPUNIT_ASSERT( m.getElement( i, i ) == i + 1 );
else
if( abs( i - j ) == 1 )
CPPUNIT_ASSERT( m.getElement( i, j ) == 1 );
else
CPPUNIT_ASSERT( m.getElement( i, j ) == 0 );
}
/****
* Set row tests
*/
void setRow_DiagonalIndexMultimapTest()
IndexMultimapType m;
IndexMultimapSetter::setup( m );
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
m.setDimensions( 10, 10 );
IndexVector rowLengths;
rowLengths.setSize( m.getRows() );
rowLengths.setValue( 7 );
m.setCompressedRowsLengths( rowLengths );
RealType values[ 1 ];
IndexType columnIndexes[ 1 ];
for( int i = 0; i < 10; i++ )
{
values[ 0 ] = i;
columnIndexes[ 0 ] = i;
m.setRow( i, columnIndexes, values, 1 );
}
for( int i = 0; i < 10; i++ )
{
for( int j = 0; j < 10; j++ )
{
if( i == j )
CPPUNIT_ASSERT( m.getElement( i, j ) == i );
else
CPPUNIT_ASSERT( m.getElement( i, j ) == 0 );
}
}
}
void setRowFast_DiagonalIndexMultimapTest()
IndexMultimapType m;
IndexMultimapSetter::setup( m );
m.setDimensions( 10, 10 );
IndexVector rowLengths;
rowLengths.setSize( m.getRows() );
rowLengths.setValue( 7 );
m.setCompressedRowsLengths( rowLengths );
if( DeviceType::DeviceType == ( int ) tnlHostDevice )
{
RealType values[ 1 ];
IndexType columnIndexes[ 1 ];
for( int i = 0; i < 10; i++ )
{
values[ 0 ] = i;
columnIndexes[ 0 ] = i;
m.setRowFast( i, columnIndexes, values, 1 );
}
}
if( DeviceType::DeviceType == ( int ) tnlCudaDevice )
{
#ifdef HAVE_CUDA
IndexMultimapType* kernel_graph = tnlCuda::passToDevice( m );
bool testResult( true );
bool* kernel_testResult = tnlCuda::passToDevice( testResult );
checkCudaDevice;
dim3 cudaBlockSize( 256 ), cudaGridSize( 1 );
int sharedMemory = 100 * ( sizeof( IndexType ) + sizeof( RealType ) );
tnlIndexMultimapTester__setRowFast_DiagonalIndexMultimapTestCudaKernel< IndexMultimapType >
<<< cudaGridSize, cudaBlockSize, sharedMemory >>>
( kernel_graph,
kernel_testResult );
CPPUNIT_ASSERT( tnlCuda::passFromDevice( kernel_testResult ) );
tnlCuda::freeFromDevice( kernel_graph );
tnlCuda::freeFromDevice( kernel_testResult );
checkCudaDevice;
#endif
}
for( int i = 0; i < 10; i++ )
{
for( int j = 0; j < 10; j++ )
{
if( i == j )
CPPUNIT_ASSERT( m.getElement( i, j ) == i );
else
CPPUNIT_ASSERT( m.getElement( i, j ) == 0 );
}
}
}
void setRow_DenseIndexMultimapTest()
IndexMultimapType m;
IndexMultimapSetter::setup( m );
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
m.setDimensions( 10, 10 );
IndexVector rowLengths;
rowLengths.setSize( m.getRows() );
rowLengths.setValue( 10 );
m.setCompressedRowsLengths( rowLengths );
RealType values[ 10 ];
IndexType columnIndexes[ 10 ];
for( int i = 0; i < 10; i++ )
columnIndexes[ i ] = i;
for( int i = 0; i < 10; i++ )
{
for( int j = 0; j < 10; j++ )
if( i == j )
values[ i ] = 1.0 + 0.5 * j;
else
values[ j ] = 1.0;
m.setRow( i, columnIndexes, values, 10 );
}
for( int i = 0; i < 10; i++ )
for( int j = 0; j < 10; j++ )
if( i == j )
CPPUNIT_ASSERT( m.getElement( i, j ) == 1.0+0.5*i );
else
CPPUNIT_ASSERT( m.getElement( i, j ) == 1.0 );
m.reset();
m.setDimensions( 10, 10 );
m.setCompressedRowsLengths( rowLengths );
for( int i = 9; i >= 0; i-- )
{
for( int j = 9; j >= 0; j-- )
values[ j ] = i+j;
m.setRow( i, columnIndexes, values, 10 );
}
for( int i = 9; i >= 0; i-- )
for( int j = 9; j >= 0; j-- )
CPPUNIT_ASSERT( m.getElement( i, j ) == i+j );
}
void setRowFast_DenseIndexMultimapTest()
IndexMultimapType m;
IndexMultimapSetter::setup( m );
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
m.setDimensions( 10, 10 );
IndexVector rowLengths;
rowLengths.setSize( m.getRows() );
rowLengths.setValue( 10 );
m.setCompressedRowsLengths( rowLengths );
RealType values[ 10 ];
IndexType columnIndexes[ 10 ];
for( int i = 0; i < 10; i++ )
columnIndexes[ i ] = i;
if( DeviceType::DeviceType == ( int ) tnlHostDevice )
{
for( int i = 0; i < 10; i++ )
{
for( int j = 0; j < 10; j++ )
if( i == j )
values[ i ] = 1.0 + 0.5 * j;
else
values[ j ] = 1.0;
m.setRowFast( i, columnIndexes, values, 10 );
}
}
if( DeviceType::DeviceType == ( int ) tnlCudaDevice )
{
#ifdef HAVE_CUDA
IndexMultimapType* kernel_graph = tnlCuda::passToDevice( m );
bool testResult( true );
bool* kernel_testResult = tnlCuda::passToDevice( testResult );
checkCudaDevice;
dim3 cudaBlockSize( 256 ), cudaGridSize( 1 );
int sharedMemory = 100 * ( sizeof( IndexType ) + sizeof( RealType ) );
tnlIndexMultimapTester__setRowFast_DenseIndexMultimapTestCudaKernel1< IndexMultimapType >
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
<<< cudaGridSize, cudaBlockSize, sharedMemory >>>
( kernel_graph,
kernel_testResult );
CPPUNIT_ASSERT( tnlCuda::passFromDevice( kernel_testResult ) );
tnlCuda::freeFromDevice( kernel_graph );
tnlCuda::freeFromDevice( kernel_testResult );
checkCudaDevice;
#endif
}
for( int i = 0; i < 10; i++ )
for( int j = 0; j < 10; j++ )
if( i == j )
CPPUNIT_ASSERT( m.getElement( i, j ) == 1.0+0.5*i );
else
CPPUNIT_ASSERT( m.getElement( i, j ) == 1.0 );
m.reset();
m.setDimensions( 10, 10 );
m.setCompressedRowsLengths( rowLengths );
if( DeviceType::DeviceType == ( int ) tnlHostDevice )
{
for( int i = 9; i >= 0; i-- )
{
for( int j = 9; j >= 0; j-- )
values[ j ] = i+j;
m.setRowFast( i, columnIndexes, values, 10 );
}
}
if( DeviceType::DeviceType == ( int ) tnlCudaDevice )
{
#ifdef HAVE_CUDA
IndexMultimapType* kernel_graph = tnlCuda::passToDevice( m );
bool testResult( true );
bool* kernel_testResult = tnlCuda::passToDevice( testResult );
checkCudaDevice;
dim3 cudaBlockSize( 256 ), cudaGridSize( 1 );
int sharedMemory = 100 * ( sizeof( IndexType ) + sizeof( RealType ) );
tnlIndexMultimapTester__setRowFast_DenseIndexMultimapTestCudaKernel2< IndexMultimapType >
<<< cudaGridSize, cudaBlockSize, sharedMemory >>>
( kernel_graph,
kernel_testResult );
CPPUNIT_ASSERT( tnlCuda::passFromDevice( kernel_testResult ) );
tnlCuda::freeFromDevice( kernel_graph );
tnlCuda::freeFromDevice( kernel_testResult );
checkCudaDevice;
#endif
}
for( int i = 9; i >= 0; i-- )
for( int j = 9; j >= 0; j-- )
CPPUNIT_ASSERT( m.getElement( i, j ) == i+j );
}
void setRow_LowerTriangularIndexMultimapTest()
IndexMultimapType m;
IndexMultimapSetter::setup( m );
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
m.setDimensions( 10, 10 );
IndexVector rowLengths;
rowLengths.setSize( m.getRows() );
for( int i = 0; i < 10; i++ )
rowLengths.setElement( i, i+1 );
m.setCompressedRowsLengths( rowLengths );
RealType values[ 10 ];
IndexType columnIndexes[ 10 ];
for( int i = 0; i < 10; i++ )
columnIndexes[ i ] = i;
for( int i = 0; i < 10; i++ )
{
for( int j = 0; j <= i; j++ )
values[ j ] = i + j;
m.setRow( i, columnIndexes, values, i + 1 );
}
for( int i = 0; i < 10; i++ )
for( int j = 0; j < 10; j++ )
if( j <= i )
CPPUNIT_ASSERT( m.getElement( i, j ) == i + j );
else
CPPUNIT_ASSERT( m.getElement( i, j ) == 0 );
m.reset();
m.setDimensions( 10, 10 );
m.setCompressedRowsLengths( rowLengths );
for( int i = 9; i >= 0; i-- )
{
for( int j = i; j >= 0; j-- )
values[ j ] = i + j;
m.setRow( i, columnIndexes, values, i + 1 );
}
for( int i = 0; i < 10; i++ )
for( int j = 0; j < 10; j++ )
if( j <= i )
CPPUNIT_ASSERT( m.getElement( i, j ) == i + j );
else
CPPUNIT_ASSERT( m.getElement( i, j ) == 0 );
}
void setRowFast_LowerTriangularIndexMultimapTest()
IndexMultimapType m;
IndexMultimapSetter::setup( m );
m.setDimensions( 10, 10 );
IndexVector rowLengths;
rowLengths.setSize( m.getRows() );
for( int i = 0; i < 10; i++ )
rowLengths.setElement( i, i+1 );
m.setCompressedRowsLengths( rowLengths );
RealType values[ 10 ];
IndexType columnIndexes[ 10 ];
for( int i = 0; i < 10; i++ )
columnIndexes[ i ] = i;
if( DeviceType::DeviceType == ( int ) tnlHostDevice )
{
for( int i = 0; i < 10; i++ )
{
for( int j = 0; j <= i; j++ )
values[ j ] = i + j;
m.setRowFast( i, columnIndexes, values, i + 1 );
}
}
if( DeviceType::DeviceType == ( int ) tnlCudaDevice )
{
#ifdef HAVE_CUDA
IndexMultimapType* kernel_graph = tnlCuda::passToDevice( m );
bool testResult( true );
bool* kernel_testResult = tnlCuda::passToDevice( testResult );
checkCudaDevice;
dim3 cudaBlockSize( 256 ), cudaGridSize( 1 );
int sharedMemory = 100 * ( sizeof( IndexType ) + sizeof( RealType ) );
tnlIndexMultimapTester__setRowFast_LowerTriangularIndexMultimapTestCudaKernel< IndexMultimapType >
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
<<< cudaGridSize, cudaBlockSize, sharedMemory >>>
( kernel_graph,
kernel_testResult );
CPPUNIT_ASSERT( tnlCuda::passFromDevice( kernel_testResult ) );
tnlCuda::freeFromDevice( kernel_graph );
tnlCuda::freeFromDevice( kernel_testResult );
checkCudaDevice;
#endif
}
for( int i = 0; i < 10; i++ )
for( int j = 0; j < 10; j++ )
if( j <= i )
CPPUNIT_ASSERT( m.getElement( i, j ) == i + j );
else
CPPUNIT_ASSERT( m.getElement( i, j ) == 0 );
m.reset();
m.setDimensions( 10, 10 );
m.setCompressedRowsLengths( rowLengths );
if( DeviceType::DeviceType == ( int ) tnlHostDevice )
{
for( int i = 9; i >= 0; i-- )
{
for( int j = i; j >= 0; j-- )
values[ j ] = i + j;
m.setRowFast( i, columnIndexes, values, i + 1 );
}
}
if( DeviceType::DeviceType == ( int ) tnlCudaDevice )
{
#ifdef HAVE_CUDA
IndexMultimapType* kernel_graph = tnlCuda::passToDevice( m );
bool testResult( true );
bool* kernel_testResult = tnlCuda::passToDevice( testResult );
checkCudaDevice;
dim3 cudaBlockSize( 256 ), cudaGridSize( 1 );
int sharedMemory = 100 * ( sizeof( IndexType ) + sizeof( RealType ) );
tnlIndexMultimapTester__setRowFast_LowerTriangularIndexMultimapTestCudaKernel< IndexMultimapType >
<<< cudaGridSize, cudaBlockSize, sharedMemory >>>
( kernel_graph,
kernel_testResult );
CPPUNIT_ASSERT( tnlCuda::passFromDevice( kernel_testResult ) );
tnlCuda::freeFromDevice( kernel_graph );
tnlCuda::freeFromDevice( kernel_testResult );
checkCudaDevice;
#endif
}
for( int i = 0; i < 10; i++ )
for( int j = 0; j < 10; j++ )
if( j <= i )
CPPUNIT_ASSERT( m.getElement( i, j ) == i + j );
else
CPPUNIT_ASSERT( m.getElement( i, j ) == 0 );
}
void vectorProduct_DiagonalIndexMultimapTest()
{
const int size = 10;
VectorType v, w;
v.setSize( size );
w.setSize( size );
IndexMultimapType m;
IndexMultimapSetter::setup( m );
m.setDimensions( size, size );
IndexVector rowLengths;
rowLengths.setSize( m.getRows() );
rowLengths.setValue( 7 );
m.setCompressedRowsLengths( rowLengths );
for( int i = 0; i < size; i++ )
{
v.setElement( i, i );
m.setElement( i, i, i );
}
m.vectorProduct( v, w );
for( int i = 0; i < size; i++ )
CPPUNIT_ASSERT( w.getElement( i ) == i*i );
}
void vectorProduct_DenseIndexMultimapTest()
{
const int size = 10;
VectorType v, w;
v.setSize( size );
w.setSize( size );
IndexMultimapType m;
IndexMultimapSetter::setup( m );
m.setDimensions( size, size );
IndexVector rowLengths;
rowLengths.setSize( m.getRows() );
rowLengths.setValue( size );
m.setCompressedRowsLengths( rowLengths );
for( int i = 0; i < size; i++ )
{
for( int j = 0; j < size; j++ )
m.setElement( i, j, i );
v.setElement( i, 1 );
}
m.vectorProduct( v, w );
for( int i = 0; i < size; i++ )
CPPUNIT_ASSERT( w.getElement( i ) == i*size );
}
void vectorProduct_LowerTriangularIndexMultimapTest()
{
const int size = 10;
VectorType v, w;
v.setSize( size );
w.setSize( size );
IndexMultimapType m;
IndexMultimapSetter::setup( m );
m.setDimensions( size, size );
IndexVector rowLengths;
rowLengths.setSize( m.getRows() );
rowLengths.setValue( size );
m.setCompressedRowsLengths( rowLengths );
for( int i = 0; i < size; i++ )
{
for( int j = 0; j <= i; j++ )
m.setElement( i, j, i );
v.setElement( i, 1 );
}