39.6 Bridge Tuning (.NET, C#, CSharp, VB, Visual Basic, F#)
NMath Premium has a built-in default bridge, which has been pre-tuned to work reasonably well for common hardware. Larger problems are routed to the GPU, where there's typically a speed advantage, while smaller problems are retained on the CPU. In these cases, it is not worth incurring the data transfer time to the GPU.
However, to get the most out of your available hardware, or your users' hardware, you can explicitly tune a bridge for optimal performance. The tuning process performs a series of sample timings on your hardware, models the performance, and infers an optimal routing from the model.
You can tune either an individual bridge function, or all functions.
Code Example – C# GPU bridge tuning
var device = BridgeManager.Instance.GetComputeDevice( 0 ); var bridge = BridgeManager.Instance.NewDefaultBridge( device ); int maxProblemSize = 1200; bridge.Tune( BridgeFunctions.dgemm, device, maxProblemSize );
Code Example – VB GPU bridge tuning
Dim Device = BridgeManager.Instance.GetComputeDevice( 0 ) Dim Bridge = BridgeManager.Instance.NewDefaultBridge( Device ) Dim MaxProblemSize As Integer = 1200 Bridge.Tune( BridgeFunctions.dgemm, Device, MaxProblemSize )
TuneAll() tunes the routing model for a given device for all GPU-aware functions.
Depending on the hardware, tuning parameters, and the number of bridge functions tuned, tuning can be an expensive operation. However, it only needs to be performed once for a particular CPU/GPU combination. Once a bridge is tuned it can be persisted, redistributed, and used again (Section 39.7).
A tuning is valid for a particular CPU/GPU combination. If three different GPUs are installed, tuning should be done once for each GPU, and then each bridge should be assigned to the device on which it was tuned. If there are three identical GPUs, the tuning can be done once, and later assigned to all identical GPUs.
Method RestoreDefaultRouting() restores the routing for a bridge to the default state.