|
Mila
Deep Neural Network Library
|
Core shape, stride, and index types for the Mila tensor API. More...
#include <array>#include <string>#include <cstdint>#include <limits>#include <stdexcept>#include <algorithm>#include <initializer_list>Classes | |
| struct | Mila::Dnn::TensorShape |
| Fixed-capacity inline shape descriptor for N-dimensional tensors. More... | |
Namespaces | |
| namespace | Mila |
| Mila main API namespace. | |
Typedefs | |
| using | Mila::Dnn::dim_t = int64_t |
| Integer type used for tensor dimensions and indices. | |
| using | Mila::Dnn::index_t = TensorShape |
| Index descriptor for multi-dimensional element access. | |
| using | Mila::Dnn::shape_t = TensorShape |
| Row-major shape descriptor for tensor dimensional sizes. | |
| using | Mila::Dnn::stride_t = TensorShape |
| Stride descriptor (in elements) for each tensor dimension, row-major layout. | |
Functions | |
| constexpr dim_t | Mila::Dnn::elementCount (const shape_t &shape) noexcept |
| Product of a shape's extents – the number of logical elements it describes. | |
| std::string | Mila::Dnn::indexToString (const index_t &index) |
| int | Mila::Dnn::narrowToKernelIndex (dim_t value) |
| Narrow a dim_t to the 32-bit index type used inside device kernels. | |
| std::string | Mila::Dnn::shapeToString (const shape_t &shape) |
| std::string | Mila::Dnn::strideToString (const stride_t &stride) |
Core shape, stride, and index types for the Mila tensor API.
Defines TensorShape – a fixed-capacity inline shape descriptor – and the shape_t, stride_t, and index_t aliases used throughout the framework.
|
export |
Index descriptor for multi-dimensional element access.
One index per tensor dimension. Valid indices satisfy: 0 <= index[i] < shape[i].
|
export |
Row-major shape descriptor for tensor dimensional sizes.
A zero in any position indicates an empty tensor.
|
export |
Stride descriptor (in elements) for each tensor dimension, row-major layout.
stride_t[i] is the element count to advance one step along dimension i. Length equals shape.size(); empty for scalars.
|
constexprexportnoexcept |
Product of a shape's extents – the number of logical elements it describes.
Distinct from TensorShape::size(), which is the rank. A rank-0 shape holds one element, so the empty product of 1 is the correct answer rather than a special case.
|
inlineexport |
Narrow a dim_t to the 32-bit index type used inside device kernels.
dim_t is the type of every axis extent, position, and element count at the API, component, and operation-interface layers. Kernels index in 32-bit for register pressure and address-arithmetic cost, so exactly one narrowing point exists per call path: the operation that launches the kernel. Routing that narrowing through this function keeps the membrane greppable and gives the out-of-range case a diagnosable failure instead of a silent wrap.
The check is host-side and runs once per launch, not per element – negligible against launch overhead. The margin is not theoretical: a Gemma 4 12B embedding table is 262144 x 3840 ~ 1.0e9 elements, roughly half of INT_MAX.
| std::out_of_range | if the value does not fit in an int. |