Table of Contents

Class GpuPINNTrainer<T>

Namespace
AiDotNet.PhysicsInformed
Assembly
AiDotNet.dll

Provides GPU-accelerated training for Physics-Informed Neural Networks.

public class GpuPINNTrainer<T>

Type Parameters

T

The numeric type used for calculations.

Inheritance
GpuPINNTrainer<T>
Inherited Members

Remarks

For Beginners: This trainer provides GPU-accelerated training methods for PINNs. It can significantly speed up training by:

  1. Processing large batches of collocation points in parallel
  2. Performing matrix operations on the GPU
  3. Using asynchronous data transfers to overlap computation

Usage:

var trainer = new GpuPINNTrainer<double>(myPinn);
var history = trainer.Train(epochs: 10000, options: GpuPINNTrainingOptions.Default);

The trainer automatically falls back to CPU if GPU is not available.

Constructors

GpuPINNTrainer(PhysicsInformedNeuralNetwork<T>, GpuPINNTrainingOptions?)

Initializes a new instance of the GPU PINN trainer.

public GpuPINNTrainer(PhysicsInformedNeuralNetwork<T> pinn, GpuPINNTrainingOptions? options = null)

Parameters

pinn PhysicsInformedNeuralNetwork<T>

The Physics-Informed Neural Network to train.

options GpuPINNTrainingOptions

Optional GPU training options.

Properties

IsUsingGpu

Gets whether GPU is currently being used for training.

public bool IsUsingGpu { get; }

Property Value

bool

Network

Gets the underlying PINN being trained.

public PhysicsInformedNeuralNetwork<T> Network { get; }

Property Value

PhysicsInformedNeuralNetwork<T>

Options

Gets the current training options.

public GpuPINNTrainingOptions Options { get; }

Property Value

GpuPINNTrainingOptions

Methods

EvaluateLoss(Tensor<T>, Tensor<T>?)

Performs a forward pass and computes loss (does not update weights).

public T EvaluateLoss(Tensor<T> batchInputs, Tensor<T>? batchTargets = null)

Parameters

batchInputs Tensor<T>

Batch of input points.

batchTargets Tensor<T>

Optional target values. If provided, computes MSE loss against outputs.

Returns

T

Loss value for this evaluation step.

Remarks

Note: This method only evaluates loss - it does not perform backpropagation or weight updates. Use the Train method for full training with gradient updates.

Exceptions

ArgumentNullException

Thrown when batchInputs is null.

ArgumentException

Thrown when batchTargets shape doesn't match outputs.

GetGpuMemoryInfo()

Gets GPU memory usage statistics.

public PINNGpuMemoryInfo? GetGpuMemoryInfo()

Returns

PINNGpuMemoryInfo

Memory usage info or null if GPU not in use.

Remarks

Limitations: DirectGpu backends do not provide a standard API to query current memory usage. The returned TotalMemoryBytes reflects the total GPU memory, but UsedMemoryBytes and AvailableMemoryBytes cannot be accurately tracked through the DirectGpu backend.

For accurate memory profiling, use external tools like NVIDIA's nvidia-smi, CUDA's nvml library, or Visual Studio's GPU profiler.

ReleaseGpuResources()

Releases GPU resources.

public void ReleaseGpuResources()

Train(T[,]?, T[,]?, int, double, bool)

Trains the PINN with GPU acceleration.

public GpuTrainingHistory<T> Train(T[,]? dataInputs = null, T[,]? dataOutputs = null, int epochs = 10000, double learningRate = 0.001, bool verbose = true)

Parameters

dataInputs T[,]

Optional measured input data.

dataOutputs T[,]

Optional measured output data.

epochs int

Number of training epochs.

learningRate double

Learning rate for optimization.

verbose bool

Whether to print progress.

Returns

GpuTrainingHistory<T>

Training history with loss values per epoch.

TryInitializeGpu()

Attempts to initialize GPU resources.

public bool TryInitializeGpu()

Returns

bool

True if GPU initialization was successful.

UpdateOptions(GpuPINNTrainingOptions)

Updates training options.

public void UpdateOptions(GpuPINNTrainingOptions options)

Parameters

options GpuPINNTrainingOptions

New options to apply.