EDSL

Embedded Domain Specific Language

Initialization

void plaidml::edsl::init()

Initializes PlaidML’s EDSL API.

Note

Initialization of PlaidML’s EDSL Python API happens automatically wherever the module plaidml.edsl is imported.

Objects

class Program

This is a program.

Public Functions

Program(const std::string &name, const std::vector<Tensor> &outputs, const std::vector<std::tuple<Tensor, Tensor>> &updates = {})

Program constructor

std::string str() const

Return the Program as a string.

const std::vector<ProgramArgument> &args() const

args

const std::vector<ProgramArgument> &inputs() const

inputs

const std::vector<ProgramArgument> &outputs() const

outputs

class TensorDim

A symbolic object used to specify the dimensions of a Tensor

Public Functions

TensorDim()

TensorDim constructor

TensorDim(const std::shared_ptr<plaidml_dim_expr> &ptr)

TensorDim constructor

TensorDim(int64_t value)

TensorDim constructor

TensorDim operator-() const

Represents a subtraction operator overload.

std::string str() const

Returns the TensorDim as a string.

int64_t as_int() const

Returns the TensorDim as an int.

class TensorIndex

A symbolic object used to directly index a Tensor or to compute a Tensor’s index as part of a formula.

Public Functions

TensorIndex()

TensorIndex constructor

TensorIndex(int64_t value)

TensorIndex constructor

TensorIndex(const std::string &name)

TensorIndex constructor

TensorIndex operator-() const

Represents an subtraction operator overload on a TensorIndex

Constraint operator<(int64_t rhs) const

TODO

Constraint operator<(const TensorDim &rhs) const

TODO

std::string str() const

Returns the TensorIndex as a string.

struct Constraint

This is a constraint.

Public Members

TensorIndex lhs

lhs

TensorDim rhs

rhs

class IndexedTensor

This is an IndexedTensor

Public Functions

IndexedTensor &operator+=(const IndexedTensor &rhs)

Represents an aggregation_op of SUM in a contraction

IndexedTensor &operator*=(const IndexedTensor &rhs)

Represents an aggregation_op of PROD in a contraction

IndexedTensor &operator>=(const IndexedTensor &rhs)

Represents an aggregation_op of MAX in a contraction

IndexedTensor &operator<=(const IndexedTensor &rhs)

Represents an aggregation_op of MIN in a contraction

IndexedTensor &operator=(const IndexedTensor &rhs)

Represents an aggregation_op of ASSIGN in a contraction

IndexedTensor operator+(const IndexedTensor &rhs) const

Represents a combo_op of PLUS in a contraction

IndexedTensor operator*(const IndexedTensor &rhs) const

Represents a combo_op of MULTIPLY in a contraction

IndexedTensor operator==(const IndexedTensor &rhs) const

Represents a combo_op of EQ in a contraction

class LogicalShape

This is a LogicalShape.

Public Functions

LogicalShape(DType dtype, const std::vector<int64_t> &dims)

LogicalShape constructor

std::string str() const

Returns a LogicalShape as a string

DType dtype() const

Returns the datatype of the LogicalShape

size_t ndims() const

Returns the number of dimensions of the LogicalShape

std::vector<int64_t> int_dims() const

Returns the dimensions of the LogicalShape as a vector of integers.

bool operator==(const LogicalShape &rhs) const

TODO

class Tensor

A multidimensional array of a fixed shape.

Public Functions

Tensor()

Tensor constructor

Tensor(int value)

Tensor constructor

Return

Tensor

Parameters
  • value: int

Tensor(unsigned value)

Tensor constructor

Return

Tensor

Parameters
  • value: unsigned int

Tensor(int64_t value)

Tensor constructor

Return

Tensor

Parameters
  • value: int64_t

Tensor(double value)

Tensor constructor

Return

Tensor

Parameters
  • value: double

Tensor(const TensorDim &dim)

Tensor constructor

Tensor(const std::vector<int64_t> &dims)

Tensor constructor

Tensor(const std::vector<TensorDim> &dims)

Tensor constructor

Tensor(const std::initializer_list<TensorDim> &dims)

Tensor constructor

Tensor(const std::string &name, const std::vector<TensorDim> &dims)

Tensor constructor

Tensor(const std::string &name, const std::initializer_list<TensorDim> &dims)

Tensor constructor

Tensor(const Tensor &rhs)

Tensor constructor

Tensor &operator=(const Tensor &rhs)

Represents an operator overload for = for a Tensor

Tensor operator-() const

Represents an eltwise negation

Tensor operator~() const

Represents an eltwise bit_not

std::string str() const

TODO

Tensor &no_reduce()

Enable no_reduce on a contraction

Tensor &use_default(const Tensor &rhs)

Set use_default on a contraction

Tensor &add_constraint(const Constraint &constraint)

TODO

Tensor &add_constraints(const std::vector<Constraint> &constraints)

TODO

LogicalShape shape() const

Return the tensor’s shape

void bind_dims(const std::vector<TensorDim> &dims) const

Verify that the specified dims match the dims of this tensor.

template<typename ...Ts>
void bind_dims(Ts... dims) const

TODO

struct TensorRef

A reference to a Tensor

Public Functions

TensorRef(const Tensor &tensor)

TensorRef constructor

operator Tensor() const

TODO

bool operator<(const TensorRef &rhs) const

TODO

bool operator==(const TensorRef &rhs) const

TODO

Public Members

Tensor tensor

The Tensor that the TensorRef is referencing

struct ProgramArgument

Description for ProgramArgument

Public Members

bool is_input

TODO

TensorRef tensor

TODO

LogicalShape shape

TODO

std::shared_ptr<Buffer> buffer

TODO

Primitives

Tensor plaidml::edsl::abs(const Tensor &x)

Computes the elementwise absolute value of x.

Return

Tensor

Parameters

Tensor plaidml::edsl::cast(const Tensor &x, DType dtype)

Casts the element type of a tensor x to the type specified by dtype.

Return

Tensor

Parameters

Tensor plaidml::edsl::ceil(const Tensor &x)

Computes the elementwise ceiling of x.

Return

Tensor

Parameters

Tensor plaidml::edsl::cos(const Tensor &x)

Computes the elementwise cosine of x.

Return

Tensor

Parameters

Tensor plaidml::edsl::cosh(const Tensor &x)

Computes the elementwise hyperbolic cosine of x.

Return

Tensor

Parameters

Tensor plaidml::edsl::exp(const Tensor &x)

Computes the elementwise natural exponential function of x: ex.

Return

Tensor

Parameters

Tensor plaidml::edsl::floor(const Tensor &x)

Computes the elementwise floor of x.

Return

Tensor

Parameters

Tensor plaidml::edsl::gather(const Tensor &x, const Tensor &y)

Takes an input tensor (x) and a set of indices to gather over (y), and returns an output tensor that gathers the input tensor from the indices specified.

Return

Tensor

Parameters

Tensor plaidml::edsl::ident(const Tensor &x)

Returns the identity of x.

Return

Tensor

Parameters

Tensor plaidml::edsl::index(const Tensor &x, size_t axis)

Returns the index of x at the specified axis.

Return

Tensor

Parameters

Tensor plaidml::edsl::log(const Tensor &x)

Computes the elementwise natural logarithm of x: ln(x).

Return

Tensor

Parameters

Tensor plaidml::edsl::pow(const Tensor &x, const Tensor &y)

Computes the elementwise yth power of x.

Return

Tensor

Parameters

Tensor plaidml::edsl::prng(const Tensor &state, const std::vector<int64_t> &dims)

Generates a Tensor of elementwise pseudorandom numbers using the seed values specified in state.

Return

Tensor

Parameters
  • state: Tensor

  • dims: vector<int64_t>

Tensor plaidml::edsl::reshape(const Tensor &x, const std::vector<int64_t> &dims)

Takes an input tensor x and reshapes it according to dims.

Return

Tensor

Parameters
  • x: Tensor

  • dims: vector<int64_t>

Tensor plaidml::edsl::reshape(const Tensor &x, const std::vector<TensorDim> &dims)

Takes an input tensor x and reshapes it according to dims.

Return

Tensor

Parameters
  • x: Tensor

  • dims: vector<TensorDim>

Tensor plaidml::edsl::round(const Tensor &x)

Rounds x elementwise.

Return

Tensor

Parameters

Tensor plaidml::edsl::scatter(const Tensor &x, const Tensor &y, const Tensor &z)

Takes an input tensor (x), a set of indices to scatter over (y), and the number of elements in the scattered tensor (z), and returns an output tensor that scatters the input tensor across the number of elements specified.

Return

Tensor

Parameters

Tensor plaidml::edsl::select(const Tensor &cond, const Tensor &true_case, const Tensor &false_case)

Performs an elementwise conditional which returns the corresponding element in true_case if the condition is evaluated to be true or the corresponding element in false_case if the condition is evaluated to be false.

Return

Tensor

Parameters

Tensor plaidml::edsl::shape(const Tensor &x)

Returns the shape of x as a Tensor.

Return

Tensor

Parameters

Tensor plaidml::edsl::sin(const Tensor &x)

Computes the elementwise sine of x.

Return

Tensor

Parameters

Tensor plaidml::edsl::sinh(const Tensor &x)

Computes the elementwise hyperbolic sine of x.

Return

Tensor

Parameters

Tensor plaidml::edsl::sqrt(const Tensor &x)

Computes the elementwise square root of x.

Return

Tensor

Parameters

Tensor plaidml::edsl::tan(const Tensor &x)

Computes the elementwise tangent of x.

Return

Tensor

Parameters

Tensor plaidml::edsl::tanh(const Tensor &x)

Computes the elementwise hyperbolic tangent of x.

Return

Tensor

Parameters

Tensor plaidml::edsl::zero()

Returns a Tensor with a value of 0.

Return

Tensor

Examples

Tensor sum_over_axis(const Tensor& I) {
   TensorDim M, N;
   TensorIndex m, n;
   I.bind_dims(M, N);
   auto O = TensorOutput(N);
   O(n) += I(m, n); // contraction
   return O;
}
\[\color{red}O[n] \color{default}= \color{green}\sum_{m} \color{blue}I[m, n] \]
\[\color{red}\verb|O(n)| \color{green}\verb| += | \color{blue}\verb|I(m, n)|\color{default}\verb|;| \]