plaidml.tile
¶
Description
TILE program construction utilities.
When writing a program in TILE, you typically specify a graph of operations, where each operation is defined by a single TILE function. You then use composition to connect the individual TILE functions into a single composite TILE function, which can then be compiled, scheduled, and executed as a single unit. The PlaidML API provides functions for building up and using these composite TILE programs.
Defining the individual per-operation TILE functions is sometimes trivial, and sometimes not. For example: although TILE makes it very easy to write a matrix multiply operation, the details of how that operations is expressed in TILE vary depending on the number of dimensions involved, whether broadcasting is required, &c. Higher-level frameworks tend to expect their backends to have a single “Do a matrix multiply” operation that’s supposed to internally figure out all of these details; that’s not really something that can be done in TILE directly.
It’s wasteful and error-prone to implement these sometimes-tricky conversions from high-level semantics to low-level TILE code for each framework. And the frameworks tend to have similar semantics, thanks to the influence of Numpy. So PlaidML provides:
- A standard high-level operation library for constructing the per-operation TILE functions and composing them together (this module)
- Utilities to assist in constructing operations, such as broadcasting logic (this module)
- A suite of operations that we’ve found to be useful across a variety of frameworks (the plaidml.op module).
This library uses two passes for building up composite functions. The first
pass constructs Python objects representing the operation graph; the second
pass translates the operation graph to the composite TILE function. This is
done for two reasons: it allows for higher-level optimizations (e.g.
translating particular subtrees to more efficient TILE operations) and for
expressing operations that cannot be efficiently implemented in the current
version of TILE (e.g. it’s very expensive to implement ArgMax in the initial
released version of TILE, but ArgMax is typically used in composite
expressions like Equal(ArgMax(X), ArgMax(Y))
, which is trivial to
efficiently implement in TILE).
More precisely, this library builds up a bipartite directed acyclic graph of
Operation
and Value
objects. Operation
is the base class of each
operation; Value
represents an operation input or output. compose
translates an operation graph into a plaidml.Function
.
See the Tile Tutorial for more information about how the TILE language works, or check out the PlaidML Op Tutorial for the details of writing your own operations.
Classes
DTypeInfo |
Describes a PlaidML datatype. |
Operation (code, inputs, outputs[, name, …]) |
Operation base class. |
Shape |
Represents a symbolic tensor shape. |
ShapeOf (x) |
Computes the shape of a supplied tensor. |
Source (op, output_name) |
|
Value (shape, var, source[, name]) |
A PlaidML variable and associated metadata. |
Functions
binary_op (lhs, rhs, op_str[, dtype, name]) |
Builds a Value for an elementwise binary operation. |
broadcast_dims (*args) |
Computes the broadcast dimensions of the supplied dimensions. |
common_dtype (*args) |
Finds the common dtype of a set of dtypes. |
compose (ctx, dev, inputs, outputs[, updates]) |
Builds a TILE Function that computes the indicated values. |
compute_aggregation_axes (dims[, axes, keepdims]) |
Computes parameters for an aggregation-over-axes operation. |
maximum (x, y) |
|
minimum (x, y) |
|
to_dot (inputs, outputs[, updates, name]) |
Translates a chain of tensor computations to a DOT graph. |
unary_op (value, op_str[, name]) |
Builds a Value for an elementwise unary operation. |
Exceptions
Error |
Errors raised during TILE function composition. |
LogicError |
Logic errors on the part of the caller. |