|
Mila
Deep Neural Network Library
|
High-level initializer helpers (device-dispatching) for tensors. More...
#include <concepts>#include <memory>#include <span>#include <type_traits>#include <cstdint>import Compute.DeviceType;import Compute.ExecutionContext;import Dnn.TensorDataTypeTraits;import Dnn.TensorDataTypeMap;import Dnn.TensorOps.Base;import Dnn.TensorDataType;import Dnn.Tensor;Namespaces | |
| namespace | Mila |
| Mila main API namespace. | |
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. | |
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:
Usage:
Preconditions:
|
export |
Fill a tensor with a scalar host value (device-dispatched) with optional ExecutionContext.
Forwards scalar fills to the device-specific TensorOps<Tag>::fill. Borrows execution context for stream control with zero overhead. The function signature enforces the expected host scalar representation for each abstract tensor data type via host_value_t<TDataType>.
| TDataType | Abstract tensor data type. |
| TMemoryResource | Memory resource type backing the tensor. |
| tensor | Destination tensor to be filled. Must satisfy isValidTensor. |
| host_value | Scalar value in host representation to broadcast to the tensor. |
| exec_context | Optional execution context for stream control (borrowed, not owned) |
Example:
|
export |
Copy host values into a tensor with device dispatch and optional ExecutionContext.
Forwards the host->tensor copy operation (span form) to the device-specific implementation TensorOps<Tag>::fill. Borrows execution context for stream control with zero overhead. Falls back to default stream when no context provided.
The host element type is selected by host_value_t<TDataType> so callers must provide values in the expected host representation (float for floating-point tensor types, int32_t for integer tensor types). The device implementation performs any necessary conversion/quantization.
| TDataType | Abstract tensor data type. |
| TMemoryResource | Memory resource type backing the tensor. |
| tensor | Destination tensor to be filled. Must satisfy isValidTensor. |
| host_values | Span of host values in host representation (see host_value_t). |
| exec_context | Optional execution context for stream control (borrowed, not owned) |
Example: