NMath User's Guide

TOC | Previous | Next | Index

39.5 GPU Logging (.NET, C#, CSharp, VB, Visual Basic, F#)

NMath Premium automatically detects the presence of a CUDA-enabled GPU at runtime and redirects appropriate computations to it. You can examine a history of this routing process by enabling GPU logging. If logging is enabled, classes that contain GPU-enabled operations log where the operations are executed (GPU or CPU), and why. This can be especially useful is debugging.

NOTE—GPU logging should not be used in production, as it greatly reduces performance.

The EnableLogging() method on the BridgeManager accepts a path to a log file, and an optional boolean value. If true, log entries are appended to the given log file; otherwise, an existing log file is overwritten.

Code Example – C# GPU Logging

string path = @"C:\tmp\MyBridge.log";
bool append = false;
BridgeManager.Instance.EnableLogging( path, append );

Code Example – VB GPU Logging

Dim Path As String = "C:\tmp\MyBridge.log"
Dim Append As Boolean = False
BridgeManager.Instance.EnableLogging( Path, Append )

EnableLogging() also accepts a TextWriter.

Code Example – C# GPU Logging

using ( var writer = new StringWriter() )
{
  BridgeManager.Instance.EnableLogging( writer );
  // Do something here
}

Code Example – VB GPU Logging

Using Writer As New StringWriter()
  BridgeManager.Instance.EnableLogging( Writer )
  ' Do something here
End Using

For example, the following log shows two general matrix multiplications. The first, multiplying two 100 x 100 matrices, is below threshold and issued to the CPU to be performed by MKL. The second, multiplying two 1000 x 1000 matrices, is over threshold and issued to the GPU to be performed by CUDA libraries.

2014-07-10 08:33:04.795 AM 13 0 dgemm CPU Below threshold ;
  size n x m 100x100 = 10000 < 490000 (crossover 700)
2014-07-10 08:33:04.959 AM 13 0 dgemm GPU Above threshold ;
  size n x m 1000x1000 = 1000000 >= 490000 (crossover 700)

The log entries include the operation time, the thread ID (13 in this case), the device ID, the bridge function being executed, the routing destination, and a description of the routing decision. The fields are tab-delimited.

You can use the IsLoggingEnabled property the BridgeManager to check whether GPU logging is currently enabled, and the DisableLogging() method to disable logging.

Code Example – C# GPU Logging

if ( BridgeManager.Instance.IsLoggingEnabled )
{
  BridgeManager.Instance.DisableLogging();
}

Code Example – VB GPU Logging

If ( BridgeManager.Instance.IsLoggingEnabled ) Then
  BridgeManager.Instance.DisableLogging()
End If

Top

Top