Skip to content
Snippets Groups Projects
Commit 929e524c authored by Jakub Klinkovský's avatar Jakub Klinkovský
Browse files

Benchmarks: include error messages in the log file

parent 41284115
No related branches found
No related tags found
No related merge requests found
...@@ -24,12 +24,16 @@ benchmarkArrayOperations( Benchmark & benchmark, ...@@ -24,12 +24,16 @@ benchmarkArrayOperations( Benchmark & benchmark,
HostArray hostArray, hostArray2; HostArray hostArray, hostArray2;
CudaArray deviceArray, deviceArray2; CudaArray deviceArray, deviceArray2;
hostArray.setSize( size ); if( ! hostArray.setSize( size ) ||
if( ! deviceArray.setSize( size ) ) ! hostArray2.setSize( size ) ||
return false; ! deviceArray.setSize( size ) ||
hostArray2.setLike( hostArray ); ! deviceArray2.setSize( size ) )
if( ! deviceArray2.setLike( deviceArray ) ) {
const char* msg = "error: allocation of arrays failed";
cerr << msg << endl;
benchmark.addErrorMessage( msg );
return false; return false;
}
Real resultHost, resultDevice; Real resultHost, resultDevice;
......
...@@ -174,11 +174,52 @@ public: ...@@ -174,11 +174,52 @@ public:
} }
} }
void
writeErrorMessage( const char* msg,
const int & colspan = 1 )
{
// initial indent string
header_indent = "!";
log << endl;
for( auto & it : metadataColumns ) {
log << header_indent << " " << it.first << endl;
}
// make sure there is a header column for the message
if( horizontalGroups.size() == 0 )
horizontalGroups.push_back( {"", 1} );
// dump stacked spanning columns
while( horizontalGroups.back().second <= 0 ) {
horizontalGroups.pop_back();
header_indent.pop_back();
}
for( int i = 0; i < horizontalGroups.size(); i++ ) {
if( horizontalGroups[ i ].second > 0 ) {
log << header_indent << " " << horizontalGroups[ i ].first << endl;
header_indent += "!";
}
}
if( horizontalGroups.size() > 0 ) {
horizontalGroups.back().second -= colspan;
header_indent.pop_back();
}
// only when changed (the header has been already adjusted)
// print each element on separate line
for( auto & it : metadataColumns ) {
log << it.second << endl;
}
log << msg << endl;
}
void void
closeTable() closeTable()
{ {
log << endl;
header_indent = body_indent = ""; header_indent = body_indent = "";
header_changed = true; header_changed = true;
horizontalGroups.clear();
} }
bool save( std::ostream & logFile ) bool save( std::ostream & logFile )
...@@ -186,7 +227,7 @@ public: ...@@ -186,7 +227,7 @@ public:
closeTable(); closeTable();
logFile << log.str(); logFile << log.str();
if( logFile.good() ) { if( logFile.good() ) {
log.str() =""; log.str() = "";
return true; return true;
} }
return false; return false;
...@@ -361,6 +402,17 @@ public: ...@@ -361,6 +402,17 @@ public:
return this->baseTime; return this->baseTime;
} }
// Adds an error message to the log. Should be called in places where the
// "time" method could not be called (e.g. due to failed allocation).
void
addErrorMessage( const char* msg,
const int & numberOfComputations = 1 )
{
// each computation has 3 subcolumns
const int colspan = 3 * numberOfComputations;
writeErrorMessage( msg, colspan );
}
using Logging::save; using Logging::save;
protected: protected:
......
...@@ -253,7 +253,7 @@ class logToHtmlConvertor: ...@@ -253,7 +253,7 @@ class logToHtmlConvertor:
elements = [line.strip() for line in body] elements = [line.strip() for line in body]
if len(elements) != len(leafColumns): if len(elements) != len(leafColumns):
raise Exception("Error in the table format: header has {} leaf columns, but the corresponding row has {} elements.".format(len(leafColumns), len(row))) raise Exception("Error in the table format: header has {} leaf columns, but the corresponding row has {} elements.".format(len(leafColumns), len(elements)))
row = collections.OrderedDict() row = collections.OrderedDict()
for element, column in zip(elements, leafColumns): for element, column in zip(elements, leafColumns):
......
...@@ -90,8 +90,8 @@ void setCudaTestMatrix( Matrix& matrix, ...@@ -90,8 +90,8 @@ void setCudaTestMatrix( Matrix& matrix,
if( gridIdx == cudaGrids - 1 ) if( gridIdx == cudaGrids - 1 )
cudaGridSize.x = cudaBlocks % tnlCuda::getMaxGridSize(); cudaGridSize.x = cudaBlocks % tnlCuda::getMaxGridSize();
setCudaTestMatrixKernel< Matrix > setCudaTestMatrixKernel< Matrix >
<<< cudaGridSize, cudaBlockSize >>> <<< cudaGridSize, cudaBlockSize >>>
( kernel_matrix, elementsPerRow, gridIdx ); ( kernel_matrix, elementsPerRow, gridIdx );
checkCudaDevice; checkCudaDevice;
} }
tnlCuda::freeFromDevice( kernel_matrix ); tnlCuda::freeFromDevice( kernel_matrix );
...@@ -119,6 +119,11 @@ benchmarkSpMV( Benchmark & benchmark, ...@@ -119,6 +119,11 @@ benchmarkSpMV( Benchmark & benchmark,
HostVector hostVector, hostVector2; HostVector hostVector, hostVector2;
CudaVector deviceVector, deviceVector2; CudaVector deviceVector, deviceVector2;
// create benchmark group
tnlList< tnlString > parsedType;
parseObjectType( HostMatrix::getType(), parsedType );
benchmark.createHorizontalGroup( parsedType[ 0 ], 2 );
if( ! hostRowLengths.setSize( size ) || if( ! hostRowLengths.setSize( size ) ||
! deviceRowLengths.setSize( size ) || ! deviceRowLengths.setSize( size ) ||
! hostMatrix.setDimensions( size, size ) || ! hostMatrix.setDimensions( size, size ) ||
...@@ -128,7 +133,9 @@ benchmarkSpMV( Benchmark & benchmark, ...@@ -128,7 +133,9 @@ benchmarkSpMV( Benchmark & benchmark,
! deviceVector.setSize( size ) || ! deviceVector.setSize( size ) ||
! deviceVector2.setSize( size ) ) ! deviceVector2.setSize( size ) )
{ {
cerr << "Unable to allocate all matrices and vectors for the SpMV benchmark." << endl; const char* msg = "error: allocation of vectors failed";
cerr << msg << endl;
benchmark.addErrorMessage( msg, 2 );
return false; return false;
} }
...@@ -137,19 +144,19 @@ benchmarkSpMV( Benchmark & benchmark, ...@@ -137,19 +144,19 @@ benchmarkSpMV( Benchmark & benchmark,
if( ! hostMatrix.setCompressedRowsLengths( hostRowLengths ) ) if( ! hostMatrix.setCompressedRowsLengths( hostRowLengths ) )
{ {
cerr << "Unable to allocate host matrix elements." << endl; const char* msg = "error: allocation of host matrix failed";
cerr << msg << endl;
benchmark.addErrorMessage( msg, 2 );
return false; return false;
} }
if( ! deviceMatrix.setCompressedRowsLengths( deviceRowLengths ) ) if( ! deviceMatrix.setCompressedRowsLengths( deviceRowLengths ) )
{ {
cerr << "Unable to allocate device matrix elements." << endl; const char* msg = "error: allocation of device matrix failed";
cerr << msg << endl;
benchmark.addErrorMessage( msg, 2 );
return false; return false;
} }
tnlList< tnlString > parsedType;
parseObjectType( HostMatrix::getType(), parsedType );
benchmark.createHorizontalGroup( parsedType[ 0 ], 2 );
const int elements = setHostTestMatrix< HostMatrix >( hostMatrix, elementsPerRow ); const int elements = setHostTestMatrix< HostMatrix >( hostMatrix, elementsPerRow );
setCudaTestMatrix< DeviceMatrix >( deviceMatrix, elementsPerRow ); setCudaTestMatrix< DeviceMatrix >( deviceMatrix, elementsPerRow );
const double datasetSize = loops * elements * ( 2 * sizeof( Real ) + sizeof( int ) ) / oneGB; const double datasetSize = loops * elements * ( 2 * sizeof( Real ) + sizeof( int ) ) / oneGB;
......
...@@ -28,12 +28,16 @@ benchmarkVectorOperations( Benchmark & benchmark, ...@@ -28,12 +28,16 @@ benchmarkVectorOperations( Benchmark & benchmark,
HostVector hostVector, hostVector2; HostVector hostVector, hostVector2;
CudaVector deviceVector, deviceVector2; CudaVector deviceVector, deviceVector2;
hostVector.setSize( size ); if( ! hostVector.setSize( size ) ||
if( ! deviceVector.setSize( size ) ) ! hostVector2.setSize( size ) ||
return false; ! deviceVector.setSize( size ) ||
hostVector2.setLike( hostVector ); ! deviceVector2.setSize( size ) )
if( ! deviceVector2.setLike( deviceVector ) ) {
const char* msg = "error: allocation of vectors failed";
cerr << msg << endl;
benchmark.addErrorMessage( msg );
return false; return false;
}
Real resultHost, resultDevice; Real resultHost, resultDevice;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment