Mila
Deep Neural Network Library
Loading...
Searching...
No Matches
TensorOps.Random.ixx File Reference

Device-dispatching random initialization for tensors. More...

#include <concepts>
#include <span>
#include <cstdint>
#include <cmath>
import Compute.DeviceType;
import Compute.ExecutionContext;
import Dnn.TensorOps.Base;
import Dnn.TensorDataTypeTraits;
import Dnn.TensorDataType;
import Dnn.TensorTypes;
import Dnn.Tensor;

Namespaces

namespace  Mila
 Mila main API namespace.

Functions

template<TensorDataType TDataType, typename TMemoryResource>
requires isValidTensor<TDataType, TMemoryResource>
void Mila::Dnn::fill_normal (Tensor< TDataType, TMemoryResource > &tensor, float mean, float stddev, IExecutionContext *exec_context=nullptr)
template<TensorDataType TDataType, typename TMemoryResource>
requires isValidTensor<TDataType, TMemoryResource>
void Mila::Dnn::fill_uniform (Tensor< TDataType, TMemoryResource > &tensor, host_value_t< TDataType > min_val, host_value_t< TDataType > max_val, IExecutionContext *exec_context=nullptr)
template<TensorDataType TDataType, typename TMemoryResource>
requires isValidTensor<TDataType, TMemoryResource> && TensorDataTypeTraits<TDataType>::is_float_type
void Mila::Dnn::xavier (Tensor< TDataType, TMemoryResource > &tensor, dim_t fan_in, dim_t fan_out, IExecutionContext *exec_context=nullptr)
 Xavier/Glorot uniform initialization: U(-limit, limit), limit = sqrt(6 / (fan_in + fan_out)).

Detailed Description

Device-dispatching random initialization for tensors.

Provides fill_normal and fill_uniform entry points, forwarding to device-specific implementations (CPU, CUDA). For CUDA, uses cuRAND for efficient device-side fill.

Function Documentation

◆ xavier()

template<TensorDataType TDataType, typename TMemoryResource>
requires isValidTensor<TDataType, TMemoryResource> && TensorDataTypeTraits<TDataType>::is_float_type
void Mila::Dnn::xavier ( Tensor< TDataType, TMemoryResource > & tensor,
dim_t fan_in,
dim_t fan_out,
IExecutionContext * exec_context = nullptr )
export

Xavier/Glorot uniform initialization: U(-limit, limit), limit = sqrt(6 / (fan_in + fan_out)).

Convenience over fill_uniform that computes the Glorot bound. Device-agnostic; dispatches through fill_uniform to the backend RandomOps.