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__
¶
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
Noneto decide from the input device.
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__
¶
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
Noneto decide from the input device.
tileops.elementwise.MulFwdOp
¶
Element-wise multiplication with broadcast: y = input * other.
__init__
¶
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,
BUILTINfor the in-tree kernels, orNoneto decide from the input device.
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__
¶
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
Noneto decide from the input device.
tileops.elementwise.FloorDivideFwdOp
¶
Element-wise floor division with broadcast: y = a // b, as torch.floor_divide.
__init__
¶
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,
BUILTINfor the in-tree kernels, orNoneto decide from the input device.
tileops.elementwise.RemainderFwdOp
¶
Element-wise remainder with broadcast: y = a % b.
__init__
¶
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,
BUILTINfor the in-tree kernels, orNoneto decide from the input device.
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__
¶
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,
BUILTINfor the in-tree kernels, orNoneto decide from the input device.
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__
¶
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,
BUILTINfor the in-tree kernels, orNoneto decide from the input device.
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__
¶
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,
BUILTINfor the in-tree kernels, orNoneto decide from the input device.
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__
¶
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.
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.
Unary math¶
tileops.elementwise.ExpFwdOp
¶
Element-wise exp(x).
__init__
¶
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,
BUILTINfor the in-tree kernels, orNoneto decide from the input device.
tileops.elementwise.Expm1FwdOp
¶
Element-wise exp(x) - 1.
__init__
¶
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,
BUILTINfor the in-tree kernels, orNoneto decide from the input device.
tileops.elementwise.LogFwdOp
¶
Element-wise log(x).
__init__
¶
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,
BUILTINfor the in-tree kernels, orNoneto decide from the input device.
tileops.elementwise.Log1pFwdOp
¶
Element-wise log(1 + x).
__init__
¶
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,
BUILTINfor the in-tree kernels, orNoneto decide from the input device.
tileops.elementwise.SqrtFwdOp
¶
Element-wise sqrt(x).
__init__
¶
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,
BUILTINfor the in-tree kernels, orNoneto decide from the input device.
tileops.elementwise.RsqrtFwdOp
¶
Element-wise 1/sqrt(x).
__init__
¶
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,
BUILTINfor the in-tree kernels, orNoneto decide from the input device.
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__
¶
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,
BUILTINfor the in-tree kernels, orNoneto decide from the input device.
tileops.elementwise.AbsFwdOp
¶
Element-wise |x|.
__init__
¶
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,
BUILTINfor the in-tree kernels, orNoneto decide from the input device.
tileops.elementwise.NegFwdOp
¶
Element-wise -x.
__init__
¶
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,
BUILTINfor the in-tree kernels, orNoneto decide from the input device.
tileops.elementwise.SignFwdOp
¶
Element-wise sign(x): -1, 0, or +1.
__init__
¶
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,
BUILTINfor the in-tree kernels, orNoneto decide from the input device.
tileops.elementwise.SinFwdOp
¶
Element-wise sin(x).
__init__
¶
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,
BUILTINfor the in-tree kernels, orNoneto decide from the input device.
tileops.elementwise.CosFwdOp
¶
Element-wise cos(x).
__init__
¶
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,
BUILTINfor the in-tree kernels, orNoneto decide from the input device.
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__
¶
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,
BUILTINfor the in-tree kernels, orNoneto decide from the input device.
tileops.elementwise.FloorFwdOp
¶
Element-wise floor(x).
__init__
¶
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,
BUILTINfor the in-tree kernels, orNoneto decide from the input device.
tileops.elementwise.CeilFwdOp
¶
Element-wise ceil(x).
__init__
¶
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,
BUILTINfor the in-tree kernels, orNoneto decide from the input device.
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__
¶
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.
tileops.elementwise.TruncFwdOp
¶
Element-wise trunc(x).
__init__
¶
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,
BUILTINfor the in-tree kernels, orNoneto decide from the input device.
Activations¶
tileops.elementwise.ReluFwdOp
¶
ReLU activation: y = max(x, 0).
__init__
¶
Build the op. Shapes and dtype are taken from the first call.
Parameters:
-
inplace(bool, default:False) –When True, write the result into
inputand returninput. -
target(Target, default:None) –Backend target to serve this op, or
Noneto decide from the input device.
tileops.elementwise.LeakyReluFwdOp
¶
Leaky ReLU: y = x if x > 0 else negative_slope * x.
__init__
¶
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
inputand returninput. -
target(Target, default:None) –Which set of kernels serves this op.
tileops.elementwise.EluFwdOp
¶
ELU: y = x if x > 0 else alpha * (exp(x) - 1).
__init__
¶
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
inputand returninput. -
target(Target, default:None) –Which set of kernels serves this op.
tileops.elementwise.SeluFwdOp
¶
Element-wise SELU activation.
__init__
¶
Build the op. Shapes and dtype are taken from the first call.
Parameters:
-
inplace(bool, default:False) –When True, write the result into
inputand returninput. -
target(Target, default:None) –Backend target to serve this op, or
Noneto decide from the input device.
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__
¶
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 approximation0.5 * x * (1 + tanh(sqrt(2/pi) * (x + 0.044715 * x^3))). -
target(Target, default:None) –Which set of kernels serves this op.
tileops.elementwise.SiluFwdOp
¶
Element-wise SiLU (Swish): y = x * sigmoid(x).
__init__
¶
Build the op. Shapes and dtype are taken from the first call.
Parameters:
-
inplace(bool, default:False) –When True, write the result into
inputand returninput. -
target(Target, default:None) –Backend target to serve this op, or
Noneto decide from the input device.
tileops.elementwise.MishFwdOp
¶
Element-wise Mish: y = x * tanh(softplus(x)).
__init__
¶
Build the op. Shapes and dtype are taken from the first call.
Parameters:
-
inplace(bool, default:False) –When True, write the result into
inputand returninput. -
target(Target, default:None) –Backend target to serve this op, or
Noneto decide from the input device.
tileops.elementwise.SigmoidFwdOp
¶
Element-wise sigmoid(x).
A float16 or bfloat16 result equals torch.sigmoid's bit for bit at every input.
__init__
¶
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,
BUILTINfor the in-tree kernels, orNoneto decide from the input device.
tileops.elementwise.TanhFwdOp
¶
Element-wise tanh(x).
__init__
¶
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,
BUILTINfor the in-tree kernels, orNoneto decide from the input device.
tileops.elementwise.HardsigmoidFwdOp
¶
Element-wise HardSigmoid: y = clamp(x + 3, 0, 6) / 6.
__init__
¶
Build the op. Shapes and dtype are taken from the first call.
Parameters:
-
inplace(bool, default:False) –When True, write the result into
inputand returninput. -
target(Target, default:None) –Backend target to serve this op, or
Noneto decide from the input device.
tileops.elementwise.HardswishFwdOp
¶
Element-wise HardSwish: y = x * clamp(x + 3, 0, 6) / 6.
__init__
¶
Build the op. Shapes and dtype are taken from the first call.
Parameters:
-
inplace(bool, default:False) –When True, write the result into
inputand returninput. -
target(Target, default:None) –Backend target to serve this op, or
Noneto decide from the input device.
tileops.elementwise.HardtanhFwdOp
¶
Hardtanh: y = clamp(x, min_val, max_val).
__init__
¶
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
inputand returninput. -
target(Target, default:None) –Which set of kernels serves this op.
tileops.elementwise.SoftplusFwdOp
¶
Softplus: y = log(1 + exp(xbeta))/beta if xbeta <= threshold else x.
__init__
¶
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.
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__
¶
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,
BUILTINfor the in-tree kernels, orNoneto decide from the input device.
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__
¶
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,
BUILTINfor the in-tree kernels, orNoneto decide from the input device.
Gated activations¶
tileops.elementwise.SiluAndMulFwdOp
¶
SiLU-and-Mul: y = silu(gate) * value.
__init__
¶
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,
BUILTINfor the in-tree kernels, orNoneto decide from the input device.
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__
¶
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,
BUILTINfor the in-tree kernels, orNoneto decide from the input device.
tileops.elementwise.GeluTanhAndMulFwdOp
¶
GELU-Tanh-and-Mul: y = gelu_tanh(gate) * value (tanh approximation).
__init__
¶
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,
BUILTINfor the in-tree kernels, orNoneto decide from the input device.
Comparison¶
tileops.elementwise.EqFwdOp
¶
Element-wise equality with broadcast: y = (a == b).
__init__
¶
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,
BUILTINfor the in-tree kernels, orNoneto decide from the input device.
tileops.elementwise.NeFwdOp
¶
Element-wise not-equal with broadcast: y = (a != b).
__init__
¶
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,
BUILTINfor the in-tree kernels, orNoneto decide from the input device.
tileops.elementwise.GtFwdOp
¶
Element-wise greater-than with broadcast: y = (a > b).
__init__
¶
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,
BUILTINfor the in-tree kernels, orNoneto decide from the input device.
tileops.elementwise.GeFwdOp
¶
Element-wise greater-equal with broadcast: y = (a >= b).
__init__
¶
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,
BUILTINfor the in-tree kernels, orNoneto decide from the input device.
tileops.elementwise.LtFwdOp
¶
Element-wise less-than with broadcast: y = (a < b).
__init__
¶
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,
BUILTINfor the in-tree kernels, orNoneto decide from the input device.
tileops.elementwise.LeFwdOp
¶
Element-wise less-equal with broadcast: y = (a <= b).
__init__
¶
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,
BUILTINfor the in-tree kernels, orNoneto decide from the input device.
tileops.elementwise.IsnanFwdOp
¶
Element-wise isnan with bool output.
Always False on integer / bool input (no NaN representation in those dtypes).
__init__
¶
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,
BUILTINfor the in-tree kernels, orNoneto decide from the input device.
tileops.elementwise.IsinfFwdOp
¶
Element-wise isinf with bool output.
Always False on integer / bool input (no Inf representation in those dtypes).
__init__
¶
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,
BUILTINfor the in-tree kernels, orNoneto decide from the input device.
tileops.elementwise.IsfiniteFwdOp
¶
Element-wise isfinite with bool output.
Always True on integer / bool input (every value in those dtypes is finite).
__init__
¶
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,
BUILTINfor the in-tree kernels, orNoneto decide from the input device.
Logical and bitwise¶
tileops.elementwise.LogicalAndFwdOp
¶
Element-wise logical AND with broadcast using non-zero truthiness.
__init__
¶
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,
BUILTINfor the in-tree kernels, orNoneto decide from the input device.
tileops.elementwise.LogicalOrFwdOp
¶
Element-wise logical OR with broadcast using non-zero truthiness.
__init__
¶
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,
BUILTINfor the in-tree kernels, orNoneto decide from the input device.
tileops.elementwise.LogicalNotFwdOp
¶
Element-wise logical NOT with bool output.
__init__
¶
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,
BUILTINfor the in-tree kernels, orNoneto decide from the input device.
tileops.elementwise.BitwiseAndFwdOp
¶
Element-wise bitwise AND with broadcast: y = a & b.
__init__
¶
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,
BUILTINfor the in-tree kernels, orNoneto decide from the input device.
tileops.elementwise.BitwiseOrFwdOp
¶
Element-wise bitwise OR with broadcast: y = a | b.
__init__
¶
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,
BUILTINfor the in-tree kernels, orNoneto decide from the input device.
tileops.elementwise.BitwiseXorFwdOp
¶
Element-wise bitwise XOR with broadcast: y = a ^ b.
__init__
¶
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,
BUILTINfor the in-tree kernels, orNoneto decide from the input device.
tileops.elementwise.BitwiseNotFwdOp
¶
Element-wise bitwise NOT (~x) for bool/integer inputs.
__init__
¶
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,
BUILTINfor the in-tree kernels, orNoneto decide from the input device.
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__
¶
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,
BUILTINfor the in-tree kernels, orNoneto decide from the input device.
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__
¶
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,
BUILTINfor the in-tree kernels, orNoneto decide from the input device.
forward
¶
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__
¶
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,
BUILTINfor the in-tree kernels, orNoneto decide from the input device.
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__
¶
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,
BUILTINfor the in-tree kernels, orNoneto decide from the input device.
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__
¶
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_fillcoercion: bool reduces non-zero toTrue; integer dtypes range-check the real value againsttorch.iinfoand truncate floats toward zero (1.5 -> 1);torch.uint8additionally wraps Python ints in[-255, 0)via two's complement. -
target(Target, default:None) –Which set of kernels serves this op — a target name,
BUILTINfor the in-tree kernels, orNoneto decide from the input device.
tileops.elementwise.NanToNumFwdOp
¶
NanToNum: replace NaN, +Inf, -Inf with specified values.
__init__
¶
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
Noneresolves to the largest finite value representable in the element type of the call (matchestorch.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
Noneresolves 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,
BUILTINfor the in-tree kernels, orNoneto decide from the input device.
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__
¶
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.
Noneproduces 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,
BUILTINfor the in-tree kernels, orNoneto decide fromdevice.
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__
¶
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.
Noneproduces 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,
BUILTINfor the in-tree kernels, orNoneto decide fromdevice.