EDSL¶
Embedded Domain Specific Language
Contents
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
-
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 constructor
-
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.
-
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
-
IndexedTensor &
-
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
-
std::string
str
() const¶ TODO
-
Tensor &
add_constraint
(const Constraint &constraint)¶ TODO
-
Tensor &
add_constraints
(const std::vector<Constraint> &constraints)¶ TODO
-
LogicalShape
shape
() const¶ Return the tensor’s shape
-
std::string
-
struct
ProgramArgument
¶ Description for ProgramArgument
Primitives¶
-
Tensor
plaidml::edsl
::
cast
(const Tensor &x, DType dtype)¶ Casts the element type of a tensor
x
to the type specified bydtype
.
-
Tensor
plaidml::edsl
::
exp
(const Tensor &x)¶ Computes the elementwise natural exponential function of
x
: ex.
-
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.
-
Tensor
plaidml::edsl
::
index
(const Tensor &x, size_t axis)¶ Returns the index of
x
at the specifiedaxis
.
-
Tensor
plaidml::edsl
::
pow
(const Tensor &x, const Tensor &y)¶ Computes the elementwise
y
th power ofx
.
-
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
.
-
Tensor
plaidml::edsl
::
reshape
(const Tensor &x, const std::vector<int64_t> &dims)¶ Takes an input tensor
x
and reshapes it according todims
.
-
Tensor
plaidml::edsl
::
reshape
(const Tensor &x, const std::vector<TensorDim> &dims)¶ Takes an input tensor
x
and reshapes it according todims
.
-
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.
-
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 infalse_case
if the condition is evaluated to be false.
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;
}