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

High-level initializer helpers (device-dispatching) for tensors. More...

#include <concepts>
#include <memory>
#include <span>
#include <type_traits>
#include <cstdint>
import Compute.ExecutionContext;
import Dnn.TensorDataTypeTraits;
import Compute.DeviceType;
import Dnn.TensorOps.Base;
import Dnn.TensorDataTypeMap;
import Dnn.TensorDataType;
import Dnn.Tensor;

Namespaces

namespace  Mila
 Mila main API namespace.
namespace  Mila::Dnn

Functions

template<TensorDataType TDataType, typename TMemoryResource>
requires isValidTensor<TDataType, TMemoryResource>
void Mila::Dnn::fill (Tensor< TDataType, TMemoryResource > &tensor, host_value_t< TDataType > host_value, IExecutionContext *exec_context=nullptr)
 Fill a tensor with a scalar host value (device-dispatched) with optional ExecutionContext.
template<TensorDataType TDataType, typename TMemoryResource>
requires isValidTensor<TDataType, TMemoryResource>
void Mila::Dnn::fill (Tensor< TDataType, TMemoryResource > &tensor, std::span< const host_value_t< TDataType > > host_values, IExecutionContext *exec_context=nullptr)
 Copy host values into a tensor with device dispatch and optional ExecutionContext.

Detailed Description

High-level initializer helpers (device-dispatching) for tensors.

This partition provides the generic, device-agnostic entry points for tensor initialization operations (copying host-provided values into tensors and filling tensors with scalar values). The implementation forwards to the device-specific TensorOps<...> partitions (for example TensorOps<Compute::CpuComputeDeviceTag>::fill(...)).

The host representation for a logical tensor element is defined by TensorDataTypeTraits<TDataType>::host_type and is exposed here via the alias host_value_t<TDataType> so callers and implementations use a single, authoritative host-side type for conversions.

ExecutionContext handling:

  • Optional ExecutionContext parameter for stream control (borrowed, not owned)
  • When provided, operations use the context's stream (caller controls sync)
  • When null, operations use default stream and synchronize before returning
  • Raw pointer semantics ensure zero overhead

Usage:

  • Call fill(tensor, values) or fill(tensor, scalar) from user code.
  • Optionally provide ExecutionContext for explicit stream control: fill(tensor, values, ctx.get())
  • The host value type is selected automatically from the tensor data type (float for floating-point tensors, int32_t for integer tensors).

Preconditions:

  • The isValidTensor<TDataType,TMemoryResource> concept must hold for the tensor types used here (ensures memory resource compatibility and trait availability).
  • ExecutionContext (if provided) must outlive the function call.