My Project
Public Member Functions | List of all members
cuda_mlp::CudaNetwork Class Reference

Feed-forward dense network with GPU-backed parameters and gradients. More...

Public Member Functions

 CudaNetwork (CublasHandle &handle)
 Construct a network tied to a cuBLAS handle. More...
 
void addLayer (int in, int out, ActivationType act)
 Append a layer definition. More...
 
void bindParams (unsigned int seed=kDefaultSeed)
 Allocate parameter/gradient buffers and initialize weights. More...
 
size_t params_size () const
 Total number of parameters. More...
 
int output_size () const
 Output dimension of the last layer. More...
 
CudaScalarparams_data ()
 Mutable device pointer to parameters. More...
 
CudaScalargrads_data ()
 Mutable device pointer to gradients. More...
 
void zeroGrads ()
 Zero all gradients. More...
 
void forward_only (const CudaScalar *input, int batch)
 Forward pass only (no gradient computation) More...
 
CudaScalar compute_loss_and_grad (const CudaScalar *input, const CudaScalar *target, int batch)
 Compute MSE loss and gradients for a batch. More...
 
void copy_output_to_host (CudaScalar *host, size_t n) const
 Copy the latest output activations to host memory. More...
 
int last_batch () const
 Batch size used in the last forward pass. More...
 

Detailed Description

Feed-forward dense network with GPU-backed parameters and gradients.

Constructor & Destructor Documentation

◆ CudaNetwork()

cuda_mlp::CudaNetwork::CudaNetwork ( CublasHandle handle)
inlineexplicit

Construct a network tied to a cuBLAS handle.

Member Function Documentation

◆ addLayer()

void cuda_mlp::CudaNetwork::addLayer ( int  in,
int  out,
ActivationType  act 
)
inline

Append a layer definition.

Parameters
inInput dimension
outOutput dimension
actActivation function

◆ bindParams()

void cuda_mlp::CudaNetwork::bindParams ( unsigned int  seed = kDefaultSeed)
inline

Allocate parameter/gradient buffers and initialize weights.

Parameters
seedRNG seed for weight initialization
Here is the call graph for this function:

◆ compute_loss_and_grad()

CudaScalar cuda_mlp::CudaNetwork::compute_loss_and_grad ( const CudaScalar input,
const CudaScalar target,
int  batch 
)
inline

Compute MSE loss and gradients for a batch.

Parameters
inputInput batch (in x batch)
targetTarget batch (out x batch)
batchBatch size
Returns
Mean squared error loss
Here is the call graph for this function:

◆ copy_output_to_host()

void cuda_mlp::CudaNetwork::copy_output_to_host ( CudaScalar host,
size_t  n 
) const
inline

Copy the latest output activations to host memory.

◆ forward_only()

void cuda_mlp::CudaNetwork::forward_only ( const CudaScalar input,
int  batch 
)
inline

Forward pass only (no gradient computation)

Parameters
inputInput batch (in x batch)
batchBatch size
Here is the caller graph for this function:

◆ grads_data()

CudaScalar* cuda_mlp::CudaNetwork::grads_data ( )
inline

Mutable device pointer to gradients.

Here is the call graph for this function:

◆ last_batch()

int cuda_mlp::CudaNetwork::last_batch ( ) const
inline

Batch size used in the last forward pass.

◆ output_size()

int cuda_mlp::CudaNetwork::output_size ( ) const
inline

Output dimension of the last layer.

Here is the caller graph for this function:

◆ params_data()

CudaScalar* cuda_mlp::CudaNetwork::params_data ( )
inline

Mutable device pointer to parameters.

Here is the call graph for this function:

◆ params_size()

size_t cuda_mlp::CudaNetwork::params_size ( ) const
inline

Total number of parameters.

◆ zeroGrads()

void cuda_mlp::CudaNetwork::zeroGrads ( )
inline

Zero all gradients.

Here is the call graph for this function:
Here is the caller graph for this function:

The documentation for this class was generated from the following file: