incin-core 0.1.0

Core tensor operations and static shape checking for incin
Documentation
//! The single declaration of stable semantic operations.
//!
//! The callback macro is intentionally data-only.  `shapes::error` uses it to
//! generate the exact diagnostic identity, while `exec::catalog` uses the same
//! rows to generate typed descriptor markers and the reviewed inventory.  A
//! backend declaration macro consumes the resulting identities when it couples
//! `Execute<O>` implementations to capability rows.

macro_rules! incin_operation_catalog {
    ($callback:ident) => {
        $callback! {
            // identity, spelling, family, semantic profile, typed attributes, min/max arity, legacy source
            (TensorFromData, "tensor_from_data", Storage, Creation, DataAttributes, 0, 0, "TensorArgsData"),
            (TensorFromBytes, "tensor_from_bytes", Storage, Creation, DataAttributes, 0, 0, "Tensor::from_bytes"),
            (TensorToBytes, "tensor_to_bytes", Storage, Transfer, NoAttributes, 1, 1, "Tensor::to_bytes"),
            (Zeros, "zeros", Fill, Creation, CreationAttributes, 0, 0, "Descriptor<op::Zeros>"),
            (Ones, "ones", Fill, Creation, CreationAttributes, 0, 0, "Descriptor<op::Ones>"),
            (UniformRandom, "rand", Random, Creation, CreationAttributes, 0, 0, "Descriptor<op::UniformRandom>"),
            (NormalRandom, "randn", Random, Creation, CreationAttributes, 0, 0, "Descriptor<op::NormalRandom>"),
            (VariableZeros, "var_zeros", Fill, Creation, CreationAttributes, 0, 0, "Descriptor<op::VariableZeros>"),
            (VariableOnes, "var_ones", Fill, Creation, CreationAttributes, 0, 0, "Descriptor<op::VariableOnes>"),
            (VariableUniformRandom, "var_rand", Random, Creation, CreationAttributes, 0, 0, "Descriptor<op::VariableUniformRandom>"),
            (VariableNormalRandom, "var_randn", Random, Creation, CreationAttributes, 0, 0, "Descriptor<op::VariableNormalRandom>"),
            (Full, "full", Fill, Creation, FullAttributes, 0, 0, "Descriptor<op::Full>"),
            (Arange, "arange", Fill, Creation, ArangeAttributes, 0, 0, "Descriptor<op::Arange>"),
            (Linspace, "linspace", Fill, Creation, LinspaceAttributes, 0, 0, "Descriptor<op::Linspace>"),
            (Sample, "sample", Random, Creation, DistributionAttributes, 0, 0, "Tensor::sample"),

            (Relu, "relu", Pointwise, UnaryFloat, NoAttributes, 1, 1, "::relu"),
            (Step, "step", Pointwise, UnaryFloat, NoAttributes, 1, 1, "::step"),
            (Mish, "mish", Pointwise, UnaryFloat, NoAttributes, 1, 1, "::mish"),
            (Elu, "elu", Pointwise, UnaryFloat, NoAttributes, 1, 1, "::elu"),
            (Gelu, "gelu", Pointwise, UnaryFloat, NoAttributes, 1, 1, "::gelu"),
            (Abs, "abs", Pointwise, UnaryFloat, NoAttributes, 1, 1, "::abs"),
            (Exp, "exp", Pointwise, UnaryFloat, NoAttributes, 1, 1, "::exp"),
            (Neg, "neg", Pointwise, UnaryFloat, NoAttributes, 1, 1, "::neg"),
            (Sqrt, "sqrt", Pointwise, UnaryFloat, NoAttributes, 1, 1, "::sqrt"),
            (Log, "log", Pointwise, UnaryFloat, NoAttributes, 1, 1, "::log"),
            (Tanh, "tanh", Pointwise, UnaryFloat, NoAttributes, 1, 1, "::tanh"),
            (Sigmoid, "sigmoid", Pointwise, UnaryFloat, NoAttributes, 1, 1, "::sigmoid"),
            (Swish, "swish", Pointwise, UnaryFloat, NoAttributes, 1, 1, "::swish"),
            (Softmax, "softmax", Normalization, Normalization, AxisAttributes, 1, 1, "::softmax"),
            (AddScalar, "add_scalar", Pointwise, UnaryFloat, ScalarAttributes, 1, 1, "::add_scalar_float"),
            (MulScalar, "mul_scalar", Pointwise, UnaryFloat, ScalarAttributes, 1, 1, "::mul_scalar_float"),
            (Powf, "powf", Pointwise, UnaryFloat, ScalarAttributes, 1, 1, "::powf"),
            (Clamp, "clamp", Pointwise, UnaryFloat, ClampAttributes, 1, 1, "::clamp"),
            (Sign, "sign", Pointwise, UnaryFloat, NoAttributes, 1, 1, "::sign"),
            (Floor, "floor", Pointwise, UnaryFloat, NoAttributes, 1, 1, "::floor"),
            (Ceil, "ceil", Pointwise, UnaryFloat, NoAttributes, 1, 1, "::ceil"),
            (Round, "round", Pointwise, UnaryFloat, NoAttributes, 1, 1, "::round"),
            (Log2, "log2", Pointwise, UnaryFloat, NoAttributes, 1, 1, "::log2"),
            (Log10, "log10", Pointwise, UnaryFloat, NoAttributes, 1, 1, "::log10"),
            (Sin, "sin", Pointwise, UnaryFloat, NoAttributes, 1, 1, "::sin"),
            (Cos, "cos", Pointwise, UnaryFloat, NoAttributes, 1, 1, "::cos"),
            (Tan, "tan", Pointwise, UnaryFloat, NoAttributes, 1, 1, "::tan"),
            (Asin, "asin", Pointwise, UnaryFloat, NoAttributes, 1, 1, "::asin"),
            (Acos, "acos", Pointwise, UnaryFloat, NoAttributes, 1, 1, "::acos"),
            (Atan, "atan", Pointwise, UnaryFloat, NoAttributes, 1, 1, "::atan"),
            (Atan2, "atan2", Pointwise, BinaryBroadcast, NoAttributes, 2, 2, "::atan2"),
            (Sinh, "sinh", Pointwise, UnaryFloat, NoAttributes, 1, 1, "::sinh"),
            (Cosh, "cosh", Pointwise, UnaryFloat, NoAttributes, 1, 1, "::cosh"),
            (Asinh, "asinh", Pointwise, UnaryFloat, NoAttributes, 1, 1, "::asinh"),
            (Acosh, "acosh", Pointwise, UnaryFloat, NoAttributes, 1, 1, "::acosh"),
            (Atanh, "atanh", Pointwise, UnaryFloat, NoAttributes, 1, 1, "::atanh"),
            (Erf, "erf", Pointwise, UnaryFloat, NoAttributes, 1, 1, "::erf"),
            (Rsqrt, "rsqrt", Pointwise, UnaryFloat, NoAttributes, 1, 1, "::rsqrt"),
            (Trunc, "trunc", Pointwise, UnaryFloat, NoAttributes, 1, 1, "::trunc"),
            (Frac, "frac", Pointwise, UnaryFloat, NoAttributes, 1, 1, "::frac"),
            (Fmod, "fmod", Pointwise, BinaryBroadcast, NoAttributes, 2, 2, "::fmod"),
            (Remainder, "remainder", Pointwise, BinaryBroadcast, NoAttributes, 2, 2, "::remainder"),
            (Add, "add", Pointwise, BinaryBroadcast, NoAttributes, 2, 2, "::add"),
            (Sub, "sub", Pointwise, BinaryBroadcast, NoAttributes, 2, 2, "::sub"),
            (Mul, "mul", Pointwise, BinaryBroadcast, NoAttributes, 2, 2, "::mul"),
            (Div, "div", Pointwise, BinaryBroadcast, NoAttributes, 2, 2, "::div"),
            (SubScalar, "sub_scalar", Pointwise, UnaryFloat, ScalarAttributes, 1, 1, "::sub_scalar"),
            (DivScalar, "div_scalar", Pointwise, UnaryFloat, ScalarAttributes, 1, 1, "::div_scalar"),
            (Maximum, "maximum", Pointwise, BinaryBroadcast, NoAttributes, 2, 2, "::maximum"),
            (Minimum, "minimum", Pointwise, BinaryBroadcast, NoAttributes, 2, 2, "::minimum"),
            (AbsDiff, "abs_diff", Pointwise, BinaryBroadcast, NoAttributes, 2, 2, "::abs_diff"),
            (Lerp, "lerp", Pointwise, BinaryBroadcast, LerpAttributes, 2, 2, "::lerp"),
            (CmpEq, "cmp_eq", Pointwise, Comparison, NoAttributes, 2, 2, "::cmp_eq"),
            (CmpNe, "cmp_ne", Pointwise, Comparison, NoAttributes, 2, 2, "::cmp_ne"),
            (CmpLt, "cmp_lt", Pointwise, Comparison, NoAttributes, 2, 2, "::cmp_lt"),
            (CmpLe, "cmp_le", Pointwise, Comparison, NoAttributes, 2, 2, "::cmp_le"),
            (CmpGt, "cmp_gt", Pointwise, Comparison, NoAttributes, 2, 2, "::cmp_gt"),
            (CmpGe, "cmp_ge", Pointwise, Comparison, NoAttributes, 2, 2, "::cmp_ge"),
            (LogicalAnd, "logical_and", Pointwise, Logical, NoAttributes, 2, 2, "::logical_and"),
            (LogicalOr, "logical_or", Pointwise, Logical, NoAttributes, 2, 2, "::logical_or"),
            (LogicalNot, "logical_not", Pointwise, Logical, NoAttributes, 1, 1, "::logical_not"),
            (AddInPlace, "add_in_place", Pointwise, Mutation, NoAttributes, 2, 2, "Tensor::add_"),
            (SubInPlace, "sub_in_place", Pointwise, Mutation, NoAttributes, 2, 2, "Tensor::sub_"),
            (MulInPlace, "mul_in_place", Pointwise, Mutation, NoAttributes, 2, 2, "Tensor::mul_"),
            (DivInPlace, "div_in_place", Pointwise, Mutation, NoAttributes, 2, 2, "Tensor::div_"),
            (ZeroInPlace, "zero_in_place", Fill, Mutation, NoAttributes, 1, 1, "Tensor::zero_"),
            (FillInPlace, "fill_in_place", Fill, Mutation, ScalarAttributes, 1, 1, "Tensor::fill_"),

            (ReshapeExact, "reshape", Storage, Shape, ShapeAttributes, 1, 1, "::reshape"),
            (TransposeExact, "transpose", Storage, Shape, TransposeAttributes, 1, 1, "::transpose"),
            (MatMulExact, "matmul", Reduction, MatMul, NoAttributes, 2, 2, "::matmul"),
            (Dot, "dot", Reduction, MatMul, NoAttributes, 2, 2, "Tensor::dot"),
            (Outer, "outer", Reduction, MatMul, NoAttributes, 2, 2, "Tensor::outer"),
            (BroadcastAs, "broadcast_as", Storage, Shape, ShapeAttributes, 1, 1, "::broadcast_as"),
            (Narrow, "narrow", Storage, Shape, NarrowAttributes, 1, 1, "::narrow"),
            (SqueezeExact, "squeeze", Storage, Shape, AxisAttributes, 1, 1, "::squeeze"),
            (StackExact, "stack", Storage, Shape, AxisAttributes, 1, usize::MAX, "::stack"),
            (ConcatExact, "concat", Storage, Shape, AxisAttributes, 1, usize::MAX, "::concat"),
            (SliceExact, "slice", Storage, Shape, SliceAttributes, 1, 1, "::slice"),
            (FlattenExact, "flatten", Storage, Shape, FlattenAttributes, 1, 1, "::flatten"),
            (WhereCond, "where_cond", Pointwise, Selection, NoAttributes, 3, 3, "::where_cond"),
            (Gather, "gather", Storage, Indexing, AxisAttributes, 2, 2, "::gather"),
            (Scatter, "scatter", Storage, Indexing, ScatterAttributes, 3, 3, "::scatter"),
            (IndexSelect, "index_select", Storage, Indexing, AxisAttributes, 2, 2, "::index_select"),
            (MaskedFill, "masked_fill", Pointwise, Selection, ScalarAttributes, 2, 2, "::masked_fill"),
            (UnsqueezeExact, "unsqueeze", Storage, Shape, AxisAttributes, 1, 1, "::unsqueeze"),
            (Repeat, "repeat", Storage, Shape, RepeatAttributes, 1, 1, "::repeat"),
            (Pad, "pad", Storage, Shape, PadAttributes, 1, 1, "::pad"),
            (Triu, "triu", Storage, Shape, DiagonalAttributes, 1, 1, "::triu"),
            (Tril, "tril", Storage, Shape, DiagonalAttributes, 1, 1, "::tril"),
            (Diag, "diag", Storage, Shape, DiagonalAttributes, 1, 1, "::diag"),
            (Chunk, "chunk", Storage, Shape, ChunkAttributes, 1, 1, "Tensor::chunk"),
            (Split, "split", Storage, Shape, SplitAttributes, 1, 1, "Tensor::split"),
            (Addmm, "addmm", Reduction, MatMul, AddmmAttributes, 3, 3, "::addmm"),
            (BatchedMatMul, "bmm", Reduction, MatMul, NoAttributes, 2, 2, "::bmm"),
            (ScaledDotProductAttention, "scaled_dot_product_attention", Reduction, Attention, AttentionAttributes, 3, 4, "::scaled_dot_product_attention"),
            (Unfold, "unfold", Storage, Shape, UnfoldAttributes, 1, 1, "::unfold"),
            (PixelShuffle, "pixel_shuffle", Storage, Shape, PixelShuffleAttributes, 1, 1, "::pixel_shuffle"),
            (GroupNorm, "group_norm", Normalization, Normalization, GroupNormAttributes, 1, 1, "::group_norm"),
            (InstanceNorm, "instance_norm", Normalization, Normalization, EpsilonAttributes, 1, 1, "::instance_norm"),
            (BroadcastLeft, "broadcast_left", Storage, Shape, ShapeAttributes, 1, 1, "::broadcast_left"),
            (ToHostFloatScalar, "float_to_scalar", Storage, Transfer, NoAttributes, 1, 1, "::float_to_scalar"),
            (ToHostFloatVec, "float_to_vec1", Storage, Transfer, NoAttributes, 1, 1, "::float_to_vec1"),
            (ToHostIntScalar, "int_to_scalar", Storage, Transfer, NoAttributes, 1, 1, "::int_to_scalar"),
            (ToHostIntVec, "int_to_vec1", Storage, Transfer, NoAttributes, 1, 1, "::int_to_vec1"),
            (ToDType, "to_dtype", Storage, Transfer, DTypeAttributes, 1, 1, "::tensor_to_dtype"),
            (ToDevice, "to_device", Storage, Transfer, DeviceAttributes, 1, 1, "TransferTo"),
            (RequireGrad, "require_grad", Storage, Autograd, NoAttributes, 1, 1, "Tensor::require_grad"),
            (Detach, "detach", Storage, Autograd, NoAttributes, 1, 1, "Tensor::detach"),
            (Backward, "backward", Storage, Autograd, NoAttributes, 1, 1, "Tensor::backward"),

            (SumAll, "sum_all", Reduction, Reduction, NoAttributes, 1, 1, "::sum_all"),
            (MeanAll, "mean_all", Reduction, Reduction, NoAttributes, 1, 1, "::mean_all"),
            (MaxAll, "max_all", Reduction, Reduction, NoAttributes, 1, 1, "::max_all"),
            (MinAll, "min_all", Reduction, Reduction, NoAttributes, 1, 1, "::min_all"),
            (SumDim, "sum_dim", Reduction, Reduction, AxisAttributes, 1, 1, "::sum_dim"),
            (SumKeepDim, "sum_keepdim", Reduction, Reduction, AxisAttributes, 1, 1, "::sum_keepdim"),
            (MeanDim, "mean_dim", Reduction, Reduction, AxisAttributes, 1, 1, "::mean_dim"),
            (MeanKeepDim, "mean_keepdim", Reduction, Reduction, AxisAttributes, 1, 1, "::mean_keepdim"),
            (MaxDim, "max_dim", Reduction, Reduction, AxisAttributes, 1, 1, "::max_dim"),
            (MaxKeepDim, "max_keepdim", Reduction, Reduction, AxisAttributes, 1, 1, "::max_keepdim"),
            (MinDim, "min_dim", Reduction, Reduction, AxisAttributes, 1, 1, "::min_dim"),
            (MinKeepDim, "min_keepdim", Reduction, Reduction, AxisAttributes, 1, 1, "::min_keepdim"),
            (ArgMax, "argmax", Reduction, IndexReduction, IndexReductionAttributes, 1, 1, "::argmax"),
            (ArgMin, "argmin", Reduction, IndexReduction, IndexReductionAttributes, 1, 1, "::argmin"),
            (ProdAll, "prod_all", Reduction, Reduction, NoAttributes, 1, 1, "::prod_all"),
            (ProdDim, "prod_dim", Reduction, Reduction, AxisAttributes, 1, 1, "::prod_dim"),
            (Cumsum, "cumsum", Reduction, Scan, AxisAttributes, 1, 1, "::cumsum"),
            (TopK, "topk", Reduction, IndexReduction, TopKAttributes, 1, 1, "::topk"),
            (Argsort, "argsort", Reduction, IndexReduction, ArgsortAttributes, 1, 1, "::argsort"),
            (Norm, "norm", Reduction, Reduction, NormAttributes, 1, 1, "Tensor::norm"),
            (VarianceAll, "var_all", Reduction, Reduction, VarianceAttributes, 1, 1, "Tensor::var_all"),
            (VarianceDim, "var_dim", Reduction, Reduction, AxisVarianceAttributes, 1, 1, "Tensor::var_dim"),
            (VarianceKeepDim, "var_keepdim", Reduction, Reduction, AxisVarianceAttributes, 1, 1, "Tensor::var_keepdim"),
            (StdAll, "std_all", Reduction, Reduction, VarianceAttributes, 1, 1, "Tensor::std_all"),
            (StdDim, "std_dim", Reduction, Reduction, AxisVarianceAttributes, 1, 1, "Tensor::std_dim"),
            (StdKeepDim, "std_keepdim", Reduction, Reduction, AxisVarianceAttributes, 1, 1, "Tensor::std_keepdim"),

            (LayerNorm, "layer_norm", Normalization, Module, LayerNormAttributes, 2, 3, "::layer_norm"),
            (BatchNorm, "batch_norm", Normalization, Module, BatchNormAttributes, 1, 5, "::batch_norm"),
            (EmbeddingExact, "embedding", Storage, Module, NoAttributes, 2, 2, "::embedding"),
            (Conv1dExact, "conv1d", Reduction, Module, Conv1dAttributes, 2, 3, "::conv1d"),
            (Conv2dExact, "conv2d", Reduction, Module, Conv2dAttributes, 2, 3, "::conv2d"),
            (ConvTranspose2d, "conv_transpose2d", Reduction, Module, ConvTranspose2dAttributes, 2, 3, "::conv_transpose2d"),
            (MaxPool2d, "max_pool2d", Reduction, Module, Pool2dAttributes, 1, 1, "::max_pool2d"),
            (AvgPool2d, "avg_pool2d", Reduction, Module, AvgPool2dAttributes, 1, 1, "::avg_pool2d"),
            (AdaptiveAvgPool2dExact, "adaptive_avg_pool2d", Reduction, Module, AdaptivePool2dAttributes, 1, 1, "::adaptive_avg_pool2d"),
            (Linear, "linear", Reduction, Composite, LinearAttributes, 2, 3, "Linear::forward"),
            (RmsNorm, "rms_norm", Normalization, Composite, EpsilonAttributes, 2, 2, "RMSNorm::forward"),
            (Dropout, "dropout", Pointwise, Composite, DropoutAttributes, 1, 1, "Dropout::forward"),
            (Rnn, "rnn", Pointwise, Composite, RecurrentAttributes, 2, 2, "RNN::forward"),
            (Lstm, "lstm", Pointwise, Composite, RecurrentAttributes, 3, 3, "LSTM::forward"),

            (MseLoss, "mse_loss", Reduction, Loss, LossAttributes, 2, 2, "Loss::mse_loss"),
            (L1Loss, "l1_loss", Reduction, Loss, LossAttributes, 2, 2, "Loss::l1_loss"),
            (BceWithLogitsLoss, "bce_with_logits_loss", Reduction, Loss, LossAttributes, 2, 2, "Loss::bce_with_logits_loss"),
            (CrossEntropyLoss, "cross_entropy_loss", Reduction, Loss, LossAttributes, 2, 2, "Loss::cross_entropy_loss"),
            (Quantize, "quantize", Pointwise, Quantized, QuantizationAttributes, 1, 1, "Descriptor<op::Quantize>"),
            (Dequantize, "dequantize", Pointwise, Quantized, QuantizationAttributes, 1, 1, "Descriptor<op::Dequantize>"),
            (QuantizedMatMul, "quantized_matmul", Reduction, Quantized, NoAttributes, 2, 2, "Descriptor<op::QuantizedMatMul>"),
            (SgdStep, "sgd_step", Pointwise, Optimizer, SgdAttributes, 2, 2, "SGD::step"),
            (AdamStep, "adam_step", Pointwise, Optimizer, AdamAttributes, 4, 4, "Adam::step"),
            (AdamWStep, "adamw_step", Pointwise, Optimizer, AdamWAttributes, 4, 4, "AdamW::step"),
        }
    };
}