跳转至

Elementwise Operators

本页暂无中文版。以下为英文原文。

Every op on this page is used the same way: construct it once, then call it. The constructor takes what the kernel is compiled with; the call takes the tensors. Both are documented under each op — __init__ and forward, where forward is what runs when you call op(...).

Arithmetic

tileops.elementwise.AddFwdOp

Element-wise addition with broadcast: y = input + alpha * other.

Conforms to torch.add(input, other, *, alpha=1). alpha is baked into the kernel, so non-default alpha runs through the same fast kernel as the default.

__init__

__init__(
    *,
    alpha=1,
    target=None
)

Build the op. Shapes and dtype are taken from the first call.

Parameters:

  • alpha (int | float, default: 1 ) –

    Multiplier on other (default 1).

  • target (Target, default: None ) –

    Backend target to serve this op, or None to decide from the input device.

forward

forward(
    input,
    other,
)

Run the op on input and other.

tileops.elementwise.SubFwdOp

Element-wise subtraction with broadcast: y = input - alpha * other.

Conforms to torch.sub(input, other, *, alpha=1). alpha is baked into the kernel, so non-default alpha runs through the same fast kernel as the default.

__init__

__init__(
    *,
    alpha=1,
    target=None
)

Build the op. Shapes and dtype are taken from the first call.

Parameters:

  • alpha (int | float, default: 1 ) –

    Multiplier on other (default 1).

  • target (Target, default: None ) –

    Backend target to serve this op, or None to decide from the input device.

forward

forward(
    input,
    other,
)

Run the op on input and other.

tileops.elementwise.MulFwdOp

Element-wise multiplication with broadcast: y = input * other.

__init__

__init__(
    *,
    target=None
)

Build the op. Shapes and dtype are taken from the first call.

Parameters:

  • target (Target, default: None ) –

    Which set of kernels serves this op — a target name, BUILTIN for the in-tree kernels, or None to decide from the input device.

forward

forward(
    input,
    other,
)

Run the op on input and other.

tileops.elementwise.DivFwdOp

Element-wise division with broadcast: y = input / other.

Conforms to torch.div(input, other, *, rounding_mode=None). rounding_mode accepts None (true division), "trunc" (truncation toward zero), or "floor" (floor division); each value selects a dedicated kernel through the call spec.

__init__

__init__(
    *,
    rounding_mode=None,
    target=None
)

Build the op. Shapes and dtype are taken from the first call.

Parameters:

  • rounding_mode (Optional[str], default: None ) –

    None, "trunc" or "floor".

  • target (Target, default: None ) –

    Backend target to serve this op, or None to decide from the input device.

forward

forward(
    input,
    other,
)

Run the op on input and other.

tileops.elementwise.FloorDivideFwdOp

Element-wise floor division with broadcast: y = a // b, as torch.floor_divide.

__init__

__init__(
    *,
    target=None
)

Build the op. Shapes and dtype are taken from the first call.

Parameters:

  • target (Target, default: None ) –

    Which set of kernels serves this op — a target name, BUILTIN for the in-tree kernels, or None to decide from the input device.

forward

forward(
    input,
    other,
)

Run the op on input and other.

tileops.elementwise.RemainderFwdOp

Element-wise remainder with broadcast: y = a % b.

__init__

__init__(
    *,
    target=None
)

Build the op. Shapes and dtype are taken from the first call.

Parameters:

  • target (Target, default: None ) –

    Which set of kernels serves this op — a target name, BUILTIN for the in-tree kernels, or None to decide from the input device.

forward

forward(
    input,
    other,
)

Run the op on input and other.

tileops.elementwise.PowFwdOp

Element-wise power with broadcast: y = input ** exponent.

Conforms to torch.pow(input, exponent): the second operand carries the manifest-declared name exponent rather than the generic other so the L1 signature check matches the manifest.

Accuracy differs from torch.pow: the power is computed as exp2(exponent * log2|input|), whose error scales with |exponent * log2(input)| rather than staying flat. Measured against a float64 reference, in units of a float32 ulp:

input exponent here torch.pow
0.9 to 1.1 -1 to 1 1.2 0.5
0.5 to 2 -2 to 2 1.8 0.6
0.25 to 4 -3 to 3 3.4 0.6
0.01 to 100 -3 to 3 10.6 0.6
1e-6 to 1e6 -2 to 2 22.5 0.6

The bound is the table above, not a constant. Callers raising a base far from one to a large exponent, or comparing results for equality, need to account for it.

__init__

__init__(
    *,
    target=None
)

Build the op. Shapes and dtype are taken from the first call.

Parameters:

  • target (Target, default: None ) –

    Which set of kernels serves this op — a target name, BUILTIN for the in-tree kernels, or None to decide from the input device.

forward

forward(
    input,
    exponent,
)

Run the op on input and exponent.

tileops.elementwise.MaximumFwdOp

Element-wise maximum with broadcast: y = max(a, b).

A NaN operand gives a NaN result, canonical rather than the operand's own payload and sign bit; torch.maximum returns the operand's bit pattern.

__init__

__init__(
    *,
    target=None
)

Build the op. Shapes and dtype are taken from the first call.

Parameters:

  • target (Target, default: None ) –

    Which set of kernels serves this op — a target name, BUILTIN for the in-tree kernels, or None to decide from the input device.

forward

forward(
    input,
    other,
)

Run the op on input and other.

tileops.elementwise.MinimumFwdOp

Element-wise minimum with broadcast: y = min(a, b).

A NaN operand gives a NaN result, canonical rather than the operand's own payload and sign bit; torch.minimum returns the operand's bit pattern.

__init__

__init__(
    *,
    target=None
)

Build the op. Shapes and dtype are taken from the first call.

Parameters:

  • target (Target, default: None ) –

    Which set of kernels serves this op — a target name, BUILTIN for the in-tree kernels, or None to decide from the input device.

forward

forward(
    input,
    other,
)

Run the op on input and other.

tileops.elementwise.LerpScalarFwdOp

Element-wise lerp with broadcast: y = a + weight * (b - a).

Unlike torch.lerp(a, b, weight) where weight is a runtime parameter, here weight is a construction-time constant baked into the compiled kernel. This enables compile-time folding but means a new Op instance is needed for each distinct weight value.

__init__

__init__(
    *,
    weight=0.5,
    target=None
)

Build the op. Shapes and dtype are taken from the first call.

Parameters:

  • weight (float, default: 0.5 ) –

    Scalar interpolation weight, fixed at construction (manifest params.weight, default 0.5).

  • target (Target, default: None ) –

    Which set of kernels serves this op.

forward

forward(
    input,
    end,
)

Run the op on input and end.

tileops.elementwise.LerpTensorFwdOp

Tensor-weight lerp: out = input + weight * (end - input).

Conforms to the Tensor-weight overload of torch.lerp — torch.lerp(input, end, weight: Tensor) where weight is a Tensor that broadcasts together with input and end to the output shape. The scalar-weight overload is handled separately by LerpScalarFwdOp.

__init__

__init__(
    *,
    target=None
)

Build the op. Shapes and dtype are taken from the first call.

Parameters:

  • target (Target, default: None ) –

    Which set of kernels serves this op.

forward

forward(
    input,
    end,
    weight,
)

Run the op on input, end and weight.

Unary math

tileops.elementwise.ExpFwdOp

Element-wise exp(x).

__init__

__init__(
    *,
    target=None
)

Build the op. Shapes and dtype are taken from the first call.

Parameters:

  • target (Target, default: None ) –

    Which set of kernels serves this op — a target name, BUILTIN for the in-tree kernels, or None to decide from the input device.

forward

forward(
    input,
)

Run the op on input.

tileops.elementwise.Expm1FwdOp

Element-wise exp(x) - 1.

__init__

__init__(
    *,
    target=None
)

Build the op. Shapes and dtype are taken from the first call.

Parameters:

  • target (Target, default: None ) –

    Which set of kernels serves this op — a target name, BUILTIN for the in-tree kernels, or None to decide from the input device.

forward

forward(
    input,
)

Run the op on input.

tileops.elementwise.LogFwdOp

Element-wise log(x).

__init__

__init__(
    *,
    target=None
)

Build the op. Shapes and dtype are taken from the first call.

Parameters:

  • target (Target, default: None ) –

    Which set of kernels serves this op — a target name, BUILTIN for the in-tree kernels, or None to decide from the input device.

forward

forward(
    input,
)

Run the op on input.

tileops.elementwise.Log1pFwdOp

Element-wise log(1 + x).

__init__

__init__(
    *,
    target=None
)

Build the op. Shapes and dtype are taken from the first call.

Parameters:

  • target (Target, default: None ) –

    Which set of kernels serves this op — a target name, BUILTIN for the in-tree kernels, or None to decide from the input device.

forward

forward(
    input,
)

Run the op on input.

tileops.elementwise.SqrtFwdOp

Element-wise sqrt(x).

__init__

__init__(
    *,
    target=None
)

Build the op. Shapes and dtype are taken from the first call.

Parameters:

  • target (Target, default: None ) –

    Which set of kernels serves this op — a target name, BUILTIN for the in-tree kernels, or None to decide from the input device.

forward

forward(
    input,
)

Run the op on input.

tileops.elementwise.RsqrtFwdOp

Element-wise 1/sqrt(x).

__init__

__init__(
    *,
    target=None
)

Build the op. Shapes and dtype are taken from the first call.

Parameters:

  • target (Target, default: None ) –

    Which set of kernels serves this op — a target name, BUILTIN for the in-tree kernels, or None to decide from the input device.

forward

forward(
    input,
)

Run the op on input.

tileops.elementwise.ReciprocalFwdOp

Element-wise 1/x.

Mirrors torch.reciprocal int-input promotion: an integral input gives a float32 output, and ReciprocalFwdKernel.specialize names float32 as the compute type for it. Floating inputs keep their dtype. A float16 or bfloat16 result equals torch.reciprocal's bit for bit at every input.

__init__

__init__(
    *,
    target=None
)

Build the op. Shapes and dtype are taken from the first call.

Parameters:

  • target (Target, default: None ) –

    Which set of kernels serves this op — a target name, BUILTIN for the in-tree kernels, or None to decide from the input device.

forward

forward(
    input,
)

Run the op on input.

tileops.elementwise.AbsFwdOp

Element-wise |x|.

__init__

__init__(
    *,
    target=None
)

Build the op. Shapes and dtype are taken from the first call.

Parameters:

  • target (Target, default: None ) –

    Which set of kernels serves this op — a target name, BUILTIN for the in-tree kernels, or None to decide from the input device.

forward

forward(
    input,
)

Run the op on input.

tileops.elementwise.NegFwdOp

Element-wise -x.

__init__

__init__(
    *,
    target=None
)

Build the op. Shapes and dtype are taken from the first call.

Parameters:

  • target (Target, default: None ) –

    Which set of kernels serves this op — a target name, BUILTIN for the in-tree kernels, or None to decide from the input device.

forward

forward(
    input,
)

Run the op on input.

tileops.elementwise.SignFwdOp

Element-wise sign(x): -1, 0, or +1.

__init__

__init__(
    *,
    target=None
)

Build the op. Shapes and dtype are taken from the first call.

Parameters:

  • target (Target, default: None ) –

    Which set of kernels serves this op — a target name, BUILTIN for the in-tree kernels, or None to decide from the input device.

forward

forward(
    input,
)

Run the op on input.

tileops.elementwise.SinFwdOp

Element-wise sin(x).

__init__

__init__(
    *,
    target=None
)

Build the op. Shapes and dtype are taken from the first call.

Parameters:

  • target (Target, default: None ) –

    Which set of kernels serves this op — a target name, BUILTIN for the in-tree kernels, or None to decide from the input device.

forward

forward(
    input,
)

Run the op on input.

tileops.elementwise.CosFwdOp

Element-wise cos(x).

__init__

__init__(
    *,
    target=None
)

Build the op. Shapes and dtype are taken from the first call.

Parameters:

  • target (Target, default: None ) –

    Which set of kernels serves this op — a target name, BUILTIN for the in-tree kernels, or None to decide from the input device.

forward

forward(
    input,
)

Run the op on input.

tileops.elementwise.ErfFwdOp

Element-wise erf(x).

On float16 and bfloat16 the error function is evaluated as a polynomial that saturates to exactly +/-1; its worst case over the real line is 1.7e-5, an order below half a float16 ulp at 1.0. float32 keeps erff.

__init__

__init__(
    *,
    target=None
)

Build the op. Shapes and dtype are taken from the first call.

Parameters:

  • target (Target, default: None ) –

    Which set of kernels serves this op — a target name, BUILTIN for the in-tree kernels, or None to decide from the input device.

forward

forward(
    input,
)

Run the op on input.

tileops.elementwise.FloorFwdOp

Element-wise floor(x).

__init__

__init__(
    *,
    target=None
)

Build the op. Shapes and dtype are taken from the first call.

Parameters:

  • target (Target, default: None ) –

    Which set of kernels serves this op — a target name, BUILTIN for the in-tree kernels, or None to decide from the input device.

forward

forward(
    input,
)

Run the op on input.

tileops.elementwise.CeilFwdOp

Element-wise ceil(x).

__init__

__init__(
    *,
    target=None
)

Build the op. Shapes and dtype are taken from the first call.

Parameters:

  • target (Target, default: None ) –

    Which set of kernels serves this op — a target name, BUILTIN for the in-tree kernels, or None to decide from the input device.

forward

forward(
    input,
)

Run the op on input.

tileops.elementwise.RoundFwdOp

Element-wise round(x) to decimals decimal places.

The shipped kernel performs banker's round-to-nearest-integer, matching torch.round for decimals=0. decimals is a manifest param, so it is fixed for the instance and handed to whichever kernel serves the op.

__init__

__init__(
    *,
    decimals=0,
    target=None
)

Build the op. Shapes and dtype are taken from the first call.

Parameters:

  • decimals (int, default: 0 ) –

    Number of decimal places to round to (manifest params.decimals, default 0).

  • target (Target, default: None ) –

    Which set of kernels serves this op.

forward

forward(
    input,
)

Run the op on input.

tileops.elementwise.TruncFwdOp

Element-wise trunc(x).

__init__

__init__(
    *,
    target=None
)

Build the op. Shapes and dtype are taken from the first call.

Parameters:

  • target (Target, default: None ) –

    Which set of kernels serves this op — a target name, BUILTIN for the in-tree kernels, or None to decide from the input device.

forward

forward(
    input,
)

Run the op on input.

Activations

tileops.elementwise.ReluFwdOp

ReLU activation: y = max(x, 0).

__init__

__init__(
    *,
    inplace=False,
    target=None
)

Build the op. Shapes and dtype are taken from the first call.

Parameters:

  • inplace (bool, default: False ) –

    When True, write the result into input and return input.

  • target (Target, default: None ) –

    Backend target to serve this op, or None to decide from the input device.

forward

forward(
    input,
)

Run the activation on input, into input itself when inplace is set.

tileops.elementwise.LeakyReluFwdOp

Leaky ReLU: y = x if x > 0 else negative_slope * x.

__init__

__init__(
    *,
    negative_slope=0.01,
    inplace=False,
    target=None
)

Build the op. Shapes and dtype are taken from the first call.

Parameters:

  • negative_slope (float, default: 0.01 ) –

    Slope for negative inputs (default 0.01).

  • inplace (bool, default: False ) –

    When True, write the result into input and return input.

  • target (Target, default: None ) –

    Which set of kernels serves this op.

forward

forward(
    input,
)

Run the activation on input, into input itself when inplace is set.

tileops.elementwise.EluFwdOp

ELU: y = x if x > 0 else alpha * (exp(x) - 1).

__init__

__init__(
    *,
    alpha=1.0,
    inplace=False,
    target=None
)

Build the op. Shapes and dtype are taken from the first call.

Parameters:

  • alpha (float, default: 1.0 ) –

    Scale for the negative part (default 1.0).

  • inplace (bool, default: False ) –

    When True, write the result into input and return input.

  • target (Target, default: None ) –

    Which set of kernels serves this op.

forward

forward(
    input,
)

Run the activation on input, into input itself when inplace is set.

tileops.elementwise.SeluFwdOp

Element-wise SELU activation.

__init__

__init__(
    *,
    inplace=False,
    target=None
)

Build the op. Shapes and dtype are taken from the first call.

Parameters:

  • inplace (bool, default: False ) –

    When True, write the result into input and return input.

  • target (Target, default: None ) –

    Backend target to serve this op, or None to decide from the input device.

forward

forward(
    input,
)

Run the activation on input, into input itself when inplace is set.

tileops.elementwise.GeluFwdOp

Element-wise GELU honoring the manifest approximate contract.

On float16 and bfloat16 the error function is evaluated as a polynomial that saturates to exactly +/-1; its worst case over the real line is 1.7e-5, an order below half a float16 ulp at 1.0. float32 keeps erff.

__init__

__init__(
    *,
    approximate="none",
    target=None
)

Build the op. Shapes and dtype are taken from the first call.

Parameters:

  • approximate (str, default: 'none' ) –

    'none' (default) evaluates the erf form; 'tanh' the tanh approximation 0.5 * x * (1 + tanh(sqrt(2/pi) * (x + 0.044715 * x^3))).

  • target (Target, default: None ) –

    Which set of kernels serves this op.

forward

forward(
    input,
)

Run the op on input.

tileops.elementwise.SiluFwdOp

Element-wise SiLU (Swish): y = x * sigmoid(x).

__init__

__init__(
    *,
    inplace=False,
    target=None
)

Build the op. Shapes and dtype are taken from the first call.

Parameters:

  • inplace (bool, default: False ) –

    When True, write the result into input and return input.

  • target (Target, default: None ) –

    Backend target to serve this op, or None to decide from the input device.

forward

forward(
    input,
)

Run the activation on input, into input itself when inplace is set.

tileops.elementwise.MishFwdOp

Element-wise Mish: y = x * tanh(softplus(x)).

__init__

__init__(
    *,
    inplace=False,
    target=None
)

Build the op. Shapes and dtype are taken from the first call.

Parameters:

  • inplace (bool, default: False ) –

    When True, write the result into input and return input.

  • target (Target, default: None ) –

    Backend target to serve this op, or None to decide from the input device.

forward

forward(
    input,
)

Run the activation on input, into input itself when inplace is set.

tileops.elementwise.SigmoidFwdOp

Element-wise sigmoid(x).

A float16 or bfloat16 result equals torch.sigmoid's bit for bit at every input.

__init__

__init__(
    *,
    target=None
)

Build the op. Shapes and dtype are taken from the first call.

Parameters:

  • target (Target, default: None ) –

    Which set of kernels serves this op — a target name, BUILTIN for the in-tree kernels, or None to decide from the input device.

forward

forward(
    input,
)

Run the op on input.

tileops.elementwise.TanhFwdOp

Element-wise tanh(x).

__init__

__init__(
    *,
    target=None
)

Build the op. Shapes and dtype are taken from the first call.

Parameters:

  • target (Target, default: None ) –

    Which set of kernels serves this op — a target name, BUILTIN for the in-tree kernels, or None to decide from the input device.

forward

forward(
    input,
)

Run the op on input.

tileops.elementwise.HardsigmoidFwdOp

Element-wise HardSigmoid: y = clamp(x + 3, 0, 6) / 6.

__init__

__init__(
    *,
    inplace=False,
    target=None
)

Build the op. Shapes and dtype are taken from the first call.

Parameters:

  • inplace (bool, default: False ) –

    When True, write the result into input and return input.

  • target (Target, default: None ) –

    Backend target to serve this op, or None to decide from the input device.

forward

forward(
    input,
)

Run the activation on input, into input itself when inplace is set.

tileops.elementwise.HardswishFwdOp

Element-wise HardSwish: y = x * clamp(x + 3, 0, 6) / 6.

__init__

__init__(
    *,
    inplace=False,
    target=None
)

Build the op. Shapes and dtype are taken from the first call.

Parameters:

  • inplace (bool, default: False ) –

    When True, write the result into input and return input.

  • target (Target, default: None ) –

    Backend target to serve this op, or None to decide from the input device.

forward

forward(
    input,
)

Run the activation on input, into input itself when inplace is set.

tileops.elementwise.HardtanhFwdOp

Hardtanh: y = clamp(x, min_val, max_val).

__init__

__init__(
    *,
    min_val=-1.0,
    max_val=1.0,
    inplace=False,
    target=None
)

Build the op. Shapes and dtype are taken from the first call.

Parameters:

  • min_val (float, default: -1.0 ) –

    Lower bound (default -1.0).

  • max_val (float, default: 1.0 ) –

    Upper bound (default 1.0).

  • inplace (bool, default: False ) –

    When True, write the result into input and return input.

  • target (Target, default: None ) –

    Which set of kernels serves this op.

forward

forward(
    input,
)

Run the activation on input, into input itself when inplace is set.

tileops.elementwise.SoftplusFwdOp

Softplus: y = log(1 + exp(xbeta))/beta if xbeta <= threshold else x.

__init__

__init__(
    *,
    beta=1.0,
    threshold=20.0,
    target=None
)

Build the op. Shapes and dtype are taken from the first call.

Parameters:

  • beta (float, default: 1.0 ) –

    Scaling factor (default 1.0).

  • threshold (float, default: 20.0 ) –

    Linear regime threshold (default 20.0).

  • target (Target, default: None ) –

    Which set of kernels serves this op.

forward

forward(
    input,
)

Run the op on input.

tileops.elementwise.PreluFwdOp

PReLU: y = x if x > 0 else weight[channel] * x.

Channel dimension follows PyTorch convention: dimension 1 for inputs with ndim >= 2, dimension 0 for 1-D inputs. Both the shape and the channel count arrive with the tensors.

__init__

__init__(
    *,
    target=None
)

Build the op. Shapes and dtype are taken from the first call.

Parameters:

  • target (Target, default: None ) –

    Which set of kernels serves this op — a target name, BUILTIN for the in-tree kernels, or None to decide from the input device.

forward

forward(
    input,
    weight,
)

Run the op on input and weight.

tileops.elementwise.DropoutFwdOp

Dropout operation with deterministic replay via TileLang RNG.

Compatible with PyTorch dropout semantics: - Training mode: output = x * mask / (1 - p), mask ~ Bernoulli(1 - p) - Eval mode (training=False): output = x (identity) - p=0: identity - p=1: all zeros

Same seed produces identical masks for deterministic replay. Uses T.rng_init / T.rng_rand_float (backed by cuRAND Philox4_32_10 by default) for per-thread random number generation.

__init__

__init__(
    p=0.5,
    seed=0,
    training=True,
    *,
    target=None
)

Build the op. Shapes and dtype are taken from the first call.

Parameters:

  • p (float, default: 0.5 ) –

    Drop probability in [0, 1].

  • seed (int, default: 0 ) –

    Integer seed for RNG.

  • training (bool, default: True ) –

    If False, dropout is disabled (identity pass-through).

  • target (Target, default: None ) –

    Which set of kernels serves this op — a target name, BUILTIN for the in-tree kernels, or None to decide from the input device.

forward

forward(
    input,
)

Run the op on input.

Gated activations

tileops.elementwise.SiluAndMulFwdOp

SiLU-and-Mul: y = silu(gate) * value.

__init__

__init__(
    *,
    target=None
)

Build the op. Shapes and dtype are taken from the first call.

Parameters:

  • target (Target, default: None ) –

    Which set of kernels serves this op — a target name, BUILTIN for the in-tree kernels, or None to decide from the input device.

forward

forward(
    x,
)

Run the op on x.

tileops.elementwise.GeluAndMulFwdOp

GELU-and-Mul: y = gelu(gate) * value (exact GELU).

On float16 and bfloat16 the error function is evaluated as a polynomial that saturates to exactly +/-1; its worst case over the real line is 1.7e-5, an order below half a float16 ulp at 1.0. float32 keeps erff.

__init__

__init__(
    *,
    target=None
)

Build the op. Shapes and dtype are taken from the first call.

Parameters:

  • target (Target, default: None ) –

    Which set of kernels serves this op — a target name, BUILTIN for the in-tree kernels, or None to decide from the input device.

forward

forward(
    x,
)

Run the op on x.

tileops.elementwise.GeluTanhAndMulFwdOp

GELU-Tanh-and-Mul: y = gelu_tanh(gate) * value (tanh approximation).

__init__

__init__(
    *,
    target=None
)

Build the op. Shapes and dtype are taken from the first call.

Parameters:

  • target (Target, default: None ) –

    Which set of kernels serves this op — a target name, BUILTIN for the in-tree kernels, or None to decide from the input device.

forward

forward(
    x,
)

Run the op on x.

Comparison

tileops.elementwise.EqFwdOp

Element-wise equality with broadcast: y = (a == b).

__init__

__init__(
    *,
    target=None
)

Build the op. Shapes and dtype are taken from the first call.

Parameters:

  • target (Target, default: None ) –

    Which set of kernels serves this op — a target name, BUILTIN for the in-tree kernels, or None to decide from the input device.

forward

forward(
    input,
    other,
)

Run the op on input and other.

tileops.elementwise.NeFwdOp

Element-wise not-equal with broadcast: y = (a != b).

__init__

__init__(
    *,
    target=None
)

Build the op. Shapes and dtype are taken from the first call.

Parameters:

  • target (Target, default: None ) –

    Which set of kernels serves this op — a target name, BUILTIN for the in-tree kernels, or None to decide from the input device.

forward

forward(
    input,
    other,
)

Run the op on input and other.

tileops.elementwise.GtFwdOp

Element-wise greater-than with broadcast: y = (a > b).

__init__

__init__(
    *,
    target=None
)

Build the op. Shapes and dtype are taken from the first call.

Parameters:

  • target (Target, default: None ) –

    Which set of kernels serves this op — a target name, BUILTIN for the in-tree kernels, or None to decide from the input device.

forward

forward(
    input,
    other,
)

Run the op on input and other.

tileops.elementwise.GeFwdOp

Element-wise greater-equal with broadcast: y = (a >= b).

__init__

__init__(
    *,
    target=None
)

Build the op. Shapes and dtype are taken from the first call.

Parameters:

  • target (Target, default: None ) –

    Which set of kernels serves this op — a target name, BUILTIN for the in-tree kernels, or None to decide from the input device.

forward

forward(
    input,
    other,
)

Run the op on input and other.

tileops.elementwise.LtFwdOp

Element-wise less-than with broadcast: y = (a < b).

__init__

__init__(
    *,
    target=None
)

Build the op. Shapes and dtype are taken from the first call.

Parameters:

  • target (Target, default: None ) –

    Which set of kernels serves this op — a target name, BUILTIN for the in-tree kernels, or None to decide from the input device.

forward

forward(
    input,
    other,
)

Run the op on input and other.

tileops.elementwise.LeFwdOp

Element-wise less-equal with broadcast: y = (a <= b).

__init__

__init__(
    *,
    target=None
)

Build the op. Shapes and dtype are taken from the first call.

Parameters:

  • target (Target, default: None ) –

    Which set of kernels serves this op — a target name, BUILTIN for the in-tree kernels, or None to decide from the input device.

forward

forward(
    input,
    other,
)

Run the op on input and other.

tileops.elementwise.IsnanFwdOp

Element-wise isnan with bool output.

Always False on integer / bool input (no NaN representation in those dtypes).

__init__

__init__(
    *,
    target=None
)

Build the op. Shapes and dtype are taken from the first call.

Parameters:

  • target (Target, default: None ) –

    Which set of kernels serves this op — a target name, BUILTIN for the in-tree kernels, or None to decide from the input device.

forward

forward(
    input,
)

Run the op on input.

tileops.elementwise.IsinfFwdOp

Element-wise isinf with bool output.

Always False on integer / bool input (no Inf representation in those dtypes).

__init__

__init__(
    *,
    target=None
)

Build the op. Shapes and dtype are taken from the first call.

Parameters:

  • target (Target, default: None ) –

    Which set of kernels serves this op — a target name, BUILTIN for the in-tree kernels, or None to decide from the input device.

forward

forward(
    input,
)

Run the op on input.

tileops.elementwise.IsfiniteFwdOp

Element-wise isfinite with bool output.

Always True on integer / bool input (every value in those dtypes is finite).

__init__

__init__(
    *,
    target=None
)

Build the op. Shapes and dtype are taken from the first call.

Parameters:

  • target (Target, default: None ) –

    Which set of kernels serves this op — a target name, BUILTIN for the in-tree kernels, or None to decide from the input device.

forward

forward(
    input,
)

Run the op on input.

Logical and bitwise

tileops.elementwise.LogicalAndFwdOp

Element-wise logical AND with broadcast using non-zero truthiness.

__init__

__init__(
    *,
    target=None
)

Build the op. Shapes and dtype are taken from the first call.

Parameters:

  • target (Target, default: None ) –

    Which set of kernels serves this op — a target name, BUILTIN for the in-tree kernels, or None to decide from the input device.

forward

forward(
    input,
    other,
)

Run the op on input and other.

tileops.elementwise.LogicalOrFwdOp

Element-wise logical OR with broadcast using non-zero truthiness.

__init__

__init__(
    *,
    target=None
)

Build the op. Shapes and dtype are taken from the first call.

Parameters:

  • target (Target, default: None ) –

    Which set of kernels serves this op — a target name, BUILTIN for the in-tree kernels, or None to decide from the input device.

forward

forward(
    input,
    other,
)

Run the op on input and other.

tileops.elementwise.LogicalNotFwdOp

Element-wise logical NOT with bool output.

__init__

__init__(
    *,
    target=None
)

Build the op. Shapes and dtype are taken from the first call.

Parameters:

  • target (Target, default: None ) –

    Which set of kernels serves this op — a target name, BUILTIN for the in-tree kernels, or None to decide from the input device.

forward

forward(
    input,
)

Run the op on input.

tileops.elementwise.BitwiseAndFwdOp

Element-wise bitwise AND with broadcast: y = a & b.

__init__

__init__(
    *,
    target=None
)

Build the op. Shapes and dtype are taken from the first call.

Parameters:

  • target (Target, default: None ) –

    Which set of kernels serves this op — a target name, BUILTIN for the in-tree kernels, or None to decide from the input device.

forward

forward(
    input,
    other,
)

Run the op on input and other.

tileops.elementwise.BitwiseOrFwdOp

Element-wise bitwise OR with broadcast: y = a | b.

__init__

__init__(
    *,
    target=None
)

Build the op. Shapes and dtype are taken from the first call.

Parameters:

  • target (Target, default: None ) –

    Which set of kernels serves this op — a target name, BUILTIN for the in-tree kernels, or None to decide from the input device.

forward

forward(
    input,
    other,
)

Run the op on input and other.

tileops.elementwise.BitwiseXorFwdOp

Element-wise bitwise XOR with broadcast: y = a ^ b.

__init__

__init__(
    *,
    target=None
)

Build the op. Shapes and dtype are taken from the first call.

Parameters:

  • target (Target, default: None ) –

    Which set of kernels serves this op — a target name, BUILTIN for the in-tree kernels, or None to decide from the input device.

forward

forward(
    input,
    other,
)

Run the op on input and other.

tileops.elementwise.BitwiseNotFwdOp

Element-wise bitwise NOT (~x) for bool/integer inputs.

__init__

__init__(
    *,
    target=None
)

Build the op. Shapes and dtype are taken from the first call.

Parameters:

  • target (Target, default: None ) –

    Which set of kernels serves this op — a target name, BUILTIN for the in-tree kernels, or None to decide from the input device.

forward

forward(
    input,
)

Run the op on input.

Selection and clamping

tileops.elementwise.WhereFwdOp

Where: out = condition ? input : other (with full PyTorch broadcasting).

Conforms to torch.where(condition, input, other): condition is a bool tensor and input / other may broadcast with each other and with condition to produce the output. The three operand shapes arrive with the tensors; broadcasting them is the kernel's business.

__init__

__init__(
    *,
    target=None
)

Build the op. Shapes and dtype are taken from the first call.

Parameters:

  • target (Target, default: None ) –

    Which set of kernels serves this op — a target name, BUILTIN for the in-tree kernels, or None to decide from the input device.

forward

forward(
    condition,
    input,
    other,
)

Run the op on condition, input and other.

tileops.elementwise.ClampTensorFwdOp

Clamp with Tensor lower and/or upper bounds (broadcasting).

Conforms to torch.clamp(input, min, max) where min and max are each either a Tensor or None. At least one of the two bounds must be a Tensor. All Tensor operands broadcast together. A single bound is torch.clamp_min / torch.clamp_max.

Which bounds this call carries is read off the call, not settled at construction, and it reaches the kernel's cache key because it changes what gets built. One instance therefore serves clamp, clamp_min and clamp_max, one specialization each.

__init__

__init__(
    *,
    target=None
)

Build the op. Shapes and dtype are taken from the first call.

Parameters:

  • target (Target, default: None ) –

    Which set of kernels serves this op — a target name, BUILTIN for the in-tree kernels, or None to decide from the input device.

forward

forward(
    input,
    min=None,
    max=None,
)

Run the op on input and whichever bounds the call passes.

tileops.elementwise.ClampScalarFwdOp

Scalar-bound clamp (torch.clamp(input, min: Number|None, max: Number|None)).

__init__

__init__(
    *,
    min=None,
    max=None,
    target=None
)

Build the op. Shapes and dtype are taken from the first call.

Parameters:

  • min (Optional[float], default: None ) –

    Lower bound (Number or None).

  • max (Optional[float], default: None ) –

    Upper bound (Number or None); at least one bound is given.

  • target (Target, default: None ) –

    Which set of kernels serves this op — a target name, BUILTIN for the in-tree kernels, or None to decide from the input device.

forward

forward(
    input,
)

Run the op on input.

tileops.elementwise.MaskedFillTensorFwdOp

MaskedFill with 0-dim Tensor value (torch.Tensor.masked_fill(mask, value: Tensor)).

Output shape is the bidirectional broadcast of input and mask; value is a 0-dim Tensor, which the kernel reads at forward time.

__init__

__init__(
    *,
    target=None
)

Build the op. Shapes and dtype are taken from the first call.

Parameters:

  • target (Target, default: None ) –

    Which set of kernels serves this op — a target name, BUILTIN for the in-tree kernels, or None to decide from the input device.

forward

forward(
    input,
    mask,
    value,
)

Run the op on input, mask and value.

tileops.elementwise.MaskedFillScalarFwdOp

MaskedFill with Number (scalar) value.

Conforms to torch.Tensor.masked_fill(mask, value: Number). Output shape follows the bidirectional broadcast of input and mask. Every dtype of the manifest union dispatches to a real kernel. A bool operand is served by whatever storage the selected kernel requires; the op passes and receives semantic bool either way.

__init__

__init__(
    *,
    value=0.0,
    target=None
)

Build the op. Shapes and dtype are taken from the first call.

Parameters:

  • value (bool | int | float, default: 0.0 ) –

    Scalar fill value (bool / int / float). Range-validated against the element type of the call with PyTorch Tensor.masked_fill coercion: bool reduces non-zero to True; integer dtypes range-check the real value against torch.iinfo and truncate floats toward zero (1.5 -> 1); torch.uint8 additionally wraps Python ints in [-255, 0) via two's complement.

  • target (Target, default: None ) –

    Which set of kernels serves this op — a target name, BUILTIN for the in-tree kernels, or None to decide from the input device.

forward

forward(
    input,
    mask,
)

Run the op on input and mask.

tileops.elementwise.NanToNumFwdOp

NanToNum: replace NaN, +Inf, -Inf with specified values.

__init__

__init__(
    *,
    nan=0.0,
    posinf=None,
    neginf=None,
    target=None
)

Build the op. Shapes and dtype are taken from the first call.

Parameters:

  • nan (float, default: 0.0 ) –

    Replacement for NaN (default 0.0).

  • posinf (Optional[float], default: None ) –

    Replacement for +Inf. Manifest default None resolves to the largest finite value representable in the element type of the call (matches torch.nan_to_num). An explicit value outside that element type's finite range is stored as Inf, as torch does.

  • neginf (Optional[float], default: None ) –

    Replacement for -Inf. Manifest default None resolves to the smallest (most negative) finite value representable in the element type of the call.

  • target (Target, default: None ) –

    Which set of kernels serves this op — a target name, BUILTIN for the in-tree kernels, or None to decide from the input device.

forward

forward(
    input,
)

Run the op on input.

Positional encodings

tileops.elementwise.AlibiFwdOp

ALiBi position encoding: bias[h, i, j] = -slope_h * |i - j|.

Generates the full (num_heads, seq_len, seq_len) bias tensor.

Note

Eager-only. Unlike the other elementwise ops in this package, AlibiFwdOp is not registered as a torch.library.custom_op, so torch.compile graph capture is not supported. The op has zero tensor inputs and constructs its output entirely from __init__ parameters; no compile-time wrapping is needed.

__init__

__init__(
    *,
    seq_len,
    num_heads,
    out_dtype=torch.float32,
    device=None,
    target=None
)

Build the op: the extents and dtype are its parameters.

Parameters:

  • seq_len (int) –

    Sequence length.

  • num_heads (int) –

    Number of attention heads.

  • out_dtype (dtype, default: float32 ) –

    Dtype of the generated tensor.

  • device (device | str | None, default: None ) –

    Where the tensor is produced, and so the device a target is detected from. None produces it on the current CUDA device, or wherever a named target decides.

  • target (Target, default: None ) –

    Which set of kernels serves this op — a target name, BUILTIN for the in-tree kernels, or None to decide from device.

forward

forward()

Generate the tensor, in out_dtype whatever storage the kernel computes in.

tileops.elementwise.SinusoidalFwdOp

Sinusoidal positional encoding from "Attention Is All You Need".

Generates the full (seq_len, d_model) encoding tensor.

Note

Eager-only. Unlike the other elementwise ops in this package, SinusoidalFwdOp is not registered as a torch.library.custom_op, so torch.compile graph capture is not supported. The op has zero tensor inputs and constructs its output entirely from __init__ parameters; no compile-time wrapping is needed.

__init__

__init__(
    *,
    seq_len,
    d_model,
    out_dtype=torch.float32,
    device=None,
    target=None
)

Build the op: the extents and dtype are its parameters.

Parameters:

  • seq_len (int) –

    Sequence length.

  • d_model (int) –

    Model dimension.

  • out_dtype (dtype, default: float32 ) –

    Dtype of the generated tensor.

  • device (device | str | None, default: None ) –

    Where the tensor is produced, and so the device a target is detected from. None produces it on the current CUDA device, or wherever a named target decides.

  • target (Target, default: None ) –

    Which set of kernels serves this op — a target name, BUILTIN for the in-tree kernels, or None to decide from device.

forward

forward()

Generate the tensor, in out_dtype whatever storage the kernel computes in.