vortex_torch.indexer.elementwise_binary

Classes

Add([alpha, beta])

Affine combination of two tensors.

Elementwise_Binary([alpha, beta])

Binary elementwise dispatcher for rank-3 logical tensors [S, C, D].

Maximum([alpha, beta])

Elementwise maximum between two tensors.

Minimum([alpha, beta])

Elementwise minimum between two tensors.

Multiply([alpha, beta])

Elementwise product of two tensors.

class vortex_torch.indexer.elementwise_binary.Elementwise_Binary(alpha=1.0, beta=1.0)[source]

Bases: vOp

Binary elementwise dispatcher for rank-3 logical tensors [S, C, D].

This operator dispatches to a binary elementwise implementation based on the pair of input formats (x._format, y._format). The logical output shape:

  • keeps the S axis from the runtime context (ctx.max_num_pages), and

  • follows broadcasting over the (C, D) axes.

Scalar parameters alpha and beta can be used by certain binary operations (e.g. an axpby-style op).

Parameters:
_impl_map

Dispatch table keyed by (x_format, y_format). Each entry maps to (callable_impl, resolved_output_format).

Type:

Dict[Tuple[FORMAT, FORMAT], Tuple[Callable, FORMAT]]

alpha

Scalar parameter used by some ops. Default is 1.0.

Type:

float

beta

Scalar parameter used by some ops. Default is 1.0.

Type:

float

impl

The resolved implementation selected during profile().

Type:

Optional[Callable]

op_type

The operator type used by the implementation.

Type:

Optional[ElementwiseBinaryOpType]

output_format

The output tensor format as determined in profile().

Type:

Optional[FORMAT]

output_buffer

Preallocated output tensor buffer that stores the binary result.

Type:

Optional[torch.Tensor]

profile(x, y, ctx)[source]

Validate inputs, select implementation, allocate the output buffer, and return a vTensor view with the resolved output format.

The dispatcher:

  • checks that x and y are rank-3 tensors of shape [S, C, D]

  • enforces broadcastability on the C and D dimensions

  • selects an implementation using (x._format, y._format)

  • allocates an output buffer with shape [S_ctx, C_out, D_out] where

    \[C_{\text{out}} = \max(C_x, C_y), \quad D_{\text{out}} = \max(D_x, D_y),\]

    and S_ctx = ctx.max_num_pages.

Parameters:
  • x (vTensor) – Left-hand input tensor, rank-3, with logical shape [S, C, D].

  • y (vTensor) – Right-hand input tensor, rank-3, with logical shape [S, C, D].

  • ctx (Context) – Execution context providing the runtime S (ctx.max_num_pages) and auxiliary-memory accounting.

Returns:

A vTensor view wrapping the allocated output buffer, using the resolved output format from the dispatch table.

Return type:

vTensor

Raises:

AssertionError – If types are not vTensor, if ranks are not 3, if C/D are not broadcastable, if formats are unsupported, or if devices of x and y do not match.

execute(x, y, ctx)[source]

Execute the selected binary elementwise implementation into the internal output buffer and return it.

Expected implementation signature:

impl(x, y, output, op_type, alpha, beta, ctx)
Parameters:
  • x (torch.Tensor) – Left-hand input tensor on the same device as y and the output buffer.

  • y (torch.Tensor) – Right-hand input tensor on the same device as x and the output buffer.

  • ctx (Context) – Execution context passed through to the underlying implementation.

Returns:

The output tensor stored in self.output_buffer.

Return type:

torch.Tensor

Raises:

AssertionError – If profile() has not been called (no implementation or buffer), or if there is a device mismatch between inputs and output.

class vortex_torch.indexer.elementwise_binary.Maximum(alpha=1.0, beta=1.0)[source]

Bases: Elementwise_Binary

Elementwise maximum between two tensors.

This operator computes the pointwise maximum:

\[\operatorname{out}(x, y) = \max(x, y)\]

Broadcasting over the (C, D) axes is supported as described in Elementwise_Binary.

Parameters:
  • alpha (float, optional) – Scalar parameter forwarded to the binary kernel. It is not used by the maximum operation itself. Default is 1.0.

  • beta (float, optional) – Scalar parameter forwarded to the binary kernel. It is not used by the maximum operation itself. Default is 1.0.

class vortex_torch.indexer.elementwise_binary.Minimum(alpha=1.0, beta=1.0)[source]

Bases: Elementwise_Binary

Elementwise minimum between two tensors.

This operator computes the pointwise minimum:

\[\operatorname{out}(x, y) = \min(x, y)\]

Broadcasting over the (C, D) axes is supported as described in Elementwise_Binary.

Parameters:
  • alpha (float, optional) – Scalar parameter forwarded to the binary kernel. It is not used by the minimum operation itself. Default is 1.0.

  • beta (float, optional) – Scalar parameter forwarded to the binary kernel. It is not used by the minimum operation itself. Default is 1.0.

class vortex_torch.indexer.elementwise_binary.Add(alpha=1.0, beta=1.0)[source]

Bases: Elementwise_Binary

Affine combination of two tensors.

This operator computes a weighted sum of the two inputs:

\[\operatorname{out}(x, y) = \alpha x + \beta y\]

With the defaults \(\alpha = 1\) and \(\beta = 1\), this reduces to standard elementwise addition:

\[\operatorname{out}(x, y) = x + y\]

Broadcasting over the (C, D) axes is supported as described in Elementwise_Binary.

Parameters:
  • alpha (float, optional) – Scalar multiplier for \(x\). Default is 1.0.

  • beta (float, optional) – Scalar multiplier for \(y\). Default is 1.0.

class vortex_torch.indexer.elementwise_binary.Multiply(alpha=1.0, beta=1.0)[source]

Bases: Elementwise_Binary

Elementwise product of two tensors.

This operator computes the pointwise product:

\[\operatorname{out}(x, y) = x \cdot y\]

Broadcasting over the (C, D) axes is supported as described in Elementwise_Binary.

Parameters:
  • alpha (float, optional) – Scalar parameter forwarded to the binary kernel. It is not used by the pure multiplication operation itself. Default is 1.0.

  • beta (float, optional) – Scalar parameter forwarded to the binary kernel. It is not used by the pure multiplication operation itself. Default is 1.0.